Skip to content

Commit

Permalink
Finally using correct units for Formaldehyde
Browse files Browse the repository at this point in the history
  • Loading branch information
dotvezz committed Jul 6, 2023
1 parent 67fb01f commit 0a46869
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions custom_components/dyson_local/vendor/libdyson/dyson_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0a46869

Please sign in to comment.