Parcourir la source

climate: add tests for turn_on/turn_off.

Fix issues in those recently added methods.
Jason Rumney il y a 3 ans
Parent
commit
6d13fd7912

+ 4 - 4
custom_components/tuya_local/generic/climate.py

@@ -291,18 +291,18 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
         # Bypass the usual dps mapping to switch the power dp directly
         # this way the hvac_mode will be kept when toggling off and on.
         if self._hvac_mode_dps and self._hvac_mode_dps.type is bool:
-            await self.device.async_set_property(self._hvac_mode_dps, True)
+            await self._device.async_set_property(self._hvac_mode_dps.id, True)
         else:
-            await super.async_turn_on()
+            await super().async_turn_on()
 
     async def async_turn_off(self):
         """Turn off the climate device."""
         # Bypass the usual dps mapping to switch the power dp directly
         # this way the hvac_mode will be kept when toggling off and on.
         if self._hvac_mode_dps and self._hvac_mode_dps.type is bool:
-            await self.device.async_set_property(self._hvac_mode_dps, False)
+            await self._device.async_set_property(self._hvac_mode_dps.id, False)
         else:
-            await super.async_turn_off()
+            await super().async_turn_off()
 
     @property
     def is_aux_heat(self):

+ 14 - 2
tests/devices/test_eberg_qubo_q40hd_heatpump.py

@@ -121,18 +121,30 @@ class TestEbergQuboQ40HDHeatpump(
             ],
         )
 
-    async def test_turn_on(self):
+    async def test_set_hvac_cool(self):
         async with assert_device_properties_set(
             self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
         ):
             await self.subject.async_set_hvac_mode(HVACMode.COOL)
 
-    async def test_turn_off(self):
+    async def test_set_hvac_off(self):
         async with assert_device_properties_set(
             self.subject._device, {POWER_DPS: False}
         ):
             await self.subject.async_set_hvac_mode(HVACMode.OFF)
 
+    async def test_turn_on(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: True}
+        ):
+            await self.subject.async_turn_on()
+
+    async def test_turn_off(self):
+        async with assert_device_properties_set(
+            self.subject._device, {POWER_DPS: False}
+        ):
+            await self.subject.async_turn_off()
+
     def test_fan_mode(self):
         self.dps[FAN_DPS] = "low"
         self.assertEqual(self.subject.fan_mode, "low")

+ 12 - 0
tests/devices/test_owon_pct513_thermostat.py

@@ -138,6 +138,18 @@ class TestOwonPCT513Thermostat(
         ):
             await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
 
+    async def test_turn_off(self):
+        async with assert_device_properties_set(
+            self.subject._device, {HVACMODE_DPS: "off"}
+        ):
+            await self.subject.async_turn_off()
+
+    async def test_turn_on(self):
+        async with assert_device_properties_set(
+            self.subject._device, {HVACMODE_DPS: "auto"}
+        ):
+            await self.subject.async_turn_on()
+
     def test_hvac_action(self):
         self.dps[HVACACTION_DPS] = "coolfanon"
         self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)