2019-02-19 13:09:06 +00:00
|
|
|
"""Support for Insteon covers via PowerLinc Modem."""
|
2018-08-31 21:56:26 +00:00
|
|
|
import math
|
|
|
|
|
2019-02-19 13:09:06 +00:00
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
2020-08-11 23:04:44 +00:00
|
|
|
DOMAIN as COVER_DOMAIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_OPEN,
|
|
|
|
SUPPORT_SET_POSITION,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-01-03 14:13:18 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-08-11 23:04:44 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-03 14:13:18 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-08-11 23:04:44 +00:00
|
|
|
from .const import SIGNAL_ADD_ENTITIES
|
2020-01-30 09:47:44 +00:00
|
|
|
from .insteon_entity import InsteonEntity
|
2020-05-17 13:27:38 +00:00
|
|
|
from .utils import async_add_insteon_entities
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
|
|
|
|
|
|
|
|
2022-01-03 14:13:18 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-08-11 23:04:44 +00:00
|
|
|
"""Set up the Insteon covers from a config entry."""
|
|
|
|
|
2021-02-02 09:17:17 +00:00
|
|
|
@callback
|
|
|
|
def async_add_insteon_cover_entities(discovery_info=None):
|
2020-08-11 23:04:44 +00:00
|
|
|
"""Add the Insteon entities for the platform."""
|
|
|
|
async_add_insteon_entities(
|
|
|
|
hass, COVER_DOMAIN, InsteonCoverEntity, async_add_entities, discovery_info
|
|
|
|
)
|
|
|
|
|
|
|
|
signal = f"{SIGNAL_ADD_ENTITIES}_{COVER_DOMAIN}"
|
2021-02-02 09:17:17 +00:00
|
|
|
async_dispatcher_connect(hass, signal, async_add_insteon_cover_entities)
|
|
|
|
async_add_insteon_cover_entities()
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class InsteonCoverEntity(InsteonEntity, CoverEntity):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""A Class for an Insteon cover entity."""
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return the current cover position."""
|
2020-05-19 17:38:00 +00:00
|
|
|
if self._insteon_device_group.value is not None:
|
|
|
|
pos = self._insteon_device_group.value
|
|
|
|
else:
|
|
|
|
pos = 0
|
|
|
|
return int(math.ceil(pos * 100 / 255))
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return the supported features for this entity."""
|
|
|
|
return SUPPORTED_FEATURES
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return the boolean response if the node is on."""
|
|
|
|
return bool(self.current_cover_position)
|
|
|
|
|
|
|
|
async def async_open_cover(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Open cover."""
|
|
|
|
await self._insteon_device.async_open()
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs):
|
2020-05-17 13:27:38 +00:00
|
|
|
"""Close cover."""
|
|
|
|
await self._insteon_device.async_close()
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
async def async_set_cover_position(self, **kwargs):
|
|
|
|
"""Set the cover position."""
|
2019-07-31 19:25:30 +00:00
|
|
|
position = int(kwargs[ATTR_POSITION] * 255 / 100)
|
2018-08-31 21:56:26 +00:00
|
|
|
if position == 0:
|
2020-05-17 13:27:38 +00:00
|
|
|
await self._insteon_device.async_close()
|
2018-08-31 21:56:26 +00:00
|
|
|
else:
|
2020-05-17 13:27:38 +00:00
|
|
|
await self._insteon_device.async_open(
|
2020-05-19 17:38:00 +00:00
|
|
|
open_level=position, group=self._insteon_device_group.group
|
2020-05-17 13:27:38 +00:00
|
|
|
)
|