Skip to content

Commit

Permalink
Adds support for Big+Quiet Carbon Dioxide sensors (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotvezz authored Oct 27, 2023
1 parent 6f72499 commit a605b17
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/dyson_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://github.com/libdyson-wg/ha-dyson",
"iot_class": "local_push",
"issue_tracker": "https://github.com/libdyson-wg/ha-dyson/issues",
"version": "1.2.0"
"version": "1.3.0"
}
30 changes: 29 additions & 1 deletion custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
DysonDevice,
DysonPureCoolLink,
DysonPurifierHumidifyCool,
DysonBigQuiet,
)

from .vendor.libdyson.const import MessageType
Expand All @@ -18,6 +19,7 @@
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
CONF_NAME,
PERCENTAGE,
TEMP_CELSIUS,
Expand Down Expand Up @@ -58,7 +60,10 @@ async def async_setup_entry(
DysonParticulatesSensor(coordinator, device, name),
]
)
else: # DysonPureCool or DysonPurifierHumidifyCool
elif isinstance(device, DysonBigQuiet):
if hasattr(device, "carbon_dioxide") and device.carbon_dioxide is not None:
entities.append(DysonCarbonDioxideSensor(coordinator, device, name))
else:
entities.extend(
[
DysonPM25Sensor(coordinator, device, name),
Expand Down Expand Up @@ -386,3 +391,26 @@ def native_value(self) -> Optional[float]:
def available(self) -> bool:
"""Return available only if device not in off, init or failed states."""
return isinstance(self._device.formaldehyde, (int, float))


class DysonCarbonDioxideSensor(DysonSensorEnvironmental):
"""Dyson sensor for Carbon Dioxide."""

_SENSOR_TYPE = "c02"
_SENSOR_NAME = "Carbon Dioxide"

_attr_device_class = SensorDeviceClass.CO2
_attr_native_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION
_attr_state_class = SensorStateClass.MEASUREMENT

@property
def native_value(self) -> Optional[float]:
"""Return the state of the sensor."""
if (value := self._device.carbon_dioxide) >= 0:
return value
return None

@property
def available(self) -> bool:
"""Return available only if device not in off, init or failed states."""
return isinstance(self._device.carbon_dioxide, (int, float))
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def nitrogen_dioxide(self) -> float:
"""Return the index value for nitrogen."""
return self._get_environmental_field_value("noxl", divisor=10)

@property
def carbon_dioxide(self) -> Optional[int]:
"""Return the PPM of carbon dioxide"""
return self._get_environmental_field_value("co2r")

def turn_on(self) -> None:
"""Turn on the device."""
self._set_configuration(fpwr="ON")
Expand Down

0 comments on commit a605b17

Please sign in to comment.