Browse Source

Increase test coverage for existing components

Jason Rumney 5 years ago
parent
commit
70677a476e
3 changed files with 34 additions and 0 deletions
  1. 8 0
      tests/heater/test_climate.py
  2. 7 0
      tests/kogan_heater/test_climate.py
  3. 19 0
      tests/test_device.py

+ 8 - 0
tests/heater/test_climate.py

@@ -389,6 +389,14 @@ class TestGoldairHeater(IsolatedAsyncioTestCase):
             {ATTR_ERROR_CODE: "something", ATTR_ERROR: "Error something"},
         )
 
+    def test_no_error_state(self):
+        # Test that no error is OK
+        self.dps[PROPERTY_TO_DPS_ID[ATTR_ERROR]] = 0
+        self.assertEqual(
+            self.subject.device_state_attributes,
+            {ATTR_ERROR_CODE: 0, ATTR_ERROR: "OK"},
+        )
+
     async def test_update(self):
         result = AsyncMock()
         self.subject._device.async_refresh.return_value = result()

+ 7 - 0
tests/kogan_heater/test_climate.py

@@ -14,6 +14,7 @@ from homeassistant.const import ATTR_TEMPERATURE, STATE_UNAVAILABLE
 from custom_components.tuya_local.kogan_heater.climate import KoganHeater
 from custom_components.tuya_local.kogan_heater.const import (
     ATTR_TARGET_TEMPERATURE,
+    ATTR_TIMER,
     HVAC_MODE_TO_DPS_MODE,
     PRESET_HIGH,
     PRESET_LOW,
@@ -197,6 +198,12 @@ class TestKoganHeater(IsolatedAsyncioTestCase):
         ):
             await self.subject.async_set_preset_mode(PRESET_HIGH)
 
+    def test_device_state_attributes(self):
+        self.dps[PROPERTY_TO_DPS_ID[ATTR_TIMER]] = 1
+        self.assertEqual(
+            self.subject.device_state_attributes, {ATTR_TIMER: 1},
+        )
+
     async def test_update(self):
         result = AsyncMock()
         self.subject._device.async_refresh.return_value = result()

+ 19 - 0
tests/test_device.py

@@ -202,6 +202,25 @@ class TestDevice(IsolatedAsyncioTestCase):
             [call(3.1), call(3.3), call(3.1)]
         )
 
+    def test_api_protocol_version_is_stable_once_successful(self):
+        self.subject._api.set_version.assert_called_once_with(3.3)
+        self.subject._api.set_version.reset_mock()
+
+        self.subject._api.status.side_effect = [
+            {"dps": {"1": False}},
+            Exception("Error"),
+            Exception("Error"),
+            Exception("Error"),
+            Exception("Error"),
+            Exception("Error"),
+            Exception("Error"),
+        ]
+        self.subject.refresh()
+        self.subject.refresh()
+        self.subject.refresh()
+
+        self.subject._api.set_version.assert_has_calls([call(3.1), call(3.3)])
+
     def test_reset_cached_state_clears_cached_state_and_pending_updates(self):
         self.subject._cached_state = {"1": True, "updated_at": time()}
         self.subject._pending_updates = {"1": False}