From dbd4781de16fd317c5787be4ed1aeb9227edd432 Mon Sep 17 00:00:00 2001
From: YogevBokobza <yogevbokobza12@gmail.com>
Date: Fri, 25 Oct 2024 14:41:49 +0300
Subject: [PATCH] Bump aioswitcher to 4.2.0 (#129118)

* bump aioswitcher to 4.2.0

* Update cover.py

* switcher fix based on requested changes
---
 .../components/switcher_kis/cover.py          | 14 +++++---
 .../components/switcher_kis/light.py          | 10 ++----
 .../components/switcher_kis/manifest.json     |  2 +-
 requirements_all.txt                          |  2 +-
 requirements_test_all.txt                     |  2 +-
 tests/components/switcher_kis/consts.py       |  8 ++---
 tests/components/switcher_kis/test_cover.py   | 14 ++++----
 tests/components/switcher_kis/test_light.py   | 32 ++++++++++++-------
 8 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/homeassistant/components/switcher_kis/cover.py b/homeassistant/components/switcher_kis/cover.py
index d81611b1629..6f71a27c72a 100644
--- a/homeassistant/components/switcher_kis/cover.py
+++ b/homeassistant/components/switcher_kis/cover.py
@@ -66,7 +66,7 @@ class SwitcherCoverEntity(SwitcherEntity, CoverEntity):
     def __init__(
         self,
         coordinator: SwitcherDataUpdateCoordinator,
-        cover_id: int | None = None,
+        cover_id: int,
     ) -> None:
         """Initialize the entity."""
         super().__init__(coordinator)
@@ -85,10 +85,14 @@ class SwitcherCoverEntity(SwitcherEntity, CoverEntity):
     def _update_data(self) -> None:
         """Update data from device."""
         data = cast(SwitcherShutter, self.coordinator.data)
-        self._attr_current_cover_position = data.position
-        self._attr_is_closed = data.position == 0
-        self._attr_is_closing = data.direction == ShutterDirection.SHUTTER_DOWN
-        self._attr_is_opening = data.direction == ShutterDirection.SHUTTER_UP
+        self._attr_current_cover_position = data.position[self._cover_id]
+        self._attr_is_closed = data.position[self._cover_id] == 0
+        self._attr_is_closing = (
+            data.direction[self._cover_id] == ShutterDirection.SHUTTER_DOWN
+        )
+        self._attr_is_opening = (
+            data.direction[self._cover_id] == ShutterDirection.SHUTTER_UP
+        )
 
     async def _async_call_api(self, api: str, *args: Any) -> None:
         """Call Switcher API."""
diff --git a/homeassistant/components/switcher_kis/light.py b/homeassistant/components/switcher_kis/light.py
index d3e8d52bc00..f5125c616da 100644
--- a/homeassistant/components/switcher_kis/light.py
+++ b/homeassistant/components/switcher_kis/light.py
@@ -6,11 +6,7 @@ import logging
 from typing import Any, cast
 
 from aioswitcher.api import SwitcherBaseResponse, SwitcherType2Api
-from aioswitcher.device import (
-    DeviceCategory,
-    DeviceState,
-    SwitcherSingleShutterDualLight,
-)
+from aioswitcher.device import DeviceCategory, DeviceState, SwitcherLight
 
 from homeassistant.components.light import ColorMode, LightEntity
 from homeassistant.config_entries import ConfigEntry
@@ -87,8 +83,8 @@ class SwitcherLightEntity(SwitcherEntity, LightEntity):
         if self.control_result is not None:
             return self.control_result
 
-        data = cast(SwitcherSingleShutterDualLight, self.coordinator.data)
-        return bool(data.lights[self._light_id] == DeviceState.ON)
+        data = cast(SwitcherLight, self.coordinator.data)
+        return bool(data.light[self._light_id] == DeviceState.ON)
 
     async def _async_call_api(self, api: str, *args: Any) -> None:
         """Call Switcher API."""
diff --git a/homeassistant/components/switcher_kis/manifest.json b/homeassistant/components/switcher_kis/manifest.json
index 902316f374e..cd754b4b8ec 100644
--- a/homeassistant/components/switcher_kis/manifest.json
+++ b/homeassistant/components/switcher_kis/manifest.json
@@ -7,6 +7,6 @@
   "iot_class": "local_push",
   "loggers": ["aioswitcher"],
   "quality_scale": "platinum",
-  "requirements": ["aioswitcher==4.0.3"],
+  "requirements": ["aioswitcher==4.2.0"],
   "single_config_entry": true
 }
diff --git a/requirements_all.txt b/requirements_all.txt
index e8e4fc17103..3f2b205cc5e 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -384,7 +384,7 @@ aiosteamist==1.0.0
 aiostreammagic==2.8.1
 
 # homeassistant.components.switcher_kis
-aioswitcher==4.0.3
+aioswitcher==4.2.0
 
 # homeassistant.components.syncthing
 aiosyncthing==0.5.1
diff --git a/requirements_test_all.txt b/requirements_test_all.txt
index 496cf5345be..6a97ad1b00d 100644
--- a/requirements_test_all.txt
+++ b/requirements_test_all.txt
@@ -366,7 +366,7 @@ aiosteamist==1.0.0
 aiostreammagic==2.8.1
 
 # homeassistant.components.switcher_kis
-aioswitcher==4.0.3
+aioswitcher==4.2.0
 
 # homeassistant.components.syncthing
 aiosyncthing==0.5.1
diff --git a/tests/components/switcher_kis/consts.py b/tests/components/switcher_kis/consts.py
index 7b0b5c28f3f..fc2becbb4d5 100644
--- a/tests/components/switcher_kis/consts.py
+++ b/tests/components/switcher_kis/consts.py
@@ -60,11 +60,11 @@ DUMMY_TARGET_TEMPERATURE = 23
 DUMMY_FAN_LEVEL = ThermostatFanLevel.LOW
 DUMMY_SWING = ThermostatSwing.OFF
 DUMMY_REMOTE_ID = "ELEC7001"
-DUMMY_POSITION = 54
-DUMMY_DIRECTION = ShutterDirection.SHUTTER_STOP
+DUMMY_POSITION = [54]
+DUMMY_DIRECTION = [ShutterDirection.SHUTTER_STOP]
 DUMMY_USERNAME = "email"
 DUMMY_TOKEN = "zvVvd7JxtN7CgvkD1Psujw=="
-DUMMY_LIGHTS = [DeviceState.ON, DeviceState.ON]
+DUMMY_LIGHT_2 = [DeviceState.ON, DeviceState.ON]
 
 DUMMY_PLUG_DEVICE = SwitcherPowerPlug(
     DeviceType.POWER_PLUG,
@@ -118,7 +118,7 @@ DUMMY_SINGLE_SHUTTER_DUAL_LIGHT_DEVICE = SwitcherSingleShutterDualLight(
     DUMMY_TOKEN_NEEDED5,
     DUMMY_POSITION,
     DUMMY_DIRECTION,
-    DUMMY_LIGHTS,
+    DUMMY_LIGHT_2,
 )
 
 DUMMY_THERMOSTAT_DEVICE = SwitcherThermostat(
diff --git a/tests/components/switcher_kis/test_cover.py b/tests/components/switcher_kis/test_cover.py
index 5e0e6c53f5a..c4b613ed2c1 100644
--- a/tests/components/switcher_kis/test_cover.py
+++ b/tests/components/switcher_kis/test_cover.py
@@ -47,7 +47,7 @@ async def test_cover(
     mock_api,
     monkeypatch: pytest.MonkeyPatch,
     device,
-    entity_id,
+    entity_id: str,
 ) -> None:
     """Test cover services."""
     await init_integration(hass, USERNAME, TOKEN)
@@ -68,7 +68,7 @@ async def test_cover(
             blocking=True,
         )
 
-        monkeypatch.setattr(device, "position", 77)
+        monkeypatch.setattr(device, "position", [77])
         mock_bridge.mock_callbacks([device])
         await hass.async_block_till_done()
 
@@ -89,7 +89,7 @@ async def test_cover(
             blocking=True,
         )
 
-        monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_UP)
+        monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_UP])
         mock_bridge.mock_callbacks([device])
         await hass.async_block_till_done()
 
@@ -109,7 +109,7 @@ async def test_cover(
             blocking=True,
         )
 
-        monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_DOWN)
+        monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_DOWN])
         mock_bridge.mock_callbacks([device])
         await hass.async_block_till_done()
 
@@ -129,7 +129,7 @@ async def test_cover(
             blocking=True,
         )
 
-        monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_STOP)
+        monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_STOP])
         mock_bridge.mock_callbacks([device])
         await hass.async_block_till_done()
 
@@ -139,7 +139,7 @@ async def test_cover(
         assert state.state == CoverState.OPEN
 
     # Test closed on position == 0
-    monkeypatch.setattr(device, "position", 0)
+    monkeypatch.setattr(device, "position", [0])
     mock_bridge.mock_callbacks([device])
     await hass.async_block_till_done()
 
@@ -161,7 +161,7 @@ async def test_cover_control_fail(
     mock_bridge,
     mock_api,
     device,
-    entity_id,
+    entity_id: str,
 ) -> None:
     """Test cover control fail."""
     await init_integration(hass, USERNAME, TOKEN)
diff --git a/tests/components/switcher_kis/test_light.py b/tests/components/switcher_kis/test_light.py
index 0fb036967e7..8a37174cf58 100644
--- a/tests/components/switcher_kis/test_light.py
+++ b/tests/components/switcher_kis/test_light.py
@@ -30,7 +30,6 @@ ENTITY_ID = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_1"
 ENTITY_ID2 = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_2"
 
 
-@pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
 @pytest.mark.parametrize(
     ("entity_id", "light_id", "device_state"),
     [
@@ -38,6 +37,7 @@ ENTITY_ID2 = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_2"
         (ENTITY_ID2, 1, [DeviceState.ON, DeviceState.OFF]),
     ],
 )
+@pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
 async def test_light(
     hass: HomeAssistant,
     mock_bridge,
@@ -56,7 +56,7 @@ async def test_light(
     assert state.state == STATE_ON
 
     # Test state change on --> off for light
-    monkeypatch.setattr(DEVICE, "lights", device_state)
+    monkeypatch.setattr(DEVICE, "light", device_state)
     mock_bridge.mock_callbacks([DEVICE])
     await hass.async_block_till_done()
 
@@ -90,6 +90,13 @@ async def test_light(
         assert state.state == STATE_OFF
 
 
+@pytest.mark.parametrize(
+    ("entity_id", "light_id", "device_state"),
+    [
+        (ENTITY_ID, 0, [DeviceState.OFF, DeviceState.ON]),
+        (ENTITY_ID2, 1, [DeviceState.ON, DeviceState.OFF]),
+    ],
+)
 @pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
 async def test_light_control_fail(
     hass: HomeAssistant,
@@ -97,17 +104,20 @@ async def test_light_control_fail(
     mock_api,
     monkeypatch: pytest.MonkeyPatch,
     caplog: pytest.LogCaptureFixture,
+    entity_id: str,
+    light_id: int,
+    device_state: list[DeviceState],
 ) -> None:
     """Test light control fail."""
     await init_integration(hass, USERNAME, TOKEN)
     assert mock_bridge
 
     # Test initial state - light off
-    monkeypatch.setattr(DEVICE, "lights", [DeviceState.OFF, DeviceState.ON])
+    monkeypatch.setattr(DEVICE, "light", device_state)
     mock_bridge.mock_callbacks([DEVICE])
     await hass.async_block_till_done()
 
-    state = hass.states.get(ENTITY_ID)
+    state = hass.states.get(entity_id)
     assert state.state == STATE_OFF
 
     # Test exception during turn on
@@ -119,20 +129,20 @@ async def test_light_control_fail(
             await hass.services.async_call(
                 LIGHT_DOMAIN,
                 SERVICE_TURN_ON,
-                {ATTR_ENTITY_ID: ENTITY_ID},
+                {ATTR_ENTITY_ID: entity_id},
                 blocking=True,
             )
 
         assert mock_api.call_count == 2
-        mock_control_device.assert_called_once_with(DeviceState.ON, 0)
-        state = hass.states.get(ENTITY_ID)
+        mock_control_device.assert_called_once_with(DeviceState.ON, light_id)
+        state = hass.states.get(entity_id)
         assert state.state == STATE_UNAVAILABLE
 
     # Make device available again
     mock_bridge.mock_callbacks([DEVICE])
     await hass.async_block_till_done()
 
-    state = hass.states.get(ENTITY_ID)
+    state = hass.states.get(entity_id)
     assert state.state == STATE_OFF
 
     # Test error response during turn on
@@ -144,11 +154,11 @@ async def test_light_control_fail(
             await hass.services.async_call(
                 LIGHT_DOMAIN,
                 SERVICE_TURN_ON,
-                {ATTR_ENTITY_ID: ENTITY_ID},
+                {ATTR_ENTITY_ID: entity_id},
                 blocking=True,
             )
 
         assert mock_api.call_count == 4
-        mock_control_device.assert_called_once_with(DeviceState.ON, 0)
-        state = hass.states.get(ENTITY_ID)
+        mock_control_device.assert_called_once_with(DeviceState.ON, light_id)
+        state = hass.states.get(entity_id)
         assert state.state == STATE_UNAVAILABLE
-- 
GitLab