mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Bump aioswitcher to 4.2.0 (#129118)
* bump aioswitcher to 4.2.0 * Update cover.py * switcher fix based on requested changes
This commit is contained in:
parent
6d48316436
commit
dbd4781de1
@ -66,7 +66,7 @@ class SwitcherCoverEntity(SwitcherEntity, CoverEntity):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: SwitcherDataUpdateCoordinator,
|
coordinator: SwitcherDataUpdateCoordinator,
|
||||||
cover_id: int | None = None,
|
cover_id: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
@ -85,10 +85,14 @@ class SwitcherCoverEntity(SwitcherEntity, CoverEntity):
|
|||||||
def _update_data(self) -> None:
|
def _update_data(self) -> None:
|
||||||
"""Update data from device."""
|
"""Update data from device."""
|
||||||
data = cast(SwitcherShutter, self.coordinator.data)
|
data = cast(SwitcherShutter, self.coordinator.data)
|
||||||
self._attr_current_cover_position = data.position
|
self._attr_current_cover_position = data.position[self._cover_id]
|
||||||
self._attr_is_closed = data.position == 0
|
self._attr_is_closed = data.position[self._cover_id] == 0
|
||||||
self._attr_is_closing = data.direction == ShutterDirection.SHUTTER_DOWN
|
self._attr_is_closing = (
|
||||||
self._attr_is_opening = data.direction == ShutterDirection.SHUTTER_UP
|
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:
|
async def _async_call_api(self, api: str, *args: Any) -> None:
|
||||||
"""Call Switcher API."""
|
"""Call Switcher API."""
|
||||||
|
@ -6,11 +6,7 @@ import logging
|
|||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from aioswitcher.api import SwitcherBaseResponse, SwitcherType2Api
|
from aioswitcher.api import SwitcherBaseResponse, SwitcherType2Api
|
||||||
from aioswitcher.device import (
|
from aioswitcher.device import DeviceCategory, DeviceState, SwitcherLight
|
||||||
DeviceCategory,
|
|
||||||
DeviceState,
|
|
||||||
SwitcherSingleShutterDualLight,
|
|
||||||
)
|
|
||||||
|
|
||||||
from homeassistant.components.light import ColorMode, LightEntity
|
from homeassistant.components.light import ColorMode, LightEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -87,8 +83,8 @@ class SwitcherLightEntity(SwitcherEntity, LightEntity):
|
|||||||
if self.control_result is not None:
|
if self.control_result is not None:
|
||||||
return self.control_result
|
return self.control_result
|
||||||
|
|
||||||
data = cast(SwitcherSingleShutterDualLight, self.coordinator.data)
|
data = cast(SwitcherLight, self.coordinator.data)
|
||||||
return bool(data.lights[self._light_id] == DeviceState.ON)
|
return bool(data.light[self._light_id] == DeviceState.ON)
|
||||||
|
|
||||||
async def _async_call_api(self, api: str, *args: Any) -> None:
|
async def _async_call_api(self, api: str, *args: Any) -> None:
|
||||||
"""Call Switcher API."""
|
"""Call Switcher API."""
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"loggers": ["aioswitcher"],
|
"loggers": ["aioswitcher"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["aioswitcher==4.0.3"],
|
"requirements": ["aioswitcher==4.2.0"],
|
||||||
"single_config_entry": true
|
"single_config_entry": true
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ aiosteamist==1.0.0
|
|||||||
aiostreammagic==2.8.1
|
aiostreammagic==2.8.1
|
||||||
|
|
||||||
# homeassistant.components.switcher_kis
|
# homeassistant.components.switcher_kis
|
||||||
aioswitcher==4.0.3
|
aioswitcher==4.2.0
|
||||||
|
|
||||||
# homeassistant.components.syncthing
|
# homeassistant.components.syncthing
|
||||||
aiosyncthing==0.5.1
|
aiosyncthing==0.5.1
|
||||||
|
@ -366,7 +366,7 @@ aiosteamist==1.0.0
|
|||||||
aiostreammagic==2.8.1
|
aiostreammagic==2.8.1
|
||||||
|
|
||||||
# homeassistant.components.switcher_kis
|
# homeassistant.components.switcher_kis
|
||||||
aioswitcher==4.0.3
|
aioswitcher==4.2.0
|
||||||
|
|
||||||
# homeassistant.components.syncthing
|
# homeassistant.components.syncthing
|
||||||
aiosyncthing==0.5.1
|
aiosyncthing==0.5.1
|
||||||
|
@ -60,11 +60,11 @@ DUMMY_TARGET_TEMPERATURE = 23
|
|||||||
DUMMY_FAN_LEVEL = ThermostatFanLevel.LOW
|
DUMMY_FAN_LEVEL = ThermostatFanLevel.LOW
|
||||||
DUMMY_SWING = ThermostatSwing.OFF
|
DUMMY_SWING = ThermostatSwing.OFF
|
||||||
DUMMY_REMOTE_ID = "ELEC7001"
|
DUMMY_REMOTE_ID = "ELEC7001"
|
||||||
DUMMY_POSITION = 54
|
DUMMY_POSITION = [54]
|
||||||
DUMMY_DIRECTION = ShutterDirection.SHUTTER_STOP
|
DUMMY_DIRECTION = [ShutterDirection.SHUTTER_STOP]
|
||||||
DUMMY_USERNAME = "email"
|
DUMMY_USERNAME = "email"
|
||||||
DUMMY_TOKEN = "zvVvd7JxtN7CgvkD1Psujw=="
|
DUMMY_TOKEN = "zvVvd7JxtN7CgvkD1Psujw=="
|
||||||
DUMMY_LIGHTS = [DeviceState.ON, DeviceState.ON]
|
DUMMY_LIGHT_2 = [DeviceState.ON, DeviceState.ON]
|
||||||
|
|
||||||
DUMMY_PLUG_DEVICE = SwitcherPowerPlug(
|
DUMMY_PLUG_DEVICE = SwitcherPowerPlug(
|
||||||
DeviceType.POWER_PLUG,
|
DeviceType.POWER_PLUG,
|
||||||
@ -118,7 +118,7 @@ DUMMY_SINGLE_SHUTTER_DUAL_LIGHT_DEVICE = SwitcherSingleShutterDualLight(
|
|||||||
DUMMY_TOKEN_NEEDED5,
|
DUMMY_TOKEN_NEEDED5,
|
||||||
DUMMY_POSITION,
|
DUMMY_POSITION,
|
||||||
DUMMY_DIRECTION,
|
DUMMY_DIRECTION,
|
||||||
DUMMY_LIGHTS,
|
DUMMY_LIGHT_2,
|
||||||
)
|
)
|
||||||
|
|
||||||
DUMMY_THERMOSTAT_DEVICE = SwitcherThermostat(
|
DUMMY_THERMOSTAT_DEVICE = SwitcherThermostat(
|
||||||
|
@ -47,7 +47,7 @@ async def test_cover(
|
|||||||
mock_api,
|
mock_api,
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
device,
|
device,
|
||||||
entity_id,
|
entity_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cover services."""
|
"""Test cover services."""
|
||||||
await init_integration(hass, USERNAME, TOKEN)
|
await init_integration(hass, USERNAME, TOKEN)
|
||||||
@ -68,7 +68,7 @@ async def test_cover(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
monkeypatch.setattr(device, "position", 77)
|
monkeypatch.setattr(device, "position", [77])
|
||||||
mock_bridge.mock_callbacks([device])
|
mock_bridge.mock_callbacks([device])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ async def test_cover(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_UP)
|
monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_UP])
|
||||||
mock_bridge.mock_callbacks([device])
|
mock_bridge.mock_callbacks([device])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ async def test_cover(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_DOWN)
|
monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_DOWN])
|
||||||
mock_bridge.mock_callbacks([device])
|
mock_bridge.mock_callbacks([device])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ async def test_cover(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
monkeypatch.setattr(device, "direction", ShutterDirection.SHUTTER_STOP)
|
monkeypatch.setattr(device, "direction", [ShutterDirection.SHUTTER_STOP])
|
||||||
mock_bridge.mock_callbacks([device])
|
mock_bridge.mock_callbacks([device])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ async def test_cover(
|
|||||||
assert state.state == CoverState.OPEN
|
assert state.state == CoverState.OPEN
|
||||||
|
|
||||||
# Test closed on position == 0
|
# Test closed on position == 0
|
||||||
monkeypatch.setattr(device, "position", 0)
|
monkeypatch.setattr(device, "position", [0])
|
||||||
mock_bridge.mock_callbacks([device])
|
mock_bridge.mock_callbacks([device])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ async def test_cover_control_fail(
|
|||||||
mock_bridge,
|
mock_bridge,
|
||||||
mock_api,
|
mock_api,
|
||||||
device,
|
device,
|
||||||
entity_id,
|
entity_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cover control fail."""
|
"""Test cover control fail."""
|
||||||
await init_integration(hass, USERNAME, TOKEN)
|
await init_integration(hass, USERNAME, TOKEN)
|
||||||
|
@ -30,7 +30,6 @@ ENTITY_ID = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_1"
|
|||||||
ENTITY_ID2 = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_2"
|
ENTITY_ID2 = f"{LIGHT_DOMAIN}.{slugify(DEVICE.name)}_light_2"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("entity_id", "light_id", "device_state"),
|
("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]),
|
(ENTITY_ID2, 1, [DeviceState.ON, DeviceState.OFF]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
|
||||||
async def test_light(
|
async def test_light(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_bridge,
|
mock_bridge,
|
||||||
@ -56,7 +56,7 @@ async def test_light(
|
|||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
# Test state change on --> off for light
|
# Test state change on --> off for light
|
||||||
monkeypatch.setattr(DEVICE, "lights", device_state)
|
monkeypatch.setattr(DEVICE, "light", device_state)
|
||||||
mock_bridge.mock_callbacks([DEVICE])
|
mock_bridge.mock_callbacks([DEVICE])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -90,6 +90,13 @@ async def test_light(
|
|||||||
assert state.state == STATE_OFF
|
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)
|
@pytest.mark.parametrize("mock_bridge", [[DEVICE]], indirect=True)
|
||||||
async def test_light_control_fail(
|
async def test_light_control_fail(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -97,17 +104,20 @@ async def test_light_control_fail(
|
|||||||
mock_api,
|
mock_api,
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
entity_id: str,
|
||||||
|
light_id: int,
|
||||||
|
device_state: list[DeviceState],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test light control fail."""
|
"""Test light control fail."""
|
||||||
await init_integration(hass, USERNAME, TOKEN)
|
await init_integration(hass, USERNAME, TOKEN)
|
||||||
assert mock_bridge
|
assert mock_bridge
|
||||||
|
|
||||||
# Test initial state - light off
|
# Test initial state - light off
|
||||||
monkeypatch.setattr(DEVICE, "lights", [DeviceState.OFF, DeviceState.ON])
|
monkeypatch.setattr(DEVICE, "light", device_state)
|
||||||
mock_bridge.mock_callbacks([DEVICE])
|
mock_bridge.mock_callbacks([DEVICE])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
# Test exception during turn on
|
# Test exception during turn on
|
||||||
@ -119,20 +129,20 @@ async def test_light_control_fail(
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: ENTITY_ID},
|
{ATTR_ENTITY_ID: entity_id},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert mock_api.call_count == 2
|
assert mock_api.call_count == 2
|
||||||
mock_control_device.assert_called_once_with(DeviceState.ON, 0)
|
mock_control_device.assert_called_once_with(DeviceState.ON, light_id)
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
# Make device available again
|
# Make device available again
|
||||||
mock_bridge.mock_callbacks([DEVICE])
|
mock_bridge.mock_callbacks([DEVICE])
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
# Test error response during turn on
|
# Test error response during turn on
|
||||||
@ -144,11 +154,11 @@ async def test_light_control_fail(
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: ENTITY_ID},
|
{ATTR_ENTITY_ID: entity_id},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert mock_api.call_count == 4
|
assert mock_api.call_count == 4
|
||||||
mock_control_device.assert_called_once_with(DeviceState.ON, 0)
|
mock_control_device.assert_called_once_with(DeviceState.ON, light_id)
|
||||||
state = hass.states.get(ENTITY_ID)
|
state = hass.states.get(entity_id)
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user