From cdccf91dfaec18e0bef6fc8c64c50f619c5b0f60 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 4 Mar 2024 10:20:48 +0100 Subject: [PATCH 1/3] Add native_unit_of_measurement, for all temperature sensors we have to let HA know we have a native unit in celcius * custom_components/daikin_onecta/const.py: * custom_components/daikin_onecta/sensor.py: --- custom_components/daikin_onecta/const.py | 53 +++++++++++++++++++++++ custom_components/daikin_onecta/sensor.py | 3 ++ 2 files changed, 56 insertions(+) diff --git a/custom_components/daikin_onecta/const.py b/custom_components/daikin_onecta/const.py index 3cc48f3..eaa7aa5 100644 --- a/custom_components/daikin_onecta/const.py +++ b/custom_components/daikin_onecta/const.py @@ -42,6 +42,7 @@ ENABLED_DEFAULT = "Enabled" STATE_CLASS = "STATE" ENTITY_CATEGORY = "ENTITY_CATEGORY" +CONF_NATIVE_UNIT_OF_MEASUREMENT = "native_unit_of_measurement" # This maps the NAME as listed in the Daikin JSON data to: # - DEVICE_CLASS: home assistant device class, see @@ -54,6 +55,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:alphabetical", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -62,6 +64,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:toggle-switch-variant", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -70,6 +73,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:alphabetical", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -78,6 +82,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:alphabetical", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -86,6 +91,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:alphabetical", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -94,6 +100,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:alphabetical", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -102,6 +109,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:numeric", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -110,6 +118,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:access-point-network", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -118,6 +127,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:wifi", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -126,6 +136,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:access-point-network", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -134,6 +145,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -142,6 +154,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -150,6 +163,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -158,6 +172,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -166,6 +181,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -174,6 +190,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -182,6 +199,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -190,6 +208,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -198,6 +217,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -206,6 +226,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -214,6 +235,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -222,6 +244,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -230,6 +253,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -238,6 +262,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -246,6 +271,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -254,6 +280,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -262,6 +289,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -270,6 +298,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -278,6 +307,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -286,6 +316,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -294,6 +325,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -302,6 +334,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "mdi:bathtub-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -310,6 +343,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -318,6 +352,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -326,6 +361,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, + CONF_NATIVE_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, CONF_ICON: "", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -334,6 +370,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:water-percent", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -342,6 +379,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "hass:air-filter", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -350,6 +388,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:rocket-launch", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -358,6 +397,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:leaf", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -366,6 +406,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: REVOLUTIONS_PER_MINUTE, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:fan", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -374,6 +415,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -382,6 +424,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -390,6 +433,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -398,6 +442,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -406,6 +451,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -414,6 +460,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -422,6 +469,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -430,6 +478,7 @@ CONF_DEVICE_CLASS: None, CONF_STATE_CLASS: None, CONF_UNIT_OF_MEASUREMENT: None, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:information-outline", ENABLED_DEFAULT: True, ENTITY_CATEGORY: EntityCategory.DIAGNOSTIC, @@ -438,6 +487,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.HUMIDITY, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: PERCENTAGE, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:water-percent", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -446,6 +496,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.PM1, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:blur", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -454,6 +505,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.PM25, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:blur", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, @@ -462,6 +514,7 @@ CONF_DEVICE_CLASS: SensorDeviceClass.PM10, CONF_STATE_CLASS: SensorStateClass.MEASUREMENT, CONF_UNIT_OF_MEASUREMENT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + CONF_NATIVE_UNIT_OF_MEASUREMENT: None, CONF_ICON: "mdi:blur", ENABLED_DEFAULT: True, ENTITY_CATEGORY: None, diff --git a/custom_components/daikin_onecta/sensor.py b/custom_components/daikin_onecta/sensor.py index a5a9c36..3449e8a 100644 --- a/custom_components/daikin_onecta/sensor.py +++ b/custom_components/daikin_onecta/sensor.py @@ -22,6 +22,7 @@ from .const import SENSOR_PERIOD_WEEKLY from .const import SENSOR_PERIODS from .const import VALUE_SENSOR_MAPPING +from .const import CONF_NATIVE_UNIT_OF_MEASUREMENT from .daikin_base import Appliance _LOGGER = logging.getLogger(__name__) @@ -264,6 +265,7 @@ def __init__( self._device_class = None self._state_class = None self._attr_has_entity_name = True + self._attr_native_unit_of_measurement = None sensor_settings = VALUE_SENSOR_MAPPING.get(value) if sensor_settings is None: _LOGGER.info( @@ -277,6 +279,7 @@ def __init__( self._attr_entity_registry_enabled_default = sensor_settings[ENABLED_DEFAULT] self._state_class = sensor_settings[CONF_STATE_CLASS] self._attr_entity_category = sensor_settings[ENTITY_CATEGORY] + self._attr_native_unit_of_measurement = sensor_settings[CONF_NATIVE_UNIT_OF_MEASUREMENT] mpt = management_point_type[0].upper() + management_point_type[1:] myname = value[0].upper() + value[1:] readable = re.findall("[A-Z][^A-Z]*", myname) From 3d872ce475446a8075b9fe9e9ac1a4634b1436a2 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 4 Mar 2024 10:41:47 +0100 Subject: [PATCH 2/3] Use _attr_native_value * custom_components/daikin_onecta/sensor.py: --- custom_components/daikin_onecta/sensor.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/custom_components/daikin_onecta/sensor.py b/custom_components/daikin_onecta/sensor.py index 3449e8a..ef806cb 100644 --- a/custom_components/daikin_onecta/sensor.py +++ b/custom_components/daikin_onecta/sensor.py @@ -285,7 +285,7 @@ def __init__( readable = re.findall("[A-Z][^A-Z]*", myname) self._attr_name = f"{mpt} {' '.join(readable)}" self._attr_unique_id = f"{self._device.getId()}_{self._management_point_type}_{self._sub_type}_{self._value}" - self._state = self.sensor_value() + self._attr_native_value = self.sensor_value() _LOGGER.info( "Device '%s:%s' supports sensor '%s'", device.name, @@ -295,7 +295,7 @@ def __init__( @callback def _handle_coordinator_update(self) -> None: - self._state = self.sensor_value() + self._attr_native_value = self.sensor_value() self.async_write_ha_state() def sensor_value(self): @@ -311,11 +311,6 @@ def sensor_value(self): _LOGGER.debug("Device '%s' sensor '%s' value '%s'", self._device.name, self._value, res) return res - @property - def state(self): - """Return the state of the sensor.""" - return self._state - @property def available(self): """Return the availability of the underlying device.""" From 73d310f563392db709921c3f368a18e15e375f27 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 4 Mar 2024 10:43:32 +0100 Subject: [PATCH 3/3] Use _attr_state_class and _attr_device_class * custom_components/daikin_onecta/sensor.py: --- custom_components/daikin_onecta/sensor.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/custom_components/daikin_onecta/sensor.py b/custom_components/daikin_onecta/sensor.py index ef806cb..910dd72 100644 --- a/custom_components/daikin_onecta/sensor.py +++ b/custom_components/daikin_onecta/sensor.py @@ -262,8 +262,8 @@ def __init__( self._sub_type = sub_type self._value = value self._unit_of_measurement = None - self._device_class = None - self._state_class = None + self._attr_device_class = None + self._attr_state_class = None self._attr_has_entity_name = True self._attr_native_unit_of_measurement = None sensor_settings = VALUE_SENSOR_MAPPING.get(value) @@ -274,10 +274,10 @@ def __init__( ) else: self._attr_icon = sensor_settings[CONF_ICON] - self._device_class = sensor_settings[CONF_DEVICE_CLASS] + self._attr_device_class = sensor_settings[CONF_DEVICE_CLASS] self._unit_of_measurement = sensor_settings[CONF_UNIT_OF_MEASUREMENT] self._attr_entity_registry_enabled_default = sensor_settings[ENABLED_DEFAULT] - self._state_class = sensor_settings[CONF_STATE_CLASS] + self._attr_state_class = sensor_settings[CONF_STATE_CLASS] self._attr_entity_category = sensor_settings[ENTITY_CATEGORY] self._attr_native_unit_of_measurement = sensor_settings[CONF_NATIVE_UNIT_OF_MEASUREMENT] mpt = management_point_type[0].upper() + management_point_type[1:] @@ -320,14 +320,6 @@ def available(self): def unit_of_measurement(self): return self._unit_of_measurement - @property - def state_class(self): - return self._state_class - - @property - def device_class(self): - return self._device_class - @property def device_info(self): """Return a device description for device registry."""