|
|
@@ -1,96 +0,0 @@
|
|
|
-from unittest import IsolatedAsyncioTestCase
|
|
|
-from unittest.mock import AsyncMock, patch
|
|
|
-
|
|
|
-from custom_components.tuya_local.purline_m100_heater.const import (
|
|
|
- ATTR_DISPLAY_OFF,
|
|
|
- ATTR_HVAC_MODE,
|
|
|
- PROPERTY_TO_DPS_ID,
|
|
|
-)
|
|
|
-from custom_components.tuya_local.purline_m100_heater.light import (
|
|
|
- PurlineM100HeaterLedDisplayLight,
|
|
|
-)
|
|
|
-
|
|
|
-from ..const import PURLINE_M100_HEATER_PAYLOAD
|
|
|
-from ..helpers import assert_device_properties_set
|
|
|
-
|
|
|
-
|
|
|
-class TestPurlineM100HeaterLedDisplayLight(IsolatedAsyncioTestCase):
|
|
|
- def setUp(self):
|
|
|
- device_patcher = patch("custom_components.tuya_local.device.TuyaLocalDevice")
|
|
|
- self.addCleanup(device_patcher.stop)
|
|
|
- self.mock_device = device_patcher.start()
|
|
|
-
|
|
|
- self.subject = PurlineM100HeaterLedDisplayLight(self.mock_device())
|
|
|
-
|
|
|
- self.dps = PURLINE_M100_HEATER_PAYLOAD.copy()
|
|
|
- self.subject._device.get_property.side_effect = lambda id: self.dps[id]
|
|
|
-
|
|
|
- def test_should_poll(self):
|
|
|
- self.assertTrue(self.subject.should_poll)
|
|
|
-
|
|
|
- def test_name_returns_device_name(self):
|
|
|
- self.assertEqual(self.subject.name, self.subject._device.name)
|
|
|
-
|
|
|
- def test_unique_id_returns_device_unique_id(self):
|
|
|
- self.assertEqual(self.subject.unique_id, self.subject._device.unique_id)
|
|
|
-
|
|
|
- def test_device_info_returns_device_info_from_device(self):
|
|
|
- self.assertEqual(self.subject.device_info, self.subject._device.device_info)
|
|
|
-
|
|
|
- def test_icon(self):
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = False
|
|
|
- self.assertEqual(self.subject.icon, "mdi:led-on")
|
|
|
-
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = True
|
|
|
- self.assertEqual(self.subject.icon, "mdi:led-off")
|
|
|
-
|
|
|
- def test_is_on(self):
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = False
|
|
|
- self.assertEqual(self.subject.is_on, True)
|
|
|
-
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = True
|
|
|
- self.assertEqual(self.subject.is_on, False)
|
|
|
-
|
|
|
- async def test_turn_on(self):
|
|
|
- async with assert_device_properties_set(
|
|
|
- self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]: False}
|
|
|
- ):
|
|
|
- await self.subject.async_turn_on()
|
|
|
-
|
|
|
- async def test_turn_off(self):
|
|
|
- async with assert_device_properties_set(
|
|
|
- self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]: True}
|
|
|
- ):
|
|
|
- await self.subject.async_turn_off()
|
|
|
-
|
|
|
- async def test_toggle_takes_no_action_when_heater_off(self):
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE]] = False
|
|
|
- await self.subject.async_toggle()
|
|
|
- self.subject._device.async_set_property.assert_not_called
|
|
|
-
|
|
|
- async def test_toggle_turns_the_light_on_when_it_was_off(self):
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE]] = True
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = True
|
|
|
-
|
|
|
- async with assert_device_properties_set(
|
|
|
- self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]: False}
|
|
|
- ):
|
|
|
- await self.subject.async_toggle()
|
|
|
-
|
|
|
- async def test_toggle_turns_the_light_off_when_it_was_on(self):
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE]] = True
|
|
|
- self.dps[PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]] = False
|
|
|
-
|
|
|
- async with assert_device_properties_set(
|
|
|
- self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]: True}
|
|
|
- ):
|
|
|
- await self.subject.async_toggle()
|
|
|
-
|
|
|
- async def test_update(self):
|
|
|
- result = AsyncMock()
|
|
|
- self.subject._device.async_refresh.return_value = result()
|
|
|
-
|
|
|
- await self.subject.async_update()
|
|
|
-
|
|
|
- self.subject._device.async_refresh.assert_called_once()
|
|
|
- result.assert_awaited()
|