From d44dbf2b095ded1b58c9d3f1742ada57ff2b6d87 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Tue, 27 Feb 2024 19:56:39 -0500 Subject: [PATCH 1/5] added entity_category to HASensor --- src/device-types/HASensor.cpp | 4 +++- src/device-types/HASensor.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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; From d062dd435b5ae841e0d30aa8e8838450b73573a6 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 28 Feb 2024 08:45:28 -0500 Subject: [PATCH 2/5] added entity_category to HA sensor --- src/utils/HADictionary.cpp | 1 + src/utils/HADictionary.h | 1 + 2 files changed, 2 insertions(+) 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[]; From 1738aa844faf47335a065d7a80ba50f389972cab Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 28 Feb 2024 11:15:44 -0500 Subject: [PATCH 3/5] add entity category to binary sensor --- src/device-types/HABinarySensor.cpp | 6 ++++-- src/device-types/HABinarySensor.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) 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; From 6f6582b9ccc3c127bfb80b4a7cc9c720f86b712a Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 28 Feb 2024 11:15:57 -0500 Subject: [PATCH 4/5] add entity category to button --- src/device-types/HAButton.cpp | 4 +++- src/device-types/HAButton.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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; From 761f4a1370d6175f4ce141da7c22daf8db5e0aea Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 28 Feb 2024 11:16:10 -0500 Subject: [PATCH 5/5] add entity category to number --- src/device-types/HANumber.cpp | 4 +++- src/device-types/HANumber.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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;