Kaynağa Gözat

Wilfa Haze: tweaks to config

- fix step of humidity.
- add back binary_sensor now that water level error is identified.
- use standard modes from https://github.com/home-assistant/core/blob/dev/homeassistant/components/humidifier/const.py
- Add tests
Jason Rumney 3 yıl önce
ebeveyn
işleme
533a7a20f7

+ 15 - 2
custom_components/tuya_local/devices/wilfa_haze_hu400bc_humidifier.yaml

@@ -21,7 +21,7 @@ primary_entity:
         max: 90
       mapping:
         - step: 5
-        - constraint: mode
+          constraint: mode
           conditions:
             - dps_val: AUTO
               invalid: true
@@ -32,7 +32,7 @@ primary_entity:
         - dps_val: AUTO
           value: auto
         - dps_val: MANUAL
-          value: humidity
+          value: normal
     - id: 20
       type: integer
       name: unknown_20
@@ -191,3 +191,16 @@ secondary_entities:
       - id: 35
         name: switch
         type: boolean
+  - entity: binary_sensor
+    class: problem
+    name: Tank
+    category: diagnostic
+    icon: "mdi:cup-outline"
+    dps:
+      - id: 22
+        type: bitfield
+        name: sensor
+        mapping:
+          - dps_val: 1
+            value: true
+          - value: false

+ 4 - 0
custom_components/tuya_local/translations/en.json

@@ -152,11 +152,13 @@
                     "sensor_timer": "Include time remaining as a sensor entity",
                     "sensor_voltage": "Include voltage as a sensor entity",
                     "sensor_ambient_temperature": "Include ambient temperature as a sensor entity",
+		    "sensor_compressor_speed": "Include compressor speed as a sensor entity",
                     "sensor_cooling_coil_pipe_temperature": "Include cooling coil pipe temperature as a sensor entity",
                     "sensor_cooling_plate_temperature": "Include cooling plate temperature as a sensor entity",
                     "sensor_eev_opening": "Include EEV opening as a sensor entity",
                     "sensor_evaporator_coil_pipe_temperature": "Include evaporator coil pipe temperature as a sensor entity",
                     "sensor_exhaust_gas_temperature": "Include exhaust gas temperature as a sensor entity",
+		    "sensor_fan_speed": "Include fan speed as a sensor entity",
                     "sensor_outlet_water_temperature": "Include outlet water temperature as a sensor entity",
                     "sensor_return_gas_temperature": "Include return gas temperature as a sensor entity",
                     "sensor_water_level": "Include water level as a sensor entity",
@@ -335,11 +337,13 @@
                     "sensor_timer": "Include time remaining as a sensor entity",
                     "sensor_voltage": "Include voltage as a sensor entity",
                     "sensor_ambient_temperature": "Include ambient temperature as a sensor entity",
+		    "sensor_compressor_speed": "Include compressor speed as a sensor entity",
                     "sensor_cooling_coil_pipe_temperature": "Include cooling coil pipe temperature as a sensor entity",
                     "sensor_cooling_plate_temperature": "Include cooling plate temperature as a sensor entity",
                     "sensor_eev_opening": "Include EEV opening as a sensor entity",
                     "sensor_evaporator_coil_pipe_temperature": "Include evaporator coil pipe temperature as a sensor entity",
                     "sensor_exhaust_gas_temperature": "Include exhaust gas temperature as a sensor entity",
+		    "sensor_fan_speed": "Include fan speed as a sensor entity",
                     "sensor_outlet_water_temperature": "Include outlet water temperature as a sensor entity",
                     "sensor_return_gas_temperature": "Include return gas temperature as a sensor entity",
                     "sensor_water_level": "Include water level as a sensor entity",

+ 19 - 1
tests/const.py

@@ -181,7 +181,7 @@ MADIMACK_HEATPUMP_PAYLOAD = {
     "105": "warm",
     "106": 30,
     "107": 18,
-    "108": 40,
+    "108": 45,
     "115": 4,
     "116": 0,
     "117": True,
@@ -1163,3 +1163,21 @@ STARLIGHT_HEATPUMP_PAYLOAD = {
     "133": "0",
     "134": '{"t":8601,"s":false,"clr":true}',
 }
+
+WILFA_HAZE_HUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "5": False,
+    "8": False,
+    "10": 20,
+    "13": 70,
+    "14": 55,
+    "16": False,
+    "18": "c",
+    "19": "cancel",
+    "20": 0,
+    "22": 0,
+    "23": "level_3",
+    "24": "MANUAL",
+    "26": False,
+    "35": False,
+}

+ 202 - 0
tests/devices/test_wilfa_haze_hu400bc_humidifier.py

@@ -0,0 +1,202 @@
+from homeassistant.components.binary_sensor import BinarySensorDeviceClass
+from homeassistant.components.humidifier.const import (
+    MODE_AUTO,
+    MODE_NORMAL,
+    SUPPORT_MODES,
+)
+from homeassistant.components.sensor import SensorDeviceClass
+from homeassistant.components.humidifier import HumidifierDeviceClass
+
+from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
+
+from ..const import WILFA_HAZE_HUMIDIFIER_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.binary_sensor import BasicBinarySensorTests
+from ..mixins.light import MultiLightTests
+from ..mixins.select import MultiSelectTests
+from ..mixins.sensor import MultiSensorTests
+from ..mixins.switch import MultiSwitchTests, SwitchableTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DPS = "1"
+LIGHT_DPS = "5"
+SOUND_DPS = "8"
+CURRENTTEMP_DPS = "10"
+HUMIDITY_DPS = "13"
+CURRENTHUMID_DPS = "14"
+SLEEP_DPS = "16"
+UNIT_DPS = "18"
+TIMER_DPS = "19"
+UNKNOWN20_DPS = "20"
+ERROR_DPS = "22"
+FAN_DPS = "23"
+PRESET_DPS = "24"
+CLEAN_DPS = "26"
+IONIZER_DPS = "35"
+
+
+class TestWilfaHazeHumidifier(
+    BasicBinarySensorTests,
+    MultiLightTests,
+    MultiSelectTests,
+    MultiSensorTests,
+    MultiSwitchTests,
+    SwitchableTests,
+    TuyaDeviceTestCase,
+):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "wilfa_haze_hu400bc_humidifier.yaml", WILFA_HAZE_HUMIDIFIER_PAYLOAD
+        )
+        self.subject = self.entities.get("humidifier")
+        self.fan = self.entities.get("fan")
+        self.setUpSwitchable(SWITCH_DPS, self.subject)
+        self.setUpBasicBinarySensor(
+            ERROR_DPS,
+            self.entities.get("binary_sensor_tank"),
+            testdata=(1, 0),
+            device_class=BinarySensorDeviceClass.PROBLEM,
+        )
+        self.setUpMultiLights(
+            [
+                {
+                    "dps": SLEEP_DPS,
+                    "name": "light_display",
+                    "testdata": (False, True),
+                },
+                {
+                    "dps": LIGHT_DPS,
+                    "name": "light_mood",
+                },
+            ],
+        )
+        self.setUpMultiSelect(
+            [
+                {
+                    "dps": TIMER_DPS,
+                    "name": "select_timer",
+                    "options": {
+                        "cancel": "Off",
+                        "1": "1 hour",
+                        "2": "2 hours",
+                        "3": "3 hours",
+                        "4": "4 hours",
+                        "5": "5 hours",
+                        "6": "6 hours",
+                        "7": "7 hours",
+                        "8": "8 hours",
+                        "9": "9 hours",
+                        "10": "10 hours",
+                        "11": "11 hours",
+                        "12": "12 hours",
+                    },
+                },
+                {
+                    "dps": UNIT_DPS,
+                    "name": "select_temperature_unit",
+                    "options": {
+                        "c": "Celsius",
+                        "f": "Fahrenheit",
+                    },
+                },
+            ],
+        )
+        self.setUpMultiSensors(
+            [
+                {
+                    "dps": CURRENTTEMP_DPS,
+                    "name": "sensor_current_temperature",
+                    "device_class": SensorDeviceClass.TEMPERATURE,
+                    "state_class": "measurement",
+                    "unit": TEMP_CELSIUS,
+                },
+                {
+                    "dps": CURRENTHUMID_DPS,
+                    "name": "sensor_current_humidity",
+                    "device_class": SensorDeviceClass.HUMIDITY,
+                    "state_class": "measurement",
+                    "unit": PERCENTAGE,
+                },
+            ]
+        )
+        self.setUpMultiSwitch(
+            [
+                {
+                    "dps": SOUND_DPS,
+                    "name": "switch_sound",
+                },
+                {
+                    "dps": CLEAN_DPS,
+                    "name": "switch_air_clean",
+                },
+                {
+                    "dps": IONIZER_DPS,
+                    "name": "switch_ionizer",
+                },
+            ]
+        )
+        self.mark_secondary(
+            [
+                "binary_sensor_tank",
+                "light_display",
+                "light_mood",
+                "select_temperature_unit",
+                "select_timer",
+                "switch_air_clean",
+                "switch_ionizer",
+                "switch_sound",
+            ]
+        )
+
+    def test_supported_features(self):
+        self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
+
+    def test_icons(self):
+        self.dps[SWITCH_DPS] = True
+        self.assertEqual(self.subject.icon, "mdi:air-humidifier")
+        self.dps[SWITCH_DPS] = False
+        self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
+
+    def test_min_target_humidity(self):
+        self.assertEqual(self.subject.min_humidity, 30)
+
+    def test_max_target_humidity(self):
+        self.assertEqual(self.subject.max_humidity, 90)
+
+    def test_target_humidity(self):
+        self.dps[HUMIDITY_DPS] = 55
+        self.assertEqual(self.subject.target_humidity, 55)
+
+    def test_available_modes(self):
+        self.assertCountEqual(
+            self.subject.available_modes,
+            [MODE_AUTO, MODE_NORMAL],
+        )
+
+    def test_mode(self):
+        self.dps[PRESET_DPS] = "AUTO"
+        self.assertEqual(self.subject.mode, MODE_AUTO)
+        self.dps[PRESET_DPS] = "MANUAL"
+        self.assertEqual(self.subject.mode, MODE_NORMAL)
+
+    async def test_set_mode_to_auto(self):
+        async with assert_device_properties_set(
+            self.subject._device, {PRESET_DPS: "AUTO"}
+        ):
+            await self.subject.async_set_mode(MODE_AUTO)
+
+    async def test_set_mode_to_normal(self):
+        async with assert_device_properties_set(
+            self.subject._device, {PRESET_DPS: "MANUAL"}
+        ):
+            await self.subject.async_set_mode(MODE_NORMAL)
+
+    def test_extra_state_attributes(self):
+        self.dps[UNKNOWN20_DPS] = 20
+        self.dps[ERROR_DPS] = 22
+        self.assertDictEqual(
+            self.subject.extra_state_attributes,
+            {"unknown_20": 20, "error": 22},
+        )

+ 94 - 2
tests/mixins/light.py

@@ -26,10 +26,10 @@ class BasicLightTests:
     def test_basic_light_color_mode(self):
         self.assertEqual(self.basicLight.color_mode, COLOR_MODE_ONOFF)
 
-    def test_light_has_no_brightness(self):
+    def test_basic_light_has_no_brightness(self):
         self.assertIsNone(self.basicLight.brightness)
 
-    def test_light_has_no_effects(self):
+    def test_basic_light_has_no_effects(self):
         self.assertIsNone(self.basicLight.effect_list)
         self.assertIsNone(self.basicLight.effect)
 
@@ -71,6 +71,98 @@ class BasicLightTests:
         self.assertEqual(self.basicLight.extra_state_attributes, {})
 
 
+class MultiLightTests:
+    def setUpMultiLights(self, lights):
+        self.multiLight = {}
+        self.multiLightDps = {}
+        self.multiLightOn = {}
+        self.multiLightOff = {}
+        for l in lights:
+            name = l["name"]
+            subject = self.entities.get(name)
+            testdata = l.get("testdata", (True, False))
+            if subject is None:
+                raise AttributeError(f"No light for {name} found.")
+            self.multiLight[name] = subject
+            self.multiLightDps[name] = l.get("dps")
+            self.multiLightOn[name] = testdata[0]
+            self.multiLightOff[name] = testdata[1]
+
+    def test_multi_light_supported_features(self):
+        for light in self.multiLight.values():
+            self.assertEqual(light.supported_features, 0)
+
+    def test_multi_light_supported_color_modes(self):
+        for light in self.multiLight.values():
+            self.assertCountEqual(
+                light.supported_color_modes,
+                [COLOR_MODE_ONOFF],
+            )
+
+    def test_multi_light_color_mode(self):
+        for light in self.multiLight.values():
+            self.assertEqual(light.color_mode, COLOR_MODE_ONOFF)
+
+    def test_multi_lights_have_no_brightness(self):
+        for light in self.multiLight.values():
+            self.assertIsNone(light.brightness)
+
+    def test_multi_lights_have_no_effects(self):
+        for light in self.multiLight.values():
+            self.assertIsNone(light.effect_list)
+            self.assertIsNone(light.effect)
+
+    def test_multi_light_is_on(self):
+        for key, light in self.multiLight.items():
+            with self.subTest(key):
+                dp_id = self.multiLightDps[key]
+                self.dps[dp_id] = self.multiLightOn[key]
+                self.assertTrue(light.is_on)
+                self.dps[dp_id] = self.multiLightOff[key]
+                self.assertFalse(light.is_on)
+
+    async def test_multi_light_turn_on(self):
+        for key, light in self.multiLight.items():
+            with self.subTest(key):
+                async with assert_device_properties_set(
+                    light._device, {self.multiLightDps[key]: self.multiLightOn[key]}
+                ):
+                    await light.async_turn_on()
+
+    async def test_multi_light_turn_off(self):
+        for key, light in self.multiLight.items():
+            with self.subTest(key):
+                async with assert_device_properties_set(
+                    light._device,
+                    {self.multiLightDps[key]: self.multiLightOff[key]},
+                ):
+                    await light.async_turn_off()
+
+    async def test_multi_light_toggle_turns_on_when_it_was_off(self):
+        for key, light in self.multiLight.items():
+            with self.subTest(key):
+                self.dps[self.multiLightDps[key]] = self.multiLightOff[key]
+                async with assert_device_properties_set(
+                    light._device,
+                    {self.multiLightDps[key]: self.multiLightOn[key]},
+                ):
+                    await light.async_toggle()
+
+    async def test_multi_light_toggle_turns_off_when_it_was_on(self):
+        for key, light in self.multiLight.items():
+            with self.subTest(key):
+                self.dps[self.multiLightDps[key]] = self.multiLightOn[key]
+                async with assert_device_properties_set(
+                    light._device,
+                    {self.multiLightDps[key]: self.multiLightOff[key]},
+                ):
+                    await light.async_toggle()
+
+    def test_multi_light_state_attributes(self):
+        for light in self.multiLight.values():
+            self.assertEqual(light.extra_state_attributes, {})
+
+
 class DimmableLightTests:
     def setUpDimmableLight(self, dps, subject, offval=0, tests=[(100, 100)]):
         self.dimmableLight = subject