Fix support for blinds in zimi integration (#150729)

Co-authored-by: Josef Zweck <josef@zweck.dev>
This commit is contained in:
markhannon
2025-08-26 20:24:54 +10:00
committed by GitHub
parent 4ee9eada41
commit c9876e2a2b
3 changed files with 48 additions and 17 deletions

View File

@@ -28,9 +28,11 @@ async def async_setup_entry(
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):
@@ -81,9 +83,9 @@ class ZimiCover(ZimiEntity, CoverEntity):
async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Open the cover/door to a specified percentage."""
if position := kwargs.get("position"):
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
await self._device.open_to_percentage(position)
position = kwargs.get("position", 0)
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
await self._device.open_to_percentage(position)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""

View File

@@ -34,12 +34,13 @@ INPUT_PORT = 5003
def mock_api_device(
device_name: str | None = None,
entity_type: str | None = None,
entity_id: str | None = None,
) -> MagicMock:
"""Mock a Zimi ControlPointDevice which is used in the zcc API with defaults."""
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.name = ENTITY_INFO["name"]
mock_api_device.type = entity_type or ENTITY_INFO["type"]

View File

@@ -14,7 +14,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
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(
@@ -25,26 +25,54 @@ async def test_cover_entity(
) -> None:
"""Tests cover entity."""
device_name = "Cover Controller"
entity_key = "cover.cover_controller_test_entity_name"
blind_device_name = "Blind Controller"
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
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)
entity = entity_registry.entities[entity_key]
assert entity.unique_id == ENTITY_INFO["id"]
blind_entity = entity_registry.entities[blind_entity_key]
assert blind_entity.unique_id == blind_entity_id
assert (
entity.supported_features
blind_entity.supported_features
== CoverEntityFeature.OPEN
| CoverEntityFeature.CLOSE
| CoverEntityFeature.STOP
| 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
services = hass.services.async_services()
@@ -53,7 +81,7 @@ async def test_cover_entity(
await hass.services.async_call(
entity_type,
SERVICE_CLOSE_COVER,
{"entity_id": entity_key},
{"entity_id": door_entity_key},
blocking=True,
)
assert mock_api.doors[0].close_door.called
@@ -62,7 +90,7 @@ async def test_cover_entity(
await hass.services.async_call(
entity_type,
SERVICE_OPEN_COVER,
{"entity_id": entity_key},
{"entity_id": door_entity_key},
blocking=True,
)
assert mock_api.doors[0].open_door.called
@@ -71,7 +99,7 @@ async def test_cover_entity(
await hass.services.async_call(
entity_type,
SERVICE_SET_COVER_POSITION,
{"entity_id": entity_key, "position": 50},
{"entity_id": door_entity_key, "position": 50},
blocking=True,
)
assert mock_api.doors[0].open_to_percentage.called