From f6d31625b005a699613568cbeddbbf72606ff6e2 Mon Sep 17 00:00:00 2001 From: Ben Vezzani Date: Thu, 4 May 2023 17:28:09 -0400 Subject: [PATCH] Fixes environmental data reporting (#17) - Improves the display of Formaldehyde data to show a graph - Sets the VOC and NO2 to their correct index scales instead of the incorrect mass measurements. - Creates new sensor entities for the above to avoid conversion errors in Home Assistant --- custom_components/dyson_local/manifest.json | 4 +- custom_components/dyson_local/sensor.py | 52 ++++++++++----------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/custom_components/dyson_local/manifest.json b/custom_components/dyson_local/manifest.json index 4f5ae02..dedba04 100644 --- a/custom_components/dyson_local/manifest.json +++ b/custom_components/dyson_local/manifest.json @@ -6,7 +6,7 @@ "issue_tracker": "https://github.com/libdyson-wg/ha-dyson/issues", "dependencies": ["zeroconf"], "codeowners": ["@libdyson-wg"], - "requirements": ["libdyson-neon==1.0.0"], - "version": "0.18.0", + "requirements": ["libdyson-neon==1.0.1"], + "version": "0.18.1", "iot_class": "local_polling" } diff --git a/custom_components/dyson_local/sensor.py b/custom_components/dyson_local/sensor.py index 7b7c14f..dae5ba1 100644 --- a/custom_components/dyson_local/sensor.py +++ b/custom_components/dyson_local/sensor.py @@ -125,7 +125,7 @@ class DysonBatterySensor(DysonSensor): _attr_native_unit_of_measurement = PERCENTAGE @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.battery_level @@ -140,7 +140,7 @@ class DysonFilterLifeSensor(DysonSensor): _attr_native_unit_of_measurement = TIME_HOURS @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.filter_life @@ -155,7 +155,7 @@ class DysonCarbonFilterLifeSensor(DysonSensor): _attr_native_unit_of_measurement = PERCENTAGE @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.carbon_filter_life @@ -170,7 +170,7 @@ class DysonHEPAFilterLifeSensor(DysonSensor): _attr_native_unit_of_measurement = PERCENTAGE @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.hepa_filter_life @@ -185,7 +185,7 @@ class DysonCombinedFilterLifeSensor(DysonSensor): _attr_native_unit_of_measurement = PERCENTAGE @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.hepa_filter_life @@ -200,7 +200,7 @@ class DysonNextDeepCleanSensor(DysonSensor): _attr_native_unit_of_measurement = TIME_HOURS @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.time_until_next_clean @@ -215,7 +215,7 @@ class DysonHumiditySensor(DysonSensorEnvironmental): _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.humidity @@ -259,7 +259,7 @@ class DysonPM25Sensor(DysonSensorEnvironmental): _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.particulate_matter_2_5 @@ -274,7 +274,7 @@ class DysonPM10Sensor(DysonSensorEnvironmental): _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.particulate_matter_10 @@ -282,14 +282,13 @@ def state(self) -> int: class DysonParticulatesSensor(DysonSensorEnvironmental): """Dyson sensor for particulate matters for "Link" devices.""" - _SENSOR_TYPE = "pm1" - _SENSOR_NAME = "Particulates" + _SENSOR_TYPE = "aqi" + _SENSOR_NAME = "Air Quality Index" _attr_device_class = SensorDeviceClass.PM1 - _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.particulates @@ -297,14 +296,13 @@ def state(self) -> int: class DysonVOCSensor(DysonSensorEnvironmental): """Dyson sensor for volatile organic compounds.""" - _SENSOR_TYPE = "voc" - _SENSOR_NAME = "Volatile Organic Compounds" - _attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS - _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER + _SENSOR_TYPE = "voc-index" + _SENSOR_NAME = "Volatile Organic Compounds Index" + _attr_device_class = SensorDeviceClass.AQI _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> float: """Return the state of the sensor.""" return self._device.volatile_organic_compounds @@ -312,27 +310,27 @@ def state(self) -> int: class DysonNO2Sensor(DysonSensorEnvironmental): """Dyson sensor for Nitrogen Dioxide.""" - _SENSOR_TYPE = "no2" - _SENSOR_NAME = "Nitrogen Dioxide" - _attr_device_class = SensorDeviceClass.NITROGEN_DIOXIDE - _attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER + _SENSOR_TYPE = "no2-index" + _SENSOR_NAME = "Nitrogen Dioxide Index" + _attr_device_class = SensorDeviceClass.AQI _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._device.nitrogen_dioxide - + class DysonHCHOSensor(DysonSensorEnvironmental): """Dyson sensor for Formaldehyde.""" _SENSOR_TYPE = "hcho" _SENSOR_NAME = "Formaldehyde" + _attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS - _attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER + _attr_state_class = SensorStateClass.MEASUREMENT @environmental_property - def state(self) -> int: + def native_value(self) -> float: """Return the state of the sensor.""" - return self._device.formaldehyde + return self._device.nitrogen_dioxide