Преглед изворни кода

Add tests for Eberg Cooly C35HD.

Issue #99
Jason Rumney пре 4 година
родитељ
комит
2b6f6c0449

+ 2 - 1
ACKNOWLEDGEMENTS.md

@@ -70,4 +70,5 @@ Further device support has been made with the assistance of users.  Please consi
  - [mpetcuRO](https://github.com/mpetcuRO) for assistance with Hysen HT08WE-2 thermometers.
  - [Paul-C-S](https://github.com/Paul-C-S) for assistance with Ecostrad Accent iQ heaters.
  - [WildeRNS](https://github.com/WildeRNS) for assistance with Nashone MTS-700-WB thermostat smartplugs.
-
+ - [ishioni](https://github.com/ishioni) for contributing support for Eberg Cooly C32HD air conditioner.
+ 

+ 23 - 5
custom_components/tuya_local/devices/eberg_cooly_c35hd.yaml

@@ -58,14 +58,14 @@ primary_entity:
     - id: 6
       name: temperature
       type: integer
+      range:
+        min: 13
+        max: 32
       mapping:
         - constraint: temperature_unit
           conditions:
-            - dps_val: false
-              range:
-                min: 13
-                max: 32
             - dps_val: true
+              value_redirect: temperature_f
               range:
                 min: 55
                 max: 90
@@ -108,10 +108,28 @@ primary_entity:
           value: "off"
     - id: 17
       type: boolean
-      name: unknown_15
+      name: unknown_17
     - id: 18
       type: integer
       name: temperature_f
+      hidden: true
+      range:
+        min: 55
+        max: 90
     - id: 19
       type: boolean
       name: unknown_19
+secondary_entities:
+  - entity: select
+    category: config
+    name: Temperature Unit
+    icon: "mdi:temperature-celsius"
+    dps:
+      - id: 10
+        type: boolean
+        name: option
+        mapping:
+          - dps_val: true
+            value: "Fahrenheit"
+          - dps_val: false
+            value: "Celsius"

+ 16 - 0
tests/const.py

@@ -665,6 +665,22 @@ EBERG_QUBO_Q40HD_PAYLOAD = {
     "101": "heat_s",
 }
 
+EBERG_COOLY_C35HD_PAYLOAD = {
+    "1": True,
+    "4": 0,
+    "5": "4",
+    "6": 25,
+    "8": "1",
+    "10": False,
+    "13": 0,
+    "14": 0,
+    "15": 0,
+    "16": False,
+    "17": False,
+    "18": 78,
+    "19": False,
+}
+
 STIRLING_FS1_FAN_PAYLOAD = {
     "1": True,
     "2": "normal",

+ 270 - 0
tests/devices/test_eberg_cooly_c35hd.py

@@ -0,0 +1,270 @@
+from homeassistant.components.climate.const import (
+    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,
+    SWING_OFF,
+    SWING_VERTICAL,
+)
+from homeassistant.const import (
+    STATE_UNAVAILABLE,
+    TEMP_CELSIUS,
+    TEMP_FAHRENHEIT,
+)
+
+from ..const import EBERG_COOLY_C35HD_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.climate import TargetTemperatureTests
+from ..mixins.select import BasicSelectTests
+from .base_device_tests import TuyaDeviceTestCase
+
+POWER_DPS = "1"
+UNKNOWN4_DPS = "4"
+HVACMODE_DPS = "5"
+TEMPERATURE_DPS = "6"
+FAN_DPS = "8"
+UNIT_DPS = "10"
+UNKNOWN13_DPS = "13"
+UNKNOWN14_DPS = "14"
+UNKNOWN15_DPS = "15"
+SWING_DPS = "16"
+UNKNOWN17_DPS = "17"
+TEMPF_DPS = "18"
+UNKNOWN19_DPS = "19"
+
+
+class TestEbergCoolyC35HDHeatpump(
+    BasicSelectTests, TargetTemperatureTests, TuyaDeviceTestCase
+):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "eberg_cooly_c35hd.yaml",
+            EBERG_COOLY_C35HD_PAYLOAD,
+        )
+        self.subject = self.entities.get("climate")
+        self.setUpTargetTemperature(
+            TEMPERATURE_DPS,
+            self.subject,
+            min=13,
+            max=32,
+        )
+        self.setUpBasicSelect(
+            UNIT_DPS,
+            self.entities.get("select_temperature_unit"),
+            {
+                True: "Fahrenheit",
+                False: "Celsius",
+            },
+        )
+        self.mark_secondary(["select_temperature_unit"])
+
+    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] = "1"
+        self.assertEqual(self.subject.icon, "mdi:fire")
+        self.dps[HVACMODE_DPS] = "2"
+        self.assertEqual(self.subject.icon, "mdi:water")
+        self.dps[HVACMODE_DPS] = "3"
+        self.assertEqual(self.subject.icon, "mdi:snowflake")
+        self.dps[HVACMODE_DPS] = "4"
+        self.assertEqual(self.subject.icon, "mdi:fan")
+        self.dps[POWER_DPS] = False
+        self.assertEqual(self.subject.icon, "mdi:hvac-off")
+
+    def test_temperature_unit(self):
+        self.dps[UNIT_DPS] = False
+        self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
+        self.dps[UNIT_DPS] = True
+        self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
+
+    def test_minimum_target_temperature_f(self):
+        self.dps[UNIT_DPS] = True
+        self.assertEqual(self.subject.min_temp, 55)
+
+    def test_maximum_target_temperature_f(self):
+        self.dps[UNIT_DPS] = True
+        self.assertEqual(self.subject.max_temp, 90)
+
+    def test_temperature_redirects_f(self):
+        self.dps[UNIT_DPS] = True
+        self.dps[TEMPERATURE_DPS] = 20
+        self.dps[TEMPF_DPS] = 90
+        self.assertEqual(self.subject.target_temperature, 90)
+
+    async def test_set_temperature_redirects_f(self):
+        self.dps[UNIT_DPS] = True
+        async with assert_device_properties_set(
+            self.subject._device,
+            {TEMPF_DPS: 85},
+        ):
+            await self.subject.async_set_target_temperature(85)
+
+    def test_hvac_mode(self):
+        self.dps[POWER_DPS] = True
+        self.dps[HVACMODE_DPS] = "1"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
+        self.dps[HVACMODE_DPS] = "2"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
+        self.dps[HVACMODE_DPS] = "3"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
+        self.dps[HVACMODE_DPS] = "4"
+        self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
+
+        self.dps[HVACMODE_DPS] = None
+        self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
+
+        self.dps[HVACMODE_DPS] = "3"
+        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_COOL,
+                HVAC_MODE_DRY,
+                HVAC_MODE_FAN_ONLY,
+                HVAC_MODE_HEAT,
+            ],
+        )
+
+    async def test_set_hvac_mode_to_heat(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "1"}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
+
+    async def test_set_hvac_mode_to_dry(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "2"}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_DRY)
+
+    async def test_set_hvac_mode_to_cool(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "3"}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
+
+    async def test_set_hvac_mode_to_fan(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "4"}
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
+
+    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, "low")
+        self.dps[FAN_DPS] = "2"
+        self.assertEqual(self.subject.fan_mode, "medium")
+        self.dps[FAN_DPS] = "3"
+        self.assertEqual(self.subject.fan_mode, "high")
+        self.dps[FAN_DPS] = "0"
+        self.assertEqual(self.subject.fan_mode, "auto")
+
+    def test_fan_modes(self):
+        self.assertCountEqual(
+            self.subject.fan_modes,
+            [
+                "auto",
+                "low",
+                "medium",
+                "high",
+            ],
+        )
+
+    async def test_set_fan_mode_to_low(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: "1"},
+        ):
+            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: "2"},
+        ):
+            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: "3"},
+        ):
+            await self.subject.async_set_fan_mode("high")
+
+    async def test_set_fan_mode_to_auto(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FAN_DPS: "0"},
+        ):
+            await self.subject.async_set_fan_mode("auto")
+
+    def test_swing_mode(self):
+        self.dps[SWING_DPS] = True
+        self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
+        self.dps[SWING_DPS] = False
+        self.assertEqual(self.subject.swing_mode, SWING_OFF)
+
+    def test_swing_modes(self):
+        self.assertCountEqual(
+            self.subject.swing_modes,
+            [
+                SWING_VERTICAL,
+                SWING_OFF,
+            ],
+        )
+
+    async def test_set_swing_mode_to_vertical(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {SWING_DPS: True},
+        ):
+            await self.subject.async_set_swing_mode(SWING_VERTICAL)
+
+    async def test_set_swing_mode_to_off(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {SWING_DPS: False},
+        ):
+            await self.subject.async_set_swing_mode(SWING_OFF)
+
+    def test_extra_state_attributes(self):
+        self.dps[UNKNOWN4_DPS] = 4
+        self.dps[UNKNOWN13_DPS] = 13
+        self.dps[UNKNOWN14_DPS] = 14
+        self.dps[UNKNOWN15_DPS] = 15
+        self.dps[UNKNOWN17_DPS] = True
+        self.dps[UNKNOWN19_DPS] = False
+
+        self.assertDictEqual(
+            self.subject.extra_state_attributes,
+            {
+                "unknown_4": 4,
+                "unknown_13": 13,
+                "unknown_14": 14,
+                "unknown_15": 15,
+                "unknown_17": True,
+                "unknown_19": False,
+            },
+        )