Bump aioswitcher to 4.2.0 (#129118)

* bump aioswitcher to 4.2.0

* Update cover.py

* switcher fix based on requested changes
pull/129152/head
YogevBokobza 2024-10-25 14:41:49 +03:00 committed by GitHub
parent 6d48316436
commit dbd4781de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 37 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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(

View File

@ -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)

View File

@ -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