mirror of
https://github.com/home-assistant/core.git
synced 2025-09-07 22:01:34 +02:00
Fix support for blinds in zimi integration (#150729)
Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
@@ -28,9 +28,11 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
api = config_entry.runtime_data
|
api = config_entry.runtime_data
|
||||||
|
|
||||||
doors = [ZimiCover(device, api) for device in api.doors]
|
covers = [ZimiCover(device, api) for device in api.blinds]
|
||||||
|
|
||||||
async_add_entities(doors)
|
covers.extend(ZimiCover(device, api) for device in api.doors)
|
||||||
|
|
||||||
|
async_add_entities(covers)
|
||||||
|
|
||||||
|
|
||||||
class ZimiCover(ZimiEntity, CoverEntity):
|
class ZimiCover(ZimiEntity, CoverEntity):
|
||||||
@@ -81,9 +83,9 @@ class ZimiCover(ZimiEntity, CoverEntity):
|
|||||||
|
|
||||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover/door to a specified percentage."""
|
"""Open the cover/door to a specified percentage."""
|
||||||
if position := kwargs.get("position"):
|
position = kwargs.get("position", 0)
|
||||||
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
|
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
|
||||||
await self._device.open_to_percentage(position)
|
await self._device.open_to_percentage(position)
|
||||||
|
|
||||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
|
@@ -34,12 +34,13 @@ INPUT_PORT = 5003
|
|||||||
def mock_api_device(
|
def mock_api_device(
|
||||||
device_name: str | None = None,
|
device_name: str | None = None,
|
||||||
entity_type: str | None = None,
|
entity_type: str | None = None,
|
||||||
|
entity_id: str | None = None,
|
||||||
) -> MagicMock:
|
) -> MagicMock:
|
||||||
"""Mock a Zimi ControlPointDevice which is used in the zcc API with defaults."""
|
"""Mock a Zimi ControlPointDevice which is used in the zcc API with defaults."""
|
||||||
|
|
||||||
mock_api_device = create_autospec(ControlPointDevice)
|
mock_api_device = create_autospec(ControlPointDevice)
|
||||||
|
|
||||||
mock_api_device.identifier = ENTITY_INFO["id"]
|
mock_api_device.identifier = entity_id or ENTITY_INFO["id"]
|
||||||
mock_api_device.room = ENTITY_INFO["room"]
|
mock_api_device.room = ENTITY_INFO["room"]
|
||||||
mock_api_device.name = ENTITY_INFO["name"]
|
mock_api_device.name = ENTITY_INFO["name"]
|
||||||
mock_api_device.type = entity_type or ENTITY_INFO["type"]
|
mock_api_device.type = entity_type or ENTITY_INFO["type"]
|
||||||
|
@@ -14,7 +14,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .common import ENTITY_INFO, mock_api_device, setup_platform
|
from .common import mock_api_device, setup_platform
|
||||||
|
|
||||||
|
|
||||||
async def test_cover_entity(
|
async def test_cover_entity(
|
||||||
@@ -25,26 +25,54 @@ async def test_cover_entity(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Tests cover entity."""
|
"""Tests cover entity."""
|
||||||
|
|
||||||
device_name = "Cover Controller"
|
blind_device_name = "Blind Controller"
|
||||||
entity_key = "cover.cover_controller_test_entity_name"
|
blind_entity_key = "cover.blind_controller_test_entity_name"
|
||||||
|
blind_entity_id = "test-entity-id-blind"
|
||||||
|
door_device_name = "Cover Controller"
|
||||||
|
door_entity_key = "cover.cover_controller_test_entity_name"
|
||||||
|
door_entity_id = "test-entity-id-door"
|
||||||
entity_type = Platform.COVER
|
entity_type = Platform.COVER
|
||||||
|
|
||||||
mock_api.doors = [mock_api_device(device_name=device_name, entity_type=entity_type)]
|
mock_api.blinds = [
|
||||||
|
mock_api_device(
|
||||||
|
device_name=blind_device_name,
|
||||||
|
entity_type=entity_type,
|
||||||
|
entity_id=blind_entity_id,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
mock_api.doors = [
|
||||||
|
mock_api_device(
|
||||||
|
device_name=door_device_name,
|
||||||
|
entity_type=entity_type,
|
||||||
|
entity_id=door_entity_id,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
await setup_platform(hass, entity_type)
|
await setup_platform(hass, entity_type)
|
||||||
|
|
||||||
entity = entity_registry.entities[entity_key]
|
blind_entity = entity_registry.entities[blind_entity_key]
|
||||||
assert entity.unique_id == ENTITY_INFO["id"]
|
assert blind_entity.unique_id == blind_entity_id
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
entity.supported_features
|
blind_entity.supported_features
|
||||||
== CoverEntityFeature.OPEN
|
== CoverEntityFeature.OPEN
|
||||||
| CoverEntityFeature.CLOSE
|
| CoverEntityFeature.CLOSE
|
||||||
| CoverEntityFeature.STOP
|
| CoverEntityFeature.STOP
|
||||||
| CoverEntityFeature.SET_POSITION
|
| CoverEntityFeature.SET_POSITION
|
||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get(entity_key)
|
door_entity = entity_registry.entities[door_entity_key]
|
||||||
|
assert door_entity.unique_id == door_entity_id
|
||||||
|
|
||||||
|
assert (
|
||||||
|
door_entity.supported_features
|
||||||
|
== CoverEntityFeature.OPEN
|
||||||
|
| CoverEntityFeature.CLOSE
|
||||||
|
| CoverEntityFeature.STOP
|
||||||
|
| CoverEntityFeature.SET_POSITION
|
||||||
|
)
|
||||||
|
|
||||||
|
state = hass.states.get(door_entity_key)
|
||||||
assert state == snapshot
|
assert state == snapshot
|
||||||
|
|
||||||
services = hass.services.async_services()
|
services = hass.services.async_services()
|
||||||
@@ -53,7 +81,7 @@ async def test_cover_entity(
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
entity_type,
|
entity_type,
|
||||||
SERVICE_CLOSE_COVER,
|
SERVICE_CLOSE_COVER,
|
||||||
{"entity_id": entity_key},
|
{"entity_id": door_entity_key},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert mock_api.doors[0].close_door.called
|
assert mock_api.doors[0].close_door.called
|
||||||
@@ -62,7 +90,7 @@ async def test_cover_entity(
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
entity_type,
|
entity_type,
|
||||||
SERVICE_OPEN_COVER,
|
SERVICE_OPEN_COVER,
|
||||||
{"entity_id": entity_key},
|
{"entity_id": door_entity_key},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert mock_api.doors[0].open_door.called
|
assert mock_api.doors[0].open_door.called
|
||||||
@@ -71,7 +99,7 @@ async def test_cover_entity(
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
entity_type,
|
entity_type,
|
||||||
SERVICE_SET_COVER_POSITION,
|
SERVICE_SET_COVER_POSITION,
|
||||||
{"entity_id": entity_key, "position": 50},
|
{"entity_id": door_entity_key, "position": 50},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert mock_api.doors[0].open_to_percentage.called
|
assert mock_api.doors[0].open_to_percentage.called
|
||||||
|
Reference in New Issue
Block a user