Skip to content

Commit c9876e2

Browse files
markhannonzweckj
andauthored
Fix support for blinds in zimi integration (home-assistant#150729)
Co-authored-by: Josef Zweck <[email protected]>
1 parent 4ee9ead commit c9876e2

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

homeassistant/components/zimi/cover.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ async def async_setup_entry(
2828

2929
api = config_entry.runtime_data
3030

31-
doors = [ZimiCover(device, api) for device in api.doors]
31+
covers = [ZimiCover(device, api) for device in api.blinds]
3232

33-
async_add_entities(doors)
33+
covers.extend(ZimiCover(device, api) for device in api.doors)
34+
35+
async_add_entities(covers)
3436

3537

3638
class ZimiCover(ZimiEntity, CoverEntity):
@@ -81,9 +83,9 @@ async def async_open_cover(self, **kwargs: Any) -> None:
8183

8284
async def async_set_cover_position(self, **kwargs: Any) -> None:
8385
"""Open the cover/door to a specified percentage."""
84-
if position := kwargs.get("position"):
85-
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
86-
await self._device.open_to_percentage(position)
86+
position = kwargs.get("position", 0)
87+
_LOGGER.debug("Sending set_cover_position(%d) for %s", position, self.name)
88+
await self._device.open_to_percentage(position)
8789

8890
async def async_stop_cover(self, **kwargs: Any) -> None:
8991
"""Stop the cover."""

tests/components/zimi/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
def mock_api_device(
3535
device_name: str | None = None,
3636
entity_type: str | None = None,
37+
entity_id: str | None = None,
3738
) -> MagicMock:
3839
"""Mock a Zimi ControlPointDevice which is used in the zcc API with defaults."""
3940

4041
mock_api_device = create_autospec(ControlPointDevice)
4142

42-
mock_api_device.identifier = ENTITY_INFO["id"]
43+
mock_api_device.identifier = entity_id or ENTITY_INFO["id"]
4344
mock_api_device.room = ENTITY_INFO["room"]
4445
mock_api_device.name = ENTITY_INFO["name"]
4546
mock_api_device.type = entity_type or ENTITY_INFO["type"]

tests/components/zimi/test_cover.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from homeassistant.core import HomeAssistant
1515
from homeassistant.helpers import entity_registry as er
1616

17-
from .common import ENTITY_INFO, mock_api_device, setup_platform
17+
from .common import mock_api_device, setup_platform
1818

1919

2020
async def test_cover_entity(
@@ -25,26 +25,54 @@ async def test_cover_entity(
2525
) -> None:
2626
"""Tests cover entity."""
2727

28-
device_name = "Cover Controller"
29-
entity_key = "cover.cover_controller_test_entity_name"
28+
blind_device_name = "Blind Controller"
29+
blind_entity_key = "cover.blind_controller_test_entity_name"
30+
blind_entity_id = "test-entity-id-blind"
31+
door_device_name = "Cover Controller"
32+
door_entity_key = "cover.cover_controller_test_entity_name"
33+
door_entity_id = "test-entity-id-door"
3034
entity_type = Platform.COVER
3135

32-
mock_api.doors = [mock_api_device(device_name=device_name, entity_type=entity_type)]
36+
mock_api.blinds = [
37+
mock_api_device(
38+
device_name=blind_device_name,
39+
entity_type=entity_type,
40+
entity_id=blind_entity_id,
41+
)
42+
]
43+
mock_api.doors = [
44+
mock_api_device(
45+
device_name=door_device_name,
46+
entity_type=entity_type,
47+
entity_id=door_entity_id,
48+
)
49+
]
3350

3451
await setup_platform(hass, entity_type)
3552

36-
entity = entity_registry.entities[entity_key]
37-
assert entity.unique_id == ENTITY_INFO["id"]
53+
blind_entity = entity_registry.entities[blind_entity_key]
54+
assert blind_entity.unique_id == blind_entity_id
3855

3956
assert (
40-
entity.supported_features
57+
blind_entity.supported_features
4158
== CoverEntityFeature.OPEN
4259
| CoverEntityFeature.CLOSE
4360
| CoverEntityFeature.STOP
4461
| CoverEntityFeature.SET_POSITION
4562
)
4663

47-
state = hass.states.get(entity_key)
64+
door_entity = entity_registry.entities[door_entity_key]
65+
assert door_entity.unique_id == door_entity_id
66+
67+
assert (
68+
door_entity.supported_features
69+
== CoverEntityFeature.OPEN
70+
| CoverEntityFeature.CLOSE
71+
| CoverEntityFeature.STOP
72+
| CoverEntityFeature.SET_POSITION
73+
)
74+
75+
state = hass.states.get(door_entity_key)
4876
assert state == snapshot
4977

5078
services = hass.services.async_services()
@@ -53,7 +81,7 @@ async def test_cover_entity(
5381
await hass.services.async_call(
5482
entity_type,
5583
SERVICE_CLOSE_COVER,
56-
{"entity_id": entity_key},
84+
{"entity_id": door_entity_key},
5785
blocking=True,
5886
)
5987
assert mock_api.doors[0].close_door.called
@@ -62,7 +90,7 @@ async def test_cover_entity(
6290
await hass.services.async_call(
6391
entity_type,
6492
SERVICE_OPEN_COVER,
65-
{"entity_id": entity_key},
93+
{"entity_id": door_entity_key},
6694
blocking=True,
6795
)
6896
assert mock_api.doors[0].open_door.called
@@ -71,7 +99,7 @@ async def test_cover_entity(
7199
await hass.services.async_call(
72100
entity_type,
73101
SERVICE_SET_COVER_POSITION,
74-
{"entity_id": entity_key, "position": 50},
102+
{"entity_id": door_entity_key, "position": 50},
75103
blocking=True,
76104
)
77105
assert mock_api.doors[0].open_to_percentage.called

0 commit comments

Comments
 (0)