hass-core/homeassistant/components/insteon/cover.py
Tom Harris dbd821a564
Change Insteon backend module to pyinsteon from insteonplm (#35198)
* Migrate to pyinsteon from insteonplm

* Rename devices entities

* Print ALDB even if not loaded

* Add relay to name map

* Change insteonplm to pyinsteon

* Update requirements_all correctly

* Code review updates

* async_set_speed receive std speed value

* default speed to std medium value

* Call async methods for fan on/off

* Comment await required in loop

* Remove emtpy and add codeowner

* Make services async and remove async_add_job call

* Remove extra logging

* New device as async task and aldb load in loop

* Place lock in context bloxk

* Limiting lock to min

* Remove .env file
2020-05-17 15:27:38 +02:00

63 lines
1.8 KiB
Python

"""Support for Insteon covers via PowerLinc Modem."""
import logging
import math
from homeassistant.components.cover import (
ATTR_POSITION,
DOMAIN,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
CoverEntity,
)
from .insteon_entity import InsteonEntity
from .utils import async_add_insteon_entities
_LOGGER = logging.getLogger(__name__)
SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Insteon platform."""
async_add_insteon_entities(
hass, DOMAIN, InsteonCoverEntity, async_add_entities, discovery_info
)
class InsteonCoverEntity(InsteonEntity, CoverEntity):
"""A Class for an Insteon cover entity."""
@property
def current_cover_position(self):
"""Return the current cover position."""
return int(math.ceil(self._insteon_device_group.value * 100 / 255))
@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 cover."""
await self._insteon_device.async_open()
async def async_close_cover(self, **kwargs):
"""Close cover."""
await self._insteon_device.async_close()
async def async_set_cover_position(self, **kwargs):
"""Set the cover position."""
position = int(kwargs[ATTR_POSITION] * 255 / 100)
if position == 0:
await self._insteon_device.async_close()
else:
await self._insteon_device.async_open(
position=position, group=self._insteon_device_group.group
)