From 5b5ff41e981c499622a162556ee12e861d4bed75 Mon Sep 17 00:00:00 2001 From: vwt12eh8 <63479906+vwt12eh8@users.noreply.github.com> Date: Sun, 28 Nov 2021 20:44:00 +0900 Subject: [PATCH 1/3] Support Purifier Humidify+Cool Formaldehyde --- libdyson/__init__.py | 5 ++++- libdyson/const.py | 2 ++ libdyson/dyson_pure_humidify_cool.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libdyson/__init__.py b/libdyson/__init__.py index d6d6d33..7b05791 100644 --- a/libdyson/__init__.py +++ b/libdyson/__init__.py @@ -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 @@ -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 @@ -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 diff --git a/libdyson/const.py b/libdyson/const.py index 324ef0b..254e1cb 100644 --- a/libdyson/const.py +++ b/libdyson/const.py @@ -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" @@ -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 diff --git a/libdyson/dyson_pure_humidify_cool.py b/libdyson/dyson_pure_humidify_cool.py index 99c932b..ebe39e2 100644 --- a/libdyson/dyson_pure_humidify_cool.py +++ b/libdyson/dyson_pure_humidify_cool.py @@ -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) -> int: + """Return formaldehyde reading.""" + return self._get_environmental_field_value("hcho") From 2caedcef72a4778f7f1df2691bedd37bbe7b9316 Mon Sep 17 00:00:00 2001 From: vwt12eh8 <63479906+vwt12eh8@users.noreply.github.com> Date: Mon, 29 Nov 2021 18:44:11 +0900 Subject: [PATCH 2/3] Fix return type problem --- libdyson/dyson_pure_humidify_cool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdyson/dyson_pure_humidify_cool.py b/libdyson/dyson_pure_humidify_cool.py index ebe39e2..cf170e0 100644 --- a/libdyson/dyson_pure_humidify_cool.py +++ b/libdyson/dyson_pure_humidify_cool.py @@ -105,6 +105,6 @@ class DysonPurifierHumidifyCoolFormaldehyde(DysonPureHumidifyCool): """Dyson Purifier Humidify+Cool Formaldehyde device.""" @property - def formaldehyde(self) -> int: + def formaldehyde(self): """Return formaldehyde reading.""" - return self._get_environmental_field_value("hcho") + return int(self._get_environmental_field_value("hcho")) From dd4ff489e6ad7a1aab0ee39cdc8093a5a5335e6b Mon Sep 17 00:00:00 2001 From: vwt12eh8 <63479906+vwt12eh8@users.noreply.github.com> Date: Mon, 29 Nov 2021 12:45:23 +0900 Subject: [PATCH 3/3] Add test for Purifier Humidify+Cool Formaldehyde --- tests/test_init.py | 3 + ...est_purifier_humidify_cool_formaldehyde.py | 69 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/test_purifier_humidify_cool_formaldehyde.py diff --git a/tests/test_init.py b/tests/test_init.py index d29fc59..e44111f 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -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, @@ -24,6 +25,7 @@ DysonPureHotCool, DysonPureHotCoolLink, DysonPureHumidifyCool, + DysonPurifierHumidifyCoolFormaldehyde, get_device, ) @@ -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]): diff --git a/tests/test_purifier_humidify_cool_formaldehyde.py b/tests/test_purifier_humidify_cool_formaldehyde.py new file mode 100644 index 0000000..954ad62 --- /dev/null +++ b/tests/test_purifier_humidify_cool_formaldehyde.py @@ -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