Просмотр исходного кода

Add experimental support for Electriq 12WMINV heatpump

First full HVAC implementation with multiple hvac modes and swing modes,
both involving interaction between two DPS.
Jason Rumney 4 лет назад
Родитель
Сommit
21f1960062

+ 168 - 0
custom_components/tuya_local/devices/electriq_12wminv_heatpump.yaml

@@ -0,0 +1,168 @@
+name: ElectriQ 12WMINV Heatpump
+primary_entity:
+  entity: climate
+  dps:
+    - id: 1
+      name: power
+      type: boolean
+      mapping:
+        - dps_val: false
+          value: "off"
+          icon: "mdi:hvac-off"
+          icon_priority: 1
+      hidden: true
+    - id: 2
+      name: temperature
+      type: integer
+      range:
+        min: 16
+        max: 32
+    - id: 3
+      name: current_temperature
+      type: integer
+    - id: 4
+      name: hvac_mode
+      type: string
+      mapping:
+        - dps_val: cold
+          icon: "mdi:snowflake"
+          icon_priority: 2
+          constraint: power
+          conditions:
+            - dps_val: false
+              value: "off"
+              value_redirect: power
+            - dps_val: true
+              value: cool
+        - dps_val: wind
+          icon: "mdi:fan"
+          icon_priority: 2
+          constraint: power
+          conditions:
+            - dps_val: false
+              value_redirect: power
+            - dps_val: true
+              value: fan_only
+        - dps_val: wet
+          icon: "mdi:water"
+          icon_priority: 2
+          constraint: power
+          conditions:
+            - dps_val: false
+              value_redirect: power
+            - dps_val: true
+              value: dry
+        - dps_val: hot
+          icon: "mdi:fire"
+          icon_priority: 2
+          constraint: power
+          conditions:
+            - dps_val: false
+              value_redirect: power
+            - dps_val: true
+              value: heat
+        - dps_val: auto
+          icon: "mdi:hvac"
+          icon_priority: 2
+          constraint: power
+          conditions:
+            - dps_val: false
+              value_redirect: power
+            - dps_val: true
+              value: auto
+    - id: 5
+      name: fan_mode
+      type: integer
+      mapping:
+        - dps_val: 1
+          value: auto
+          constraint: hvac_mode
+          conditions:
+            - dps_val: wet
+              invalid: true
+        - dps_val: 2
+          value: Turbo
+          constraint: hvac_mode
+          conditions:
+            - dps_val: wet
+              invalid: true
+        - dps_val: 3
+          value: low
+          constraint: hvac_mode
+          conditions:
+            - dps_val: wet
+              invalid: true
+        - dps_val: 4
+          value: medium
+          constraint: hvac_mode
+          conditions:
+            - dps_val: wet
+              invalid: true
+        - dps_val: 5
+          value: high
+          constraint: hvac_mode
+          conditions:
+            - dps_val: wet
+              invalid: true
+    - id: 8
+      name: unknown_8
+      type: boolean
+    - id: 12
+      name: unknown_12
+      type: boolean
+    - id: 102
+      name: unknown_102
+      type: boolean
+    - id: 103
+      name: unknown_103
+      type: boolean
+    - id: 106
+      name: swing_mode
+      type: boolean
+      mapping:
+        - dps_val: false
+          constraint: horiz_swing
+          conditions:
+            - dps_val: false
+              value: "off"
+            - dps_val: true
+              value: horizontal
+        - dps_val: true
+          constraint: horiz_swing
+          conditions:
+            - dps_val: false
+              value: vertical
+            - dps_val: true
+              value: both
+    - id: 107
+      name: horiz_swing
+      type: boolean
+      hidden: true
+    - id: 108
+      name: unknown_108
+      type: integer
+    - id: 109
+      name: unknown_109
+      type: integer
+    - id: 110
+      name: unknown_110
+      type: integer
+secondary_entities:
+  - entity: switch
+    name: Sleep
+    icon: "mdi:power-sleep"
+    dps:
+      - id: 101
+        name: switch
+        type: boolean
+  - entity: light
+    name: Display
+    dps:
+      - id: 104
+        name: switch
+        type: boolean
+        mapping:
+          - dps_val: true
+            icon: "mdi:led-on"
+          - dps_val: false
+            icon: "mdi:led-off"

+ 19 - 0
tests/const.py

@@ -205,3 +205,22 @@ ELECTRIQ_DEHUMIDIFIER_PAYLOAD = {
 
 POOLEX_SILVERLINE_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "Heat", "13": 0}
 POOLEX_VERTIGO_HEATPUMP_PAYLOAD = {"1": True, "2": 30, "3": 28, "4": "heat", "9": 0}
+
+ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD = {
+    "1": True,
+    "2": 20,
+    "3": 18,
+    "4": "auto",
+    "5": "1",
+    "8": False,
+    "12": False,
+    "101": True,
+    "102": False,
+    "103": False,
+    "104": True,
+    "106": False,
+    "107": False,
+    "108": 0,
+    "109": 0,
+    "110": 0,
+}

+ 388 - 0
tests/devices/test_electriq_12wminv_heatpump.py

@@ -0,0 +1,388 @@
+from homeassistant.components.climate.const import (
+    HVAC_MODE_AUTO,
+    HVAC_MODE_COOL,
+    HVAC_MODE_DRY,
+    HVAC_MODE_FAN_ONLY,
+    HVAC_MODE_HEAT,
+    HVAC_MODE_OFF,
+    SUPPORT_FAN_MODE,
+    SUPPORT_SWING_MODE,
+    SUPPORT_TARGET_TEMPERATURE,
+)
+from homeassistant.const import STATE_UNAVAILABLE
+
+from ..const import ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+POWER_DPS = "1"
+TEMPERATURE_DPS = "2"
+CURRENTTEMP_DPS = "3"
+HVACMODE_DPS = "4"
+FAN_DPS = "5"
+UNKNOWN8_DPS = "8"
+UNKNOWN12_DPS = "12"
+SWITCH_DPS = "101"
+UNKNOWN102_DPS = "102"
+UNKNOWN103_DPS = "103"
+LIGHT_DPS = "104"
+VSWING_DPS = "106"
+HSWING_DPS = "107"
+UNKNOWN108_DPS = "108"
+UNKNOWN109_DPS = "109"
+UNKNOWN110_DPS = "110"
+
+
+class TestElectriq12WMINVHeatpump(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "electriq_12wminv_heatpump.yaml", ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD
+        )
+        self.subject = self.entities.get("climate")
+        self.light = self.entities.get("light")
+        self.switch = self.entities.get("switch")
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
+        )
+
+    def test_icon(self):
+        self.dps[POWER_DPS] = True
+        self.dps[HVACMODE_DPS] = "auto"
+        self.assertEqual(self.subject.icon, "mdi:hvac")
+        self.dps[HVACMODE_DPS] = "cold"
+        self.assertEqual(self.subject.icon, "mdi:snowflake")
+        self.dps[HVACMODE_DPS] = "hot"
+        self.assertEqual(self.subject.icon, "mdi:fire")
+        self.dps[HVACMODE_DPS] = "wet"
+        self.assertEqual(self.subject.icon, "mdi:water")
+        self.dps[HVACMODE_DPS] = "wind"
+        self.assertEqual(self.subject.icon, "mdi:fan")
+        self.dps[POWER_DPS] = False
+        self.assertEqual(self.subject.icon, "mdi:hvac-off")
+
+    def test_temperature_unit_returns_device_temperature_unit(self):
+        self.assertEqual(
+            self.subject.temperature_unit, self.subject._device.temperature_unit
+        )
+
+    def test_target_temperature(self):
+        self.dps[TEMPERATURE_DPS] = 25
+        self.assertEqual(self.subject.target_temperature, 25)
+
+    def test_target_temperature_step(self):
+        self.assertEqual(self.subject.target_temperature_step, 1)
+
+    def test_minimum_target_temperature(self):
+        self.assertEqual(self.subject.min_temp, 16)
+
+    def test_maximum_target_temperature(self):
+        self.assertEqual(self.subject.max_temp, 32)
+
+    async def test_legacy_set_temperature_with_temperature(self):
+        async with assert_device_properties_set(
+            self.subject._device, {TEMPERATURE_DPS: 24}
+        ):
+            await self.subject.async_set_temperature(temperature=24)
+
+    async def test_legacy_set_temperature_with_no_valid_properties(self):
+        await self.subject.async_set_temperature(something="else")
+        self.subject._device.async_set_property.assert_not_called
+
+    async def test_set_target_temperature_succeeds_within_valid_range(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {TEMPERATURE_DPS: 25},
+        ):
+            await self.subject.async_set_target_temperature(25)
+
+    async def test_set_target_temperature_rounds_value_to_closest_integer(self):
+        async with assert_device_properties_set(
+            self.subject._device, {TEMPERATURE_DPS: 23}
+        ):
+            await self.subject.async_set_target_temperature(22.6)
+
+    async def test_set_target_temperature_fails_outside_valid_range(self):
+        with self.assertRaisesRegex(
+            ValueError, "temperature \\(15\\) must be between 16 and 32"
+        ):
+            await self.subject.async_set_target_temperature(15)
+
+        with self.assertRaisesRegex(
+            ValueError, "temperature \\(33\\) must be between 16 and 32"
+        ):
+            await self.subject.async_set_target_temperature(33)
+
+    def test_current_temperature(self):
+        self.dps[CURRENTTEMP_DPS] = 25
+        self.assertEqual(self.subject.current_temperature, 25)
+
+    def test_hvac_mode(self):
+        self.dps[POWER_DPS] = True
+        self.dps[HVACMODE_DPS] = "hot"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
+
+        self.dps[HVACMODE_DPS] = "cold"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
+
+        self.dps[HVACMODE_DPS] = "wet"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
+
+        self.dps[HVACMODE_DPS] = "wind"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
+
+        self.dps[HVACMODE_DPS] = "auto"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
+
+        self.dps[HVACMODE_DPS] = None
+        self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
+
+        self.dps[HVACMODE_DPS] = "auto"
+        self.dps[POWER_DPS] = False
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
+
+    def test_hvac_modes(self):
+        self.assertCountEqual(
+            self.subject.hvac_modes,
+            [
+                HVAC_MODE_OFF,
+                HVAC_MODE_HEAT,
+                HVAC_MODE_AUTO,
+                HVAC_MODE_COOL,
+                HVAC_MODE_DRY,
+                HVAC_MODE_FAN_ONLY,
+            ],
+        )
+
+    async def test_turn_on(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "hot"}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
+
+    async def test_turn_off(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: False}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
+
+    def test_fan_mode(self):
+        self.dps[FAN_DPS] = 1
+        self.assertEqual(self.subject.fan_mode, "auto")
+        self.dps[FAN_DPS] = 2
+        self.assertEqual(self.subject.fan_mode, "Turbo")
+        self.dps[FAN_DPS] = 3
+        self.assertEqual(self.subject.fan_mode, "low")
+        self.dps[FAN_DPS] = 4
+        self.assertEqual(self.subject.fan_mode, "medium")
+        self.dps[FAN_DPS] = 5
+        self.assertEqual(self.subject.fan_mode, "high")
+
+    def test_fan_mode_invalid_in_dry_hvac_mode(self):
+        self.dps[HVACMODE_DPS] = "wet"
+        self.dps[FAN_DPS] = 1
+        self.assertIs(self.subject.fan_mode, None)
+
+    def test_fan_modes(self):
+        self.assertCountEqual(
+            self.subject.fan_modes,
+            [
+                "auto",
+                "Turbo",
+                "low",
+                "medium",
+                "high",
+            ],
+        )
+
+    async def test_set_fan_mode_to_auto(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: 1},
+        ):
+            await self.subject.async_set_fan_mode("auto")
+
+    async def test_set_fan_mode_to_turbo(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: 2},
+        ):
+            await self.subject.async_set_fan_mode("Turbo")
+
+    async def test_set_fan_mode_to_low(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: 3},
+        ):
+            await self.subject.async_set_fan_mode("low")
+
+    async def test_set_fan_mode_to_medium(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: 4},
+        ):
+            await self.subject.async_set_fan_mode("medium")
+
+    async def test_set_fan_mode_to_high(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: 5},
+        ):
+            await self.subject.async_set_fan_mode("high")
+
+    def test_swing_modes(self):
+        self.assertCountEqual(
+            self.subject.swing_modes,
+            ["off", "horizontal", "vertical", "both"],
+        )
+
+    def test_swing_mode(self):
+        self.dps[VSWING_DPS] = False
+        self.dps[HSWING_DPS] = False
+        self.assertEqual(self.subject.swing_mode, "off")
+
+        self.dps[VSWING_DPS] = True
+        self.assertEqual(self.subject.swing_mode, "vertical")
+
+        self.dps[HSWING_DPS] = True
+        self.assertEqual(self.subject.swing_mode, "both")
+
+        self.dps[VSWING_DPS] = False
+        self.assertEqual(self.subject.swing_mode, "horizontal")
+
+    async def test_set_swing_mode_to_both(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {HSWING_DPS: True, VSWING_DPS: True},
+        ):
+            await self.subject.async_set_swing_mode("both")
+
+    async def test_set_swing_mode_to_horizontal(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {HSWING_DPS: True, VSWING_DPS: False},
+        ):
+            await self.subject.async_set_swing_mode("horizontal")
+
+    async def test_set_swing_mode_to_off(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {HSWING_DPS: False, VSWING_DPS: False},
+        ):
+            await self.subject.async_set_swing_mode("off")
+
+    async def test_set_swing_mode_to_vertical(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {HSWING_DPS: False, VSWING_DPS: True},
+        ):
+            await self.subject.async_set_swing_mode("vertical")
+
+    def test_device_state_attribures(self):
+        self.dps[UNKNOWN8_DPS] = True
+        self.dps[UNKNOWN12_DPS] = False
+        self.dps[UNKNOWN102_DPS] = True
+        self.dps[UNKNOWN103_DPS] = False
+        self.dps[UNKNOWN108_DPS] = 108
+        self.dps[UNKNOWN109_DPS] = 109
+        self.dps[UNKNOWN110_DPS] = 110
+        self.assertCountEqual(
+            self.subject.device_state_attributes,
+            {
+                "unknown_8": True,
+                "unknown_12": False,
+                "unknown_102": True,
+                "unknown_103": False,
+                "unknown_108": 108,
+                "unknown_109": 109,
+                "unknown_110": 110,
+            },
+        )
+
+    def test_light_state_attributes(self):
+        self.assertEqual(self.light.device_state_attributes, {})
+
+    def test_light_is_on(self):
+        self.dps[LIGHT_DPS] = True
+        self.assertTrue(self.light.is_on)
+        self.dps[LIGHT_DPS] = False
+        self.assertFalse(self.light.is_on)
+
+    async def test_light_turn_on(self):
+        async with assert_device_properties_set(
+            self.light._device,
+            {LIGHT_DPS: True},
+        ):
+            await self.light.async_turn_on()
+
+    async def test_light_turn_off(self):
+        async with assert_device_properties_set(
+            self.light._device,
+            {LIGHT_DPS: False},
+        ):
+            await self.light.async_turn_off()
+
+    async def test_toggle_turns_the_light_on_when_it_was_off(self):
+        self.dps[LIGHT_DPS] = False
+
+        async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
+            await self.light.async_toggle()
+
+    async def test_toggle_turns_the_light_off_when_it_was_on(self):
+        self.dps[LIGHT_DPS] = True
+
+        async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
+            await self.light.async_toggle()
+
+    def test_light_icon(self):
+        self.dps[LIGHT_DPS] = True
+        self.assertEqual(self.light.icon, "mdi:led-on")
+
+        self.dps[LIGHT_DPS] = False
+        self.assertEqual(self.light.icon, "mdi:led-off")
+
+    def test_switch_state_attributes(self):
+        self.assertEqual(self.switch.device_state_attributes, {})
+
+    def test_switch_is_on(self):
+        self.dps[SWITCH_DPS] = True
+        self.assertTrue(self.switch.is_on)
+        self.dps[SWITCH_DPS] = False
+        self.assertFalse(self.switch.is_on)
+
+    async def test_switch_turn_on(self):
+        async with assert_device_properties_set(
+            self.switch._device,
+            {SWITCH_DPS: True},
+        ):
+            await self.switch.async_turn_on()
+
+    async def test_switch_turn_off(self):
+        async with assert_device_properties_set(
+            self.switch._device,
+            {SWITCH_DPS: False},
+        ):
+            await self.switch.async_turn_off()
+
+    async def test_toggle_turns_the_switch_on_when_it_was_off(self):
+        self.dps[SWITCH_DPS] = False
+
+        async with assert_device_properties_set(
+            self.switch._device, {SWITCH_DPS: True}
+        ):
+            await self.switch.async_toggle()
+
+    async def test_toggle_turns_the_switch_off_when_it_was_on(self):
+        self.dps[SWITCH_DPS] = True
+
+        async with assert_device_properties_set(
+            self.switch._device, {SWITCH_DPS: False}
+        ):
+            await self.switch.async_toggle()
+
+    def test_switch_icon(self):
+        self.assertEqual(self.switch.icon, "mdi:power-sleep")