Skip to content

Commit

Permalink
Initial refactor for formaldehyde
Browse files Browse the repository at this point in the history
  • Loading branch information
dotvezz authored May 1, 2023
1 parent 3e5d860 commit 67f6a54
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 28 deletions.
6 changes: 2 additions & 4 deletions custom_components/dyson_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
Dyson360Heurist,
DysonPureHotCool,
DysonPureHotCoolLink,
DysonPureHumidifyCool,
DysonPurifierHumidifyCoolFormaldehyde,
DysonPurifierHumidifyCool,
MessageType,
get_device,
)
Expand Down Expand Up @@ -158,8 +157,7 @@ def _async_get_platforms(device: DysonDevice) -> List[str]:
platforms.append("climate")
if isinstance(device, DysonPureHotCoolLink):
platforms.extend(["binary_sensor", "climate"])
if isinstance(device, DysonPureHumidifyCool) or isinstance(
device, DysonPurifierHumidifyCoolFormaldehyde):
if isinstance(device, DysonPurifierHumidifyCool):
platforms.append("humidifier")
return platforms

Expand Down
6 changes: 3 additions & 3 deletions custom_components/dyson_local/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ async def async_setup_entry(
entity = DysonPureCoolLinkEntity(device, name)
elif isinstance(device, DysonPureCool):
entity = DysonPureCoolEntity(device, name)
else: # DysonPureHumidityCool
entity = DysonPureHumidifyCoolEntity(device, name)
else: # DysonPurifierHumidifyCool
entity = DysonPurifierHumidifyCoolEntity(device, name)
async_add_entities([entity])

platform = entity_platform.current_platform.get()
Expand Down Expand Up @@ -243,7 +243,7 @@ def set_angle(self, angle_low: int, angle_high: int) -> None:
self._device.enable_oscillation(angle_low, angle_high)


class DysonPureHumidifyCoolEntity(DysonFanEntity):
class DysonPurifierHumidifyCoolEntity(DysonFanEntity):
"""Dyson Pure Humidify+Cool entity."""

@property
Expand Down
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==0.10.2"],
"version": "0.17.2",
"requirements": ["libdyson-neon==1.0.0"],
"version": "0.18.0",
"iot_class": "local_polling"
}
6 changes: 2 additions & 4 deletions custom_components/dyson_local/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from libdyson import (
DysonPureCoolLink,
DysonPureHotCoolLink,
DysonPureHumidifyCool,
DysonPurifierHumidifyCoolFormaldehyde,
DysonPurifierHumidifyCool,
HumidifyOscillationMode,
WaterHardness,
)
Expand Down Expand Up @@ -66,8 +65,7 @@ async def async_setup_entry(
device, DysonPureCoolLink
):
entities.append(DysonAirQualitySelect(device, name))
if isinstance(device, DysonPureHumidifyCool) or isinstance(
device, DysonPurifierHumidifyCoolFormaldehyde):
if isinstance(device, DysonPurifierHumidifyCool):
entities.extend(
[
DysonOscillationModeSelect(device, name),
Expand Down
13 changes: 7 additions & 6 deletions custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
Dyson360Heurist,
DysonDevice,
DysonPureCoolLink,
DysonPureHumidifyCool,
DysonPurifierHumidifyCoolFormaldehyde,
DysonPurifierHumidifyCool,
)

from libdyson.const import MessageType
from libdyson.dyson_device import DysonFanDevice

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -48,14 +49,15 @@ async def async_setup_entry(
DysonTemperatureSensor(coordinator, device, name),
DysonVOCSensor(coordinator, device, name),
]

if isinstance(device, DysonPureCoolLink):
entities.extend(
[
DysonFilterLifeSensor(device, name),
DysonParticulatesSensor(coordinator, device, name),
]
)
else: # DysonPureCool or DysonPureHumidifyCool
else: # DysonPureCool or DysonPurifierHumidifyCool
entities.extend(
[
DysonPM25Sensor(coordinator, device, name),
Expand All @@ -72,10 +74,9 @@ async def async_setup_entry(
DysonHEPAFilterLifeSensor(device, name),
]
)
if isinstance(device, DysonPureHumidifyCool) or isinstance(
device, DysonPurifierHumidifyCoolFormaldehyde):
if isinstance(device, DysonPurifierHumidifyCool):
entities.append(DysonNextDeepCleanSensor(device, name))
if isinstance(device, DysonPurifierHumidifyCoolFormaldehyde):
if hasattr(device, "formaldehyde") and device.formaldehyde is not None:
entities.append(DysonHCHOSensor(coordinator, device, name))
async_add_entities(entities)

Expand Down
10 changes: 5 additions & 5 deletions tests/dyson_local/test_humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from unittest.mock import patch

from libdyson import DEVICE_TYPE_PURE_HUMIDIFY_COOL, DysonPureHumidifyCool, MessageType
from libdyson import DEVICE_TYPE_PURE_HUMIDIFY_COOL, DysonPurifierHumidifyCool, MessageType
from libdyson.const import AirQualityTarget
import pytest

Expand Down Expand Up @@ -40,9 +40,9 @@


@pytest.fixture
def device() -> DysonPureHumidifyCool:
def device() -> DysonPurifierHumidifyCool:
"""Return mocked device."""
device = get_base_device(DysonPureHumidifyCool, DEVICE_TYPE_PURE_HUMIDIFY_COOL)
device = get_base_device(DysonPurifierHumidifyCool, DEVICE_TYPE_PURE_HUMIDIFY_COOL)
device.is_on = True
device.speed = 5
device.auto_mode = False
Expand All @@ -55,7 +55,7 @@ def device() -> DysonPureHumidifyCool:
yield device


async def test_state(hass: HomeAssistant, device: DysonPureHumidifyCool):
async def test_state(hass: HomeAssistant, device: DysonPurifierHumidifyCool):
"""Test entity state and attributes."""
state = hass.states.get(ENTITY_ID)
assert state.state == STATE_ON
Expand Down Expand Up @@ -105,7 +105,7 @@ async def test_state(hass: HomeAssistant, device: DysonPureHumidifyCool):
)
async def test_command(
hass: HomeAssistant,
device: DysonPureHumidifyCool,
device: DysonPurifierHumidifyCool,
service: str,
service_data: dict,
command: str,
Expand Down
8 changes: 4 additions & 4 deletions tests/dyson_local/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Dyson360Heurist,
DysonPureCool,
DysonPureCoolLink,
DysonPureHumidifyCool,
DysonPurifierHumidifyCool,
)
from libdyson.const import ENVIRONMENTAL_OFF, MessageType
from libdyson.dyson_device import DysonDevice, DysonFanDevice
Expand Down Expand Up @@ -67,8 +67,8 @@ def _get_pure_cool_seperated() -> DysonPureCool:
return device


def _get_pure_humidify_cool() -> DysonPureHumidifyCool:
device = _get_fan(DysonPureHumidifyCool, DEVICE_TYPE_PURE_HUMIDIFY_COOL)
def _get_pure_humidify_cool() -> DysonPurifierHumidifyCool:
device = _get_fan(DysonPurifierHumidifyCool, DEVICE_TYPE_PURE_HUMIDIFY_COOL)
device.carbon_filter_life = None
device.hepa_filter_life = 50
device.time_until_next_clean = 1800
Expand Down Expand Up @@ -178,7 +178,7 @@ async def test_pure_cool_seperated(hass: HomeAssistant, device: DysonFanDevice):


@pytest.mark.parametrize("device", [_get_pure_humidify_cool], indirect=True)
async def test_pure_humidify_cool(hass: HomeAssistant, device: DysonPureHumidifyCool):
async def test_pure_humidify_cool(hass: HomeAssistant, device: DysonPurifierHumidifyCool):
"""Test Pure Humidify+Cool sensors."""
assert hass.states.get(f"sensor.{NAME}_next_deep_clean").state == "1800"
device.time_until_next_clean = 1500
Expand Down

0 comments on commit 67f6a54

Please sign in to comment.