Add typing to deCONZ Climate and Cover platforms (#59610)
This commit is contained in:
parent
edbe54c346
commit
29e0ef604e
3 changed files with 69 additions and 35 deletions
|
@ -1,5 +1,10 @@
|
|||
"""Support for deCONZ covers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import ValuesView
|
||||
from typing import Any
|
||||
|
||||
from pydeconz.light import Cover
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
|
@ -18,11 +23,13 @@ from homeassistant.components.cover import (
|
|||
SUPPORT_STOP_TILT,
|
||||
CoverEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .deconz_device import DeconzDevice
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
from .gateway import DeconzGateway, get_gateway_from_config_entry
|
||||
|
||||
DEVICE_CLASS = {
|
||||
"Level controllable output": DEVICE_CLASS_DAMPER,
|
||||
|
@ -31,13 +38,19 @@ DEVICE_CLASS = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up covers for deCONZ component."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
gateway.entities[DOMAIN] = set()
|
||||
|
||||
@callback
|
||||
def async_add_cover(lights=gateway.api.lights.values()):
|
||||
def async_add_cover(
|
||||
lights: list[Cover] | ValuesView[Cover] = gateway.api.lights.values(),
|
||||
) -> None:
|
||||
"""Add cover from deCONZ."""
|
||||
entities = []
|
||||
|
||||
|
@ -66,8 +79,9 @@ class DeconzCover(DeconzDevice, CoverEntity):
|
|||
"""Representation of a deCONZ cover."""
|
||||
|
||||
TYPE = DOMAIN
|
||||
_device: Cover
|
||||
|
||||
def __init__(self, device, gateway):
|
||||
def __init__(self, device: Cover, gateway: DeconzGateway) -> None:
|
||||
"""Set up cover device."""
|
||||
super().__init__(device, gateway)
|
||||
|
||||
|
@ -85,52 +99,52 @@ class DeconzCover(DeconzDevice, CoverEntity):
|
|||
self._attr_device_class = DEVICE_CLASS.get(self._device.type)
|
||||
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
def current_cover_position(self) -> int:
|
||||
"""Return the current position of the cover."""
|
||||
return 100 - self._device.lift
|
||||
return 100 - self._device.lift # type: ignore[no-any-return]
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
def is_closed(self) -> bool:
|
||||
"""Return if the cover is closed."""
|
||||
return not self._device.is_open
|
||||
|
||||
async def async_set_cover_position(self, **kwargs):
|
||||
async def async_set_cover_position(self, **kwargs: int) -> None:
|
||||
"""Move the cover to a specific position."""
|
||||
position = 100 - kwargs[ATTR_POSITION]
|
||||
await self._device.set_position(lift=position)
|
||||
|
||||
async def async_open_cover(self, **kwargs):
|
||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||
"""Open cover."""
|
||||
await self._device.open()
|
||||
|
||||
async def async_close_cover(self, **kwargs):
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Close cover."""
|
||||
await self._device.close()
|
||||
|
||||
async def async_stop_cover(self, **kwargs):
|
||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||
"""Stop cover."""
|
||||
await self._device.stop()
|
||||
|
||||
@property
|
||||
def current_cover_tilt_position(self):
|
||||
def current_cover_tilt_position(self) -> int | None:
|
||||
"""Return the current tilt position of the cover."""
|
||||
if self._device.tilt is not None:
|
||||
return 100 - self._device.tilt
|
||||
return 100 - self._device.tilt # type: ignore[no-any-return]
|
||||
return None
|
||||
|
||||
async def async_set_cover_tilt_position(self, **kwargs):
|
||||
async def async_set_cover_tilt_position(self, **kwargs: int) -> None:
|
||||
"""Tilt the cover to a specific position."""
|
||||
position = 100 - kwargs[ATTR_TILT_POSITION]
|
||||
await self._device.set_position(tilt=position)
|
||||
|
||||
async def async_open_cover_tilt(self, **kwargs):
|
||||
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
|
||||
"""Open cover tilt."""
|
||||
await self._device.set_position(tilt=0)
|
||||
|
||||
async def async_close_cover_tilt(self, **kwargs):
|
||||
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
||||
"""Close cover tilt."""
|
||||
await self._device.set_position(tilt=100)
|
||||
|
||||
async def async_stop_cover_tilt(self, **kwargs):
|
||||
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
||||
"""Stop cover tilt."""
|
||||
await self._device.stop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue