mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add cover entity to Zimi integration (#144330)
This commit is contained in:
parent
0cf503d871
commit
880f5faeec
@ -16,7 +16,13 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from .const import DOMAIN
|
||||
from .helpers import async_connect_to_controller
|
||||
|
||||
PLATFORMS = [Platform.FAN, Platform.LIGHT, Platform.SENSOR, Platform.SWITCH]
|
||||
PLATFORMS = [
|
||||
Platform.COVER,
|
||||
Platform.FAN,
|
||||
Platform.LIGHT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
93
homeassistant/components/zimi/cover.py
Normal file
93
homeassistant/components/zimi/cover.py
Normal file
@ -0,0 +1,93 @@
|
||||
"""Platform for cover integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
CoverDeviceClass,
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import ZimiConfigEntry
|
||||
from .entity import ZimiEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ZimiConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Zimi Cover platform."""
|
||||
|
||||
api = config_entry.runtime_data
|
||||
|
||||
doors = [ZimiCover(device, api) for device in api.doors]
|
||||
|
||||
async_add_entities(doors)
|
||||
|
||||
|
||||
class ZimiCover(ZimiEntity, CoverEntity):
|
||||
"""Representation of a Zimi cover."""
|
||||
|
||||
_attr_device_class = CoverDeviceClass.GARAGE
|
||||
_attr_supported_features = (
|
||||
CoverEntityFeature.OPEN
|
||||
| CoverEntityFeature.CLOSE
|
||||
| CoverEntityFeature.SET_POSITION
|
||||
| CoverEntityFeature.STOP
|
||||
)
|
||||
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Close the cover/door."""
|
||||
_LOGGER.debug("Sending close_cover() for %s", self.name)
|
||||
await self._device.close_door()
|
||||
|
||||
@property
|
||||
def current_cover_position(self) -> int | None:
|
||||
"""Return the current cover/door position."""
|
||||
return self._device.percentage
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool | None:
|
||||
"""Return true if cover is closed."""
|
||||
return self._device.is_closed
|
||||
|
||||
@property
|
||||
def is_closing(self) -> bool | None:
|
||||
"""Return true if cover is closing."""
|
||||
return self._device.is_closing
|
||||
|
||||
@property
|
||||
def is_opening(self) -> bool | None:
|
||||
"""Return true if cover is opening."""
|
||||
return self._device.is_opening
|
||||
|
||||
@property
|
||||
def is_open(self) -> bool | None:
|
||||
"""Return true if cover is open."""
|
||||
return self._device.is_open
|
||||
|
||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||
"""Open the cover/door."""
|
||||
_LOGGER.debug("Sending open_cover() for %s", self.name)
|
||||
await self._device.open_door()
|
||||
|
||||
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)
|
||||
|
||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||
"""Stop the cover."""
|
||||
_LOGGER.debug(
|
||||
"Stopping open_cover() by setting to current position for %s", self.name
|
||||
)
|
||||
await self.async_set_cover_position(position=self.current_cover_position)
|
Loading…
x
Reference in New Issue
Block a user