mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add HmIP-MOD_TM to HomematicIP Cloud (#30255)
This commit is contained in:
parent
c5a280c064
commit
658ec309aa
@ -2,7 +2,12 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from homematicip.aio.device import AsyncFullFlushBlind, AsyncFullFlushShutter
|
from homematicip.aio.device import (
|
||||||
|
AsyncFullFlushBlind,
|
||||||
|
AsyncFullFlushShutter,
|
||||||
|
AsyncGarageDoorModuleTormatic,
|
||||||
|
)
|
||||||
|
from homematicip.base.enums import DoorCommand, DoorState
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
@ -40,6 +45,8 @@ async def async_setup_entry(
|
|||||||
entities.append(HomematicipCoverSlats(hap, device))
|
entities.append(HomematicipCoverSlats(hap, device))
|
||||||
elif isinstance(device, AsyncFullFlushShutter):
|
elif isinstance(device, AsyncFullFlushShutter):
|
||||||
entities.append(HomematicipCoverShutter(hap, device))
|
entities.append(HomematicipCoverShutter(hap, device))
|
||||||
|
elif isinstance(device, AsyncGarageDoorModuleTormatic):
|
||||||
|
entities.append(HomematicipGarageDoorModuleTormatic(hap, device))
|
||||||
|
|
||||||
if entities:
|
if entities:
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@ -106,3 +113,35 @@ class HomematicipCoverSlats(HomematicipCoverShutter, CoverDevice):
|
|||||||
async def async_stop_cover_tilt(self, **kwargs) -> None:
|
async def async_stop_cover_tilt(self, **kwargs) -> None:
|
||||||
"""Stop the device if in motion."""
|
"""Stop the device if in motion."""
|
||||||
await self._device.set_shutter_stop()
|
await self._device.set_shutter_stop()
|
||||||
|
|
||||||
|
|
||||||
|
class HomematicipGarageDoorModuleTormatic(HomematicipGenericDevice, CoverDevice):
|
||||||
|
"""Representation of a HomematicIP Garage Door Module for Tormatic."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_cover_position(self) -> int:
|
||||||
|
"""Return current position of cover."""
|
||||||
|
door_state_to_position = {
|
||||||
|
DoorState.CLOSED: 0,
|
||||||
|
DoorState.OPEN: 100,
|
||||||
|
DoorState.VENTILATION_POSITION: 10,
|
||||||
|
DoorState.POSITION_UNKNOWN: None,
|
||||||
|
}
|
||||||
|
return door_state_to_position.get(self._device.doorState)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_closed(self) -> Optional[bool]:
|
||||||
|
"""Return if the cover is closed."""
|
||||||
|
return self._device.doorState == DoorState.CLOSED
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs) -> None:
|
||||||
|
"""Open the cover."""
|
||||||
|
await self._device.send_door_command(DoorCommand.OPEN)
|
||||||
|
|
||||||
|
async def async_close_cover(self, **kwargs) -> None:
|
||||||
|
"""Close the cover."""
|
||||||
|
await self._device.send_door_command(DoorCommand.CLOSE)
|
||||||
|
|
||||||
|
async def async_stop_cover(self, **kwargs) -> None:
|
||||||
|
"""Stop the cover."""
|
||||||
|
await self._device.send_door_command(DoorCommand.STOP)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Tests for HomematicIP Cloud cover."""
|
"""Tests for HomematicIP Cloud cover."""
|
||||||
|
from homematicip.base.enums import DoorCommand, DoorState
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_CURRENT_POSITION,
|
ATTR_CURRENT_POSITION,
|
||||||
ATTR_CURRENT_TILT_POSITION,
|
ATTR_CURRENT_TILT_POSITION,
|
||||||
@ -153,3 +155,47 @@ async def test_hmip_cover_slats(hass, default_mock_hap):
|
|||||||
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
|
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
|
||||||
ha_state = hass.states.get(entity_id)
|
ha_state = hass.states.get(entity_id)
|
||||||
assert ha_state.state == STATE_OPEN
|
assert ha_state.state == STATE_OPEN
|
||||||
|
|
||||||
|
|
||||||
|
async def test_hmip_garage_door_tormatic(hass, default_mock_hap):
|
||||||
|
"""Test HomematicipCoverShutte."""
|
||||||
|
entity_id = "cover.garage_door_module"
|
||||||
|
entity_name = "Garage Door Module"
|
||||||
|
device_model = "HmIP-MOD-TM"
|
||||||
|
|
||||||
|
ha_state, hmip_device = get_and_check_entity_basics(
|
||||||
|
hass, default_mock_hap, entity_id, entity_name, device_model
|
||||||
|
)
|
||||||
|
|
||||||
|
assert ha_state.state == "closed"
|
||||||
|
assert ha_state.attributes["current_position"] == 0
|
||||||
|
service_call_counter = len(hmip_device.mock_calls)
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
|
||||||
|
)
|
||||||
|
assert len(hmip_device.mock_calls) == service_call_counter + 1
|
||||||
|
assert hmip_device.mock_calls[-1][0] == "send_door_command"
|
||||||
|
assert hmip_device.mock_calls[-1][1] == (DoorCommand.OPEN,)
|
||||||
|
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.OPEN)
|
||||||
|
ha_state = hass.states.get(entity_id)
|
||||||
|
assert ha_state.state == STATE_OPEN
|
||||||
|
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
|
||||||
|
)
|
||||||
|
assert len(hmip_device.mock_calls) == service_call_counter + 3
|
||||||
|
assert hmip_device.mock_calls[-1][0] == "send_door_command"
|
||||||
|
assert hmip_device.mock_calls[-1][1] == (DoorCommand.CLOSE,)
|
||||||
|
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.CLOSED)
|
||||||
|
ha_state = hass.states.get(entity_id)
|
||||||
|
assert ha_state.state == STATE_CLOSED
|
||||||
|
assert ha_state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
|
||||||
|
)
|
||||||
|
assert len(hmip_device.mock_calls) == service_call_counter + 5
|
||||||
|
assert hmip_device.mock_calls[-1][0] == "send_door_command"
|
||||||
|
assert hmip_device.mock_calls[-1][1] == (DoorCommand.STOP,)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user