Skip to content

Commit

Permalink
Fixes environmental data reporting (#17)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dotvezz committed May 5, 2023
1 parent 67f6a54 commit f6d3162
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions custom_components/dyson_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
52 changes: 25 additions & 27 deletions custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -274,65 +274,63 @@ 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


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


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


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

0 comments on commit f6d3162

Please sign in to comment.