Explorar el Código

Smartplugs: Remove tests for removed legacy attributes

Last change also removed some obsolete attributes from smartplugs.
Tests need updating, and now we can finish the removal by removing the
deprecated property from the switch platform and remaining two devices
that defined it.

Also updated tests to use the config name smartplugv1 instead of
legacy "kogan_switch" which needs to be searched for in file contents,
so will be slowing the tests down.  Probably the legacy_type can be
removed after checking for others, as user configs were migrated
long ago so it was only used by the tests.
Jason Rumney hace 3 años
padre
commit
2d59403fda

+ 0 - 2
custom_components/tuya_local/devices/README.md

@@ -571,8 +571,6 @@ Humidifer can also cover dehumidifiers (use class to specify which).
 
 ### switch
 - **switch** (required, boolean): a dp to control the switch state.
-- **current_power_w** (optional, number): a dp that returns the current power consumption in watts.
-   This is a legacy attribute, for the HA Energy dashboard it is advisable to also provide a sensor entity linked to the same dp as well.
 
 ### vacuum
 - **status** (required, mapping of strings): a dp to report and control the status of the vacuum.

+ 0 - 6
custom_components/tuya_local/devices/digoo_dgsp202.yaml

@@ -7,12 +7,6 @@ primary_entity:
     - id: 1
       type: boolean
       name: switch
-    - id: 19
-      type: integer
-      name: current_power_w
-      readonly: true
-      mapping:
-        - scale: 10
 secondary_entities:
   - entity: switch
     name: Outlet 2

+ 0 - 5
custom_components/tuya_local/devices/moes_rgb_socket.yaml

@@ -6,11 +6,6 @@ primary_entity:
     - id: 101
       type: boolean
       name: switch
-    - id: 105
-      type: integer
-      name: current_power_w
-      mapping:
-        - scale: 10
 secondary_entities:
   - entity: light
     name: Night light

+ 0 - 10
custom_components/tuya_local/switch.py

@@ -31,7 +31,6 @@ class TuyaLocalSwitch(TuyaLocalEntity, SwitchEntity):
         """
         dps_map = self._init_begin(device, config)
         self._switch_dps = dps_map.pop("switch")
-        self._power_dps = dps_map.get("current_power_w", None)
         self._init_end(dps_map)
 
     @property
@@ -51,15 +50,6 @@ class TuyaLocalSwitch(TuyaLocalEntity, SwitchEntity):
             return self.available
         return self._switch_dps.get_value(self._device)
 
-    @property
-    def current_power_w(self):
-        """Return the current power consumption in Watts."""
-        if self._power_dps is None:
-            return None
-
-        pwr = self._power_dps.get_value(self._device)
-        return pwr
-
     async def async_turn_on(self, **kwargs):
         """Turn the switch on"""
         await self._switch_dps.async_set_value(self._device, True)

+ 0 - 19
tests/devices/test_smartplugv1.py

@@ -75,22 +75,3 @@ class TestKoganSwitch(
 
     def test_device_class_is_outlet(self):
         self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
-
-    def test_current_power_w(self):
-        self.dps[POWER_DPS] = 1234
-        self.assertEqual(self.subject.current_power_w, 123.4)
-
-    def test_extra_state_attributes_set(self):
-        self.dps[TIMER_DPS] = 1
-        self.dps[VOLTAGE_DPS] = 2350
-        self.dps[CURRENT_DPS] = 1234
-        self.dps[POWER_DPS] = 5678
-        self.assertDictEqual(
-            self.subject.extra_state_attributes,
-            {
-                "timer": 1,
-                "current_a": 1.234,
-                "voltage_v": 235.0,
-                "current_power_w": 567.8,
-            },
-        )

+ 0 - 19
tests/devices/test_smartplugv2.py

@@ -76,25 +76,6 @@ class TestSwitchV2(
     def test_device_class_is_outlet(self):
         self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
 
-    def test_current_power_w(self):
-        self.dps[POWER_DPS] = 1234
-        self.assertEqual(self.subject.current_power_w, 123.4)
-
-    def test_extra_state_attributes_set(self):
-        self.dps[TIMER_DPS] = 1
-        self.dps[VOLTAGE_DPS] = 2350
-        self.dps[CURRENT_DPS] = 1234
-        self.dps[POWER_DPS] = 5678
-        self.assertDictEqual(
-            self.subject.extra_state_attributes,
-            {
-                "timer": 1,
-                "current_a": 1.234,
-                "voltage_v": 235.0,
-                "current_power_w": 567.8,
-            },
-        )
-
     def test_sensor_precision(self):
         self.assertEqual(self.multiSensor["sensor_current"].native_precision, 0)
         self.assertEqual(self.multiSensor["sensor_power"].native_precision, 1)

+ 6 - 46
tests/mixins/switch.py

@@ -105,23 +105,8 @@ class BasicSwitchTests:
     def test_basic_switch_class_device_class(self):
         self.assertEqual(self.basicSwitch.device_class, self.basicSwitchDevClass)
 
-    def test_basic_switch_current_power_w(self):
-        if self.basicSwitchPowerDps is None:
-            self.assertIsNone(self.basicSwitch.current_power_w)
-        else:
-            self.dps[self.basicSwitchPowerDps] = 123
-            self.assertEqual(
-                self.basicSwitch.current_power_w, 123 / self.basicSwitchPowerScale
-            )
-
     def test_basic_switch_state_attributes(self):
-        if self.basicSwitchPowerDps is None:
-            self.assertEqual(self.basicSwitch.extra_state_attributes, {})
-        else:
-            self.dps[self.basicSwitchPowerDps] = 99 * self.basicSwitchPowerScale
-            self.assertDictEqual(
-                self.basicSwitch.extra_state_attributes, {"current_power_w": 99.0}
-            )
+        self.assertEqual(self.basicSwitch.extra_state_attributes, {})
 
 
 class MultiSwitchTests:
@@ -204,35 +189,10 @@ class MultiSwitchTests:
                 f"{key} device_class mismatch",
             )
 
-    def test_multi_switch_current_power_w(self):
-        for key, subject in self.multiSwitch.items():
-            dp = self.multiSwitchPowerDps.get(key)
-            if dp is None:
-                self.assertIsNone(
-                    subject.current_power_w,
-                    f"{key} current_power_w unexpectedly exists",
-                )
-            else:
-                self.dps[dp] = 1234
-                self.assertEqual(
-                    subject.current_power_w,
-                    1234 / self.multiSwitchPowerScale.get(key, 1),
-                    f"{key} current_power_w not as expected",
-                )
-
     def test_multi_switch_state_attributes(self):
         for key, subject in self.multiSwitch.items():
-            dp = self.multiSwitchPowerDps.get(key)
-            if dp is None:
-                self.assertEqual(
-                    subject.extra_state_attributes,
-                    {},
-                    f"{key} has unexpected extra_state_attributes",
-                )
-            else:
-                self.dps[dp] = 987 * self.multiSwitchPowerScale.get(key, 1)
-                self.assertDictEqual(
-                    subject.extra_state_attributes,
-                    {"current_power_w": 987.0},
-                    f"{key} extra_state_attributes mismatch",
-                )
+            self.assertEqual(
+                subject.extra_state_attributes,
+                {},
+                f"{key} has unexpected extra_state_attributes",
+            )

+ 1 - 1
tests/test_climate.py

@@ -72,7 +72,7 @@ async def test_init_entry_fails_if_device_has_no_climate(hass):
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "kogan_switch",
+            CONF_TYPE: "smartplugv1",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },

+ 3 - 3
tests/test_config_flow.py

@@ -387,14 +387,14 @@ async def test_flow_select_type_aborts_when_no_match(mock_device, hass):
 @patch.object(config_flow.ConfigFlowHandler, "device")
 async def test_flow_select_type_data_valid(mock_device, hass):
     """Test the flow continues when valid data is supplied."""
-    setup_device_mock(mock_device, type="kogan_switch")
+    setup_device_mock(mock_device, type="smartplugv1")
 
     flow = await hass.config_entries.flow.async_init(
         DOMAIN, context={"source": "select_type"}
     )
     result = await hass.config_entries.flow.async_configure(
         flow["flow_id"],
-        user_input={CONF_TYPE: "kogan_switch"},
+        user_input={CONF_TYPE: "smartplugv1"},
     )
     assert "form" == result["type"]
     assert "choose_entities" == result["step_id"]
@@ -404,7 +404,7 @@ async def test_flow_select_type_data_valid(mock_device, hass):
 async def test_flow_choose_entities_init(hass):
     """Test the initialisation of the form in the 3rd step of the config flow."""
 
-    with patch.dict(config_flow.ConfigFlowHandler.data, {CONF_TYPE: "kogan_switch"}):
+    with patch.dict(config_flow.ConfigFlowHandler.data, {CONF_TYPE: "smartplugv1"}):
         result = await hass.config_entries.flow.async_init(
             DOMAIN, context={"source": "choose_entities"}
         )

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
tests/test_device_config.py


+ 1 - 1
tests/test_light.py

@@ -44,7 +44,7 @@ async def test_init_entry_fails_if_device_has_no_light(hass):
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "kogan_switch",
+            CONF_TYPE: "smartplugv1",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },

+ 1 - 1
tests/test_lock.py

@@ -44,7 +44,7 @@ async def test_init_entry_fails_if_device_has_no_lock(hass):
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "kogan_switch",
+            CONF_TYPE: "smartplugv1",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },

+ 1 - 1
tests/test_switch.py

@@ -18,7 +18,7 @@ async def test_init_entry(hass):
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "kogan_switch",
+            CONF_TYPE: "smartplugv1",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },

+ 1 - 1
tests/test_water_heater.py

@@ -47,7 +47,7 @@ async def test_init_entry_fails_if_device_has_no_water_heater(hass):
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "kogan_switch",
+            CONF_TYPE: "smartplugv1",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio