diff --git a/src/device-types/HABinarySensor.cpp b/src/device-types/HABinarySensor.cpp index 20ab76ff..036d764c 100644 --- a/src/device-types/HABinarySensor.cpp +++ b/src/device-types/HABinarySensor.cpp @@ -8,7 +8,8 @@ HABinarySensor::HABinarySensor(const char* uniqueId) : HABaseDeviceType(AHATOFSTR(HAComponentBinarySensor), uniqueId), _class(nullptr), _icon(nullptr), - _currentState(false) + _currentState(false), + _entityCategory(nullptr) { } @@ -42,11 +43,12 @@ void HABinarySensor::buildSerializer() return; } - _serializer = new HASerializer(this, 9); // 9 - max properties nb + _serializer = new HASerializer(this, 10); // 10 - max properties nb _serializer->set(AHATOFSTR(HANameProperty), _name); _serializer->set(AHATOFSTR(HAObjectIdProperty), _objectId); _serializer->set(HASerializer::WithUniqueId); _serializer->set(AHATOFSTR(HADeviceClassProperty), _class); + _serializer->set(AHATOFSTR(HAStateEntityCategory), _entityCategory); _serializer->set(AHATOFSTR(HAIconProperty), _icon); if (_expireAfter.isSet()) { diff --git a/src/device-types/HABinarySensor.h b/src/device-types/HABinarySensor.h index 518e546c..85c98786 100644 --- a/src/device-types/HABinarySensor.h +++ b/src/device-types/HABinarySensor.h @@ -63,6 +63,15 @@ class HABinarySensor : public HABaseDeviceType inline void setDeviceClass(const char* deviceClass) { _class = deviceClass; } + /** + * Sets the entity category for the sensor. + * See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + * + * @param entityCategory The category name. + */ + inline void setEntityCategory(const char* entityCategory) + { _entityCategory = entityCategory; } + /** * Sets icon of the sensor. * Any icon from MaterialDesignIcons.com (for example: `mdi:home`). @@ -88,6 +97,9 @@ class HABinarySensor : public HABaseDeviceType /// The device class. It can be nullptr. const char* _class; + /// The entity category for the sensor. It can be nullptr. See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + const char* _entityCategory; + /// The icon of the sensor. It can be nullptr. const char* _icon; diff --git a/src/device-types/HAButton.cpp b/src/device-types/HAButton.cpp index 4a913c65..d35f42ec 100644 --- a/src/device-types/HAButton.cpp +++ b/src/device-types/HAButton.cpp @@ -7,6 +7,7 @@ HAButton::HAButton(const char* uniqueId) : HABaseDeviceType(AHATOFSTR(HAComponentButton), uniqueId), _class(nullptr), + _entityCategory(nullptr), _icon(nullptr), _retain(false), _commandCallback(nullptr) @@ -20,11 +21,12 @@ void HAButton::buildSerializer() return; } - _serializer = new HASerializer(this, 9); // 9 - max properties nb + _serializer = new HASerializer(this, 10); // 10 - max properties nb _serializer->set(AHATOFSTR(HANameProperty), _name); _serializer->set(AHATOFSTR(HAObjectIdProperty), _objectId); _serializer->set(HASerializer::WithUniqueId); _serializer->set(AHATOFSTR(HADeviceClassProperty), _class); + _serializer->set(AHATOFSTR(HAStateEntityCategory), _entityCategory); _serializer->set(AHATOFSTR(HAIconProperty), _icon); // optional property diff --git a/src/device-types/HAButton.h b/src/device-types/HAButton.h index 58c88fd1..76964408 100644 --- a/src/device-types/HAButton.h +++ b/src/device-types/HAButton.h @@ -32,6 +32,15 @@ class HAButton : public HABaseDeviceType inline void setDeviceClass(const char* deviceClass) { _class = deviceClass; } + /** + * Sets the entity category for the sensor. + * See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + * + * @param entityCategory The category name. + */ + inline void setEntityCategory(const char* entityCategory) + { _entityCategory = entityCategory; } + /** * Sets icon of the button. * Any icon from MaterialDesignIcons.com (for example: `mdi:home`). @@ -72,6 +81,9 @@ class HAButton : public HABaseDeviceType /// The device class. It can be nullptr. const char* _class; + /// The entity category for the sensor. It can be nullptr. See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + const char* _entityCategory; + /// The icon of the button. It can be nullptr. const char* _icon; diff --git a/src/device-types/HANumber.cpp b/src/device-types/HANumber.cpp index 2c413450..9c1e7da5 100644 --- a/src/device-types/HANumber.cpp +++ b/src/device-types/HANumber.cpp @@ -8,6 +8,7 @@ HANumber::HANumber(const char* uniqueId, const NumberPrecision precision) : HABaseDeviceType(AHATOFSTR(HAComponentNumber), uniqueId), _precision(precision), _class(nullptr), + _entityCategory(nullptr), _icon(nullptr), _retain(false), _optimistic(false), @@ -42,11 +43,12 @@ void HANumber::buildSerializer() return; } - _serializer = new HASerializer(this, 16); // 16 - max properties nb + _serializer = new HASerializer(this, 17); // 17 - max properties nb _serializer->set(AHATOFSTR(HANameProperty), _name); _serializer->set(AHATOFSTR(HAObjectIdProperty), _objectId); _serializer->set(HASerializer::WithUniqueId); _serializer->set(AHATOFSTR(HADeviceClassProperty), _class); + _serializer->set(AHATOFSTR(HAStateEntityCategory), _entityCategory); _serializer->set(AHATOFSTR(HAIconProperty), _icon); _serializer->set(AHATOFSTR(HAUnitOfMeasurementProperty), _unitOfMeasurement); _serializer->set( diff --git a/src/device-types/HANumber.h b/src/device-types/HANumber.h index e20d6fef..417f976d 100644 --- a/src/device-types/HANumber.h +++ b/src/device-types/HANumber.h @@ -106,6 +106,15 @@ class HANumber : public HABaseDeviceType inline void setDeviceClass(const char* deviceClass) { _class = deviceClass; } + /** + * Sets the entity category for the sensor. + * See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + * + * @param entityCategory The category name. + */ + inline void setEntityCategory(const char* entityCategory) + { _entityCategory = entityCategory; } + /** * Sets icon of the number. * Any icon from MaterialDesignIcons.com (for example: `mdi:home`). @@ -228,6 +237,9 @@ class HANumber : public HABaseDeviceType /// The device class. It can be nullptr. const char* _class; + /// The entity category for the sensor. It can be nullptr. See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + const char* _entityCategory; + /// The icon of the number. It can be nullptr. const char* _icon; diff --git a/src/device-types/HASensor.cpp b/src/device-types/HASensor.cpp index 0d2efe9a..e36301db 100644 --- a/src/device-types/HASensor.cpp +++ b/src/device-types/HASensor.cpp @@ -8,6 +8,7 @@ HASensor::HASensor(const char* uniqueId, const uint16_t features) : HABaseDeviceType(AHATOFSTR(HAComponentSensor), uniqueId), _features(features), _deviceClass(nullptr), + _entityCategory(nullptr), _stateClass(nullptr), _forceUpdate(false), _icon(nullptr), @@ -46,12 +47,13 @@ void HASensor::buildSerializer() return; } - _serializer = new HASerializer(this, 13); // 13 - max properties nb + _serializer = new HASerializer(this, 14); // 13 - max properties nb _serializer->set(AHATOFSTR(HANameProperty), _name); _serializer->set(AHATOFSTR(HAObjectIdProperty), _objectId); _serializer->set(HASerializer::WithUniqueId); _serializer->set(AHATOFSTR(HADeviceClassProperty), _deviceClass); _serializer->set(AHATOFSTR(HAStateClassProperty), _stateClass); + _serializer->set(AHATOFSTR(HAStateEntityCategory), _entityCategory); _serializer->set(AHATOFSTR(HAIconProperty), _icon); _serializer->set(AHATOFSTR(HAUnitOfMeasurementProperty), _unitOfMeasurement); diff --git a/src/device-types/HASensor.h b/src/device-types/HASensor.h index 6dbd2812..34827f73 100644 --- a/src/device-types/HASensor.h +++ b/src/device-types/HASensor.h @@ -64,6 +64,15 @@ class HASensor : public HABaseDeviceType inline void setDeviceClass(const char* deviceClass) { _deviceClass = deviceClass; } + /** + * Sets the entity category for the sensor. + * See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + * + * @param entityCategory The category name. + */ + inline void setEntityCategory(const char* entityCategory) + { _entityCategory = entityCategory; } + /** * Sets class of the state for the long term stats. * See: https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics @@ -110,6 +119,9 @@ class HASensor : public HABaseDeviceType /// The device class. It can be nullptr. const char* _deviceClass; + /// The entity category for the sensor. It can be nullptr. See: https://www.home-assistant.io/integrations/sensor.mqtt/#entity_category + const char* _entityCategory; + /// The state class for the long term stats. It can be nullptr. See: https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics const char* _stateClass; diff --git a/src/utils/HADictionary.cpp b/src/utils/HADictionary.cpp index 266d21dd..077d809c 100644 --- a/src/utils/HADictionary.cpp +++ b/src/utils/HADictionary.cpp @@ -42,6 +42,7 @@ const char HAUniqueIdProperty[] PROGMEM = {"uniq_id"}; const char HAObjectIdProperty[] PROGMEM = {"obj_id"}; const char HADeviceProperty[] PROGMEM = {"dev"}; const char HADeviceClassProperty[] PROGMEM = {"dev_cla"}; +const char HAStateEntityCategory[] PROGMEM = {"ent_cat"}; const char HAStateClassProperty[] PROGMEM = {"stat_cla"}; const char HAIconProperty[] PROGMEM = {"ic"}; const char HARetainProperty[] PROGMEM = {"ret"}; diff --git a/src/utils/HADictionary.h b/src/utils/HADictionary.h index 609f38df..518fad82 100644 --- a/src/utils/HADictionary.h +++ b/src/utils/HADictionary.h @@ -42,6 +42,7 @@ extern const char HAUniqueIdProperty[]; extern const char HAObjectIdProperty[]; extern const char HADeviceProperty[]; extern const char HADeviceClassProperty[]; +extern const char HAStateEntityCategory[]; extern const char HAStateClassProperty[]; extern const char HAIconProperty[]; extern const char HARetainProperty[];