Skip to content

Commit

Permalink
Merge pull request #19 from vwt12eh8/ph04
Browse files Browse the repository at this point in the history
Support Purifier Humidify+Cool Formaldehyde
  • Loading branch information
Kakise authored Nov 29, 2021
2 parents e52f4da + dd4ff48 commit 7b19d1c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libdyson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DEVICE_TYPE_PURE_HOT_COOL_NEW,
DEVICE_TYPE_PURE_HOT_COOL_LINK,
DEVICE_TYPE_PURE_HUMIDIFY_COOL,
DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE,
)
from .const import CleaningMode # noqa: F401
from .const import CleaningType # noqa: F401
Expand All @@ -33,7 +34,7 @@
from .dyson_pure_cool_link import DysonPureCoolLink
from .dyson_pure_hot_cool import DysonPureHotCool
from .dyson_pure_hot_cool_link import DysonPureHotCoolLink
from .dyson_pure_humidify_cool import DysonPureHumidifyCool
from .dyson_pure_humidify_cool import DysonPureHumidifyCool, DysonPurifierHumidifyCoolFormaldehyde
from .utils import get_mqtt_info_from_wifi_info # noqa: F401


Expand Down Expand Up @@ -64,4 +65,6 @@ def get_device(serial: str, credential: str, device_type: str) -> Optional[Dyson
return DysonPureHotCool(serial, credential, device_type)
if device_type == DEVICE_TYPE_PURE_HUMIDIFY_COOL:
return DysonPureHumidifyCool(serial, credential, device_type)
if device_type == DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE:
return DysonPurifierHumidifyCoolFormaldehyde(serial, credential, device_type)
return None
2 changes: 2 additions & 0 deletions libdyson/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
DEVICE_TYPE_PURE_COOL_FORMALDEHYDE = "438E"
DEVICE_TYPE_PURE_COOL_DESK = "520"
DEVICE_TYPE_PURE_HUMIDIFY_COOL = "358"
DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE = "358E"
DEVICE_TYPE_PURE_HOT_COOL_LINK = "455"
DEVICE_TYPE_PURE_HOT_COOL = "527"
DEVICE_TYPE_PURE_HOT_COOL_NEW = "527E"
Expand All @@ -25,6 +26,7 @@
DEVICE_TYPE_PURE_HOT_COOL_NEW: "Pure Hot+Cool (New)",
DEVICE_TYPE_PURE_HOT_COOL_LINK: "Pure Hot+Cool Link",
DEVICE_TYPE_PURE_HUMIDIFY_COOL: "Pure Humidify+Cool",
DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE: "Purifier Humidify+Cool Formaldehyde",
}

ENVIRONMENTAL_OFF = -1
Expand Down
9 changes: 9 additions & 0 deletions libdyson/dyson_pure_humidify_cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ def set_target_humidity(self, target_humidity: int) -> None:
def set_water_hardness(self, water_hardness: WaterHardness) -> None:
"""Set water hardness."""
self._set_configuration(wath=WATER_HARDNESS_ENUM_TO_STR[water_hardness])


class DysonPurifierHumidifyCoolFormaldehyde(DysonPureHumidifyCool):
"""Dyson Purifier Humidify+Cool Formaldehyde device."""

@property
def formaldehyde(self):
"""Return formaldehyde reading."""
return int(self._get_environmental_field_value("hcho"))
3 changes: 3 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DEVICE_TYPE_PURE_HOT_COOL_NEW,
DEVICE_TYPE_PURE_HOT_COOL_LINK,
DEVICE_TYPE_PURE_HUMIDIFY_COOL,
DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE,
Dyson360Eye,
Dyson360Heurist,
DysonDevice,
Expand All @@ -24,6 +25,7 @@
DysonPureHotCool,
DysonPureHotCoolLink,
DysonPureHumidifyCool,
DysonPurifierHumidifyCoolFormaldehyde,
get_device,
)

Expand All @@ -44,6 +46,7 @@
(DEVICE_TYPE_PURE_HOT_COOL, DysonPureHotCool),
(DEVICE_TYPE_PURE_HOT_COOL_NEW, DysonPureHotCool),
(DEVICE_TYPE_PURE_HUMIDIFY_COOL, DysonPureHumidifyCool),
(DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE, DysonPurifierHumidifyCoolFormaldehyde),
],
)
def test_get_device(device_type: str, class_type: Type[DysonDevice]):
Expand Down
69 changes: 69 additions & 0 deletions tests/test_purifier_humidify_cool_formaldehyde.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Tests for Purifier Humidify+Cool Formaldehyde"""

import pytest

from libdyson.const import (
DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE,
ENVIRONMENTAL_FAIL,
ENVIRONMENTAL_INIT,
ENVIRONMENTAL_OFF,
)
from libdyson.dyson_pure_humidify_cool import DysonPurifierHumidifyCoolFormaldehyde

from . import CREDENTIAL, HOST, SERIAL
from .mocked_mqtt import MockedMQTT
from .test_pure_humidify_cool import STATUS as TEST_PURE_HUMIDIFY_COOL_STATUS

DEVICE_TYPE = DEVICE_TYPE_PURIFIER_HUMIDIFY_COOL_FORMALDEHYDE

STATUS = TEST_PURE_HUMIDIFY_COOL_STATUS
ENVIRONMENTAL_DATA = {
"data": {
"tact": "OFF",
"hact": "OFF",
"pm25": "OFF",
"pm10": "OFF",
"va10": "INIT",
"noxl": "FAIL",
"p25r": "OFF",
"p10r": "OFF",
"sltm": "OFF",
"hcho": "OFF",
"hchr": "OFF",
}
}


def test_properties(mqtt_client: MockedMQTT):
"""Test properties of Purifier Humidify+Cool Formaldehyde."""
device = DysonPurifierHumidifyCoolFormaldehyde(SERIAL, CREDENTIAL, DEVICE_TYPE)
device.connect(HOST)

# Environmental
assert device.particulate_matter_2_5 == ENVIRONMENTAL_OFF
assert device.particulate_matter_10 == ENVIRONMENTAL_OFF
assert device.volatile_organic_compounds == ENVIRONMENTAL_INIT
assert device.nitrogen_dioxide == ENVIRONMENTAL_FAIL
assert device.formaldehyde == ENVIRONMENTAL_OFF

mqtt_client._environmental_data = {
"data": {
"tact": "2977",
"hact": "0058",
"pm25": "0009",
"pm10": "0005",
"va10": "0004",
"noxl": "0011",
"p25r": "0010",
"p10r": "0009",
"sltm": "OFF",
"hcho": "0001",
"hchr": "0002",
}
}
device.request_environmental_data()
assert device.particulate_matter_2_5 == 9
assert device.particulate_matter_10 == 5
assert device.volatile_organic_compounds == 4
assert device.nitrogen_dioxide == 11
assert device.formaldehyde == 1

0 comments on commit 7b19d1c

Please sign in to comment.