From 0a46869deafb713b9b89958e023155f40ebb2c4b Mon Sep 17 00:00:00 2001 From: Ben Vezzani Date: Thu, 6 Jul 2023 00:15:44 -0400 Subject: [PATCH] Finally using correct units for Formaldehyde --- custom_components/dyson_local/sensor.py | 4 +++- .../dyson_local/vendor/libdyson/dyson_device.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/dyson_local/sensor.py b/custom_components/dyson_local/sensor.py index 4184363..7406d22 100644 --- a/custom_components/dyson_local/sensor.py +++ b/custom_components/dyson_local/sensor.py @@ -17,6 +17,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER, CONF_NAME, PERCENTAGE, TEMP_CELSIUS, @@ -372,10 +373,11 @@ class DysonHCHOSensor(DysonSensorEnvironmental): _SENSOR_NAME = "Formaldehyde" _attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS + _attr_native_unit_of_measurement = CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER _attr_state_class = SensorStateClass.MEASUREMENT @property - def native_value(self) -> Optional[int]: + def native_value(self) -> Optional[float]: """Return the state of the sensor.""" if (value := self._device.formaldehyde) >= 0: return value diff --git a/custom_components/dyson_local/vendor/libdyson/dyson_device.py b/custom_components/dyson_local/vendor/libdyson/dyson_device.py index 0760383..8a3407f 100644 --- a/custom_components/dyson_local/vendor/libdyson/dyson_device.py +++ b/custom_components/dyson_local/vendor/libdyson/dyson_device.py @@ -257,13 +257,13 @@ def warning_code(self) -> str: return self._get_field_value(self._status, "wacd") @property - def formaldehyde(self) -> Optional[int]: + def formaldehyde(self) -> Optional[float]: """Return formaldehyde reading.""" - val = self._get_environmental_field_value("hcho") + val = self._get_environmental_field_value("hchr", divisor=1000) if val is None: return None - return int(val) + return float(val) @property def humidity(self) -> int: