2019-02-19 13:09:06 +00:00
|
|
|
"""Support for Insteon covers via PowerLinc Modem."""
|
2018-08-31 21:56:26 +00:00
|
|
|
import logging
|
|
|
|
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,
|
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_OPEN,
|
|
|
|
SUPPORT_SET_POSITION,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-01-30 09:47:44 +00:00
|
|
|
from .insteon_entity import InsteonEntity
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-08-31 21:56:26 +00:00
|
|
|
"""Set up the Insteon platform."""
|
|
|
|
if not discovery_info:
|
|
|
|
return
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
insteon_modem = hass.data["insteon"].get("modem")
|
2018-08-31 21:56:26 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
address = discovery_info["address"]
|
2018-08-31 21:56:26 +00:00
|
|
|
device = insteon_modem.devices[address]
|
2019-07-31 19:25:30 +00:00
|
|
|
state_key = discovery_info["state_key"]
|
2018-08-31 21:56:26 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug(
|
|
|
|
"Adding device %s entity %s to Cover platform",
|
|
|
|
device.address.hex,
|
|
|
|
device.states[state_key].name,
|
|
|
|
)
|
2018-08-31 21:56:26 +00:00
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
new_entity = InsteonCoverEntity(device, state_key)
|
2018-08-31 21:56:26 +00:00
|
|
|
|
|
|
|
async_add_entities([new_entity])
|
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class InsteonCoverEntity(InsteonEntity, CoverEntity):
|
2018-08-31 21:56:26 +00:00
|
|
|
"""A Class for an Insteon device."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return the current cover position."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return int(math.ceil(self._insteon_device_state.value * 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):
|
|
|
|
"""Open device."""
|
|
|
|
self._insteon_device_state.open()
|
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
|
|
"""Close device."""
|
|
|
|
self._insteon_device_state.close()
|
|
|
|
|
|
|
|
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:
|
|
|
|
self._insteon_device_state.close()
|
|
|
|
else:
|
|
|
|
self._insteon_device_state.set_position(position)
|