* lib version * unit-test refactoring * added type hints * added cover * added test to see that consts have the same value as library consts * Update tests/components/dynalite/test_init.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed trigger template * Update homeassistant/components/dynalite/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/dynalite/const.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * removed CONF_TRIGGER from const corrected type hints - not clear why mypy didn't catch it * conversion of the config to library CONFs * moved to use the value since it should come from the library * taking CONF_HOST from homeassistant.const instead of module const * use dict.get removed leftover log * force device_class to be from homeassistant consts * move dict.get to inline * removed CONF from values changed "channelcover" to "channel_cover" * moved some CONF values out of const.py and taking them from homeassistant.const * verifying that device class is a valid HA device class * moved shutter to home assistant const Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
"""Support for the Dynalite channels as covers."""
|
|
from typing import Callable
|
|
|
|
from homeassistant.components.cover import DEVICE_CLASSES, CoverDevice
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant, callback
|
|
|
|
from .const import DEFAULT_COVER_CLASS
|
|
from .dynalitebase import DynaliteBase, async_setup_entry_base
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
|
|
) -> None:
|
|
"""Record the async_add_entities function to add them later when received from Dynalite."""
|
|
|
|
@callback
|
|
def cover_from_device(device, bridge):
|
|
if device.has_tilt:
|
|
return DynaliteCoverWithTilt(device, bridge)
|
|
return DynaliteCover(device, bridge)
|
|
|
|
async_setup_entry_base(
|
|
hass, config_entry, async_add_entities, "cover", cover_from_device
|
|
)
|
|
|
|
|
|
class DynaliteCover(DynaliteBase, CoverDevice):
|
|
"""Representation of a Dynalite Channel as a Home Assistant Cover."""
|
|
|
|
@property
|
|
def device_class(self) -> str:
|
|
"""Return the class of the device."""
|
|
dev_cls = self._device.device_class
|
|
if dev_cls in DEVICE_CLASSES:
|
|
return dev_cls
|
|
return DEFAULT_COVER_CLASS
|
|
|
|
@property
|
|
def current_cover_position(self) -> int:
|
|
"""Return the position of the cover from 0 to 100."""
|
|
return self._device.current_cover_position
|
|
|
|
@property
|
|
def is_opening(self) -> bool:
|
|
"""Return true if cover is opening."""
|
|
return self._device.is_opening
|
|
|
|
@property
|
|
def is_closing(self) -> bool:
|
|
"""Return true if cover is closing."""
|
|
return self._device.is_closing
|
|
|
|
@property
|
|
def is_closed(self) -> bool:
|
|
"""Return true if cover is closed."""
|
|
return self._device.is_closed
|
|
|
|
async def async_open_cover(self, **kwargs) -> None:
|
|
"""Open the cover."""
|
|
await self._device.async_open_cover(**kwargs)
|
|
|
|
async def async_close_cover(self, **kwargs) -> None:
|
|
"""Close the cover."""
|
|
await self._device.async_close_cover(**kwargs)
|
|
|
|
async def async_set_cover_position(self, **kwargs) -> None:
|
|
"""Set the cover position."""
|
|
await self._device.async_set_cover_position(**kwargs)
|
|
|
|
async def async_stop_cover(self, **kwargs) -> None:
|
|
"""Stop the cover."""
|
|
await self._device.async_stop_cover(**kwargs)
|
|
|
|
|
|
class DynaliteCoverWithTilt(DynaliteCover):
|
|
"""Representation of a Dynalite Channel as a Home Assistant Cover that uses up and down for tilt."""
|
|
|
|
@property
|
|
def current_cover_tilt_position(self) -> int:
|
|
"""Return the current tilt position."""
|
|
return self._device.current_cover_tilt_position
|
|
|
|
async def async_open_cover_tilt(self, **kwargs) -> None:
|
|
"""Open cover tilt."""
|
|
await self._device.async_open_cover_tilt(**kwargs)
|
|
|
|
async def async_close_cover_tilt(self, **kwargs) -> None:
|
|
"""Close cover tilt."""
|
|
await self._device.async_close_cover_tilt(**kwargs)
|
|
|
|
async def async_set_cover_tilt_position(self, **kwargs) -> None:
|
|
"""Set the cover tilt position."""
|
|
await self._device.async_set_cover_tilt_position(**kwargs)
|
|
|
|
async def async_stop_cover_tilt(self, **kwargs) -> None:
|
|
"""Stop the cover tilt."""
|
|
await self._device.async_stop_cover_tilt(**kwargs)
|