* First cut of Rollease Acmeda Pulse Hub integration. * Acmeda integration improvements: - Moved common code into a base entity - Battery level sensor added - Localisation now working * Added requirement for aiopulse now that it has been uploaded to PyPI. * Exclude acmeda integration from coverage check as it relies on a hub being present. * Fix Travis CI build issues. * Remove unused constants. * Remove unused group logic from cover.py * Removed commented code from base.py * Remove sensors (battery entities) on removal of hub. * Remove unused groups from sensor.py * Acmeda device and entity update made fully asynchronous using subscriptions to remove need for config polling. * Updated aiopulse version dependency. Removed non-functional battery charging indication. * Rationalised common code to update entities into helpers.py * Fix linting issue. * Correct additional CI pylint errors. * Index config_entries by entry_id. Move entity loading and unloading to __init__.py Add entry_id to dispatcher signal Removed now unused polling code hub Added config_flow unit tests * Tweak to integration config_entry title. * Bumped aiopulse module to 0.3.2. Reduced verbosity of aiopulse module. * Changed to using direct write of device state. Removed old style async_step_init config_flow step. * Remove superfluous battery_level and device_state_attributes from battery entity. * Removal of unused strings. Removal of unused create_config_flow helper. Removal of stale comment. * Remove use of shared container to track existing enities. Moved removal and deregistration of entities to base class through use of dispatch helper. * Fixed strings.json * Fix incorrect use of remove instead of pop on dict. * Add support for tilting covers, bump aiopulse version number. * Bump aiopulse version to v0.3.4. Fixed bug in cover supported_features. * Bumped aiopulse version to 0.4.0 Update acmeda .coveragerc exclusions * Removed already configured hub check from __init__.py async_setup_entry Removed passing in hass reference to base entity class Renamed entity async_reset to async_will_remove_from_hass Changed device_info and properties Migrated to CoveEntity from CoverDevice Added dispatched_connect cleanup on hub removal Removed unused entries from manifest Removed override of battery icon Renamed translations folder * Reversed unintended change to .coveragerc * Fixed config flow for multi-hub discovery. * Acmeda enhancements as requested by MartinHjelmare * Force import to connect to hub to retrieve id prior to creating entry * Remove YAML configuration support. * Tidied up config_flow and tests: - removed unnecessary steps - fixed typos * Removed storage of hub in config_flow.
122 lines
3.6 KiB
Python
122 lines
3.6 KiB
Python
"""Support for Acmeda Roller Blinds."""
|
|
from homeassistant.components.cover import (
|
|
ATTR_POSITION,
|
|
SUPPORT_CLOSE,
|
|
SUPPORT_CLOSE_TILT,
|
|
SUPPORT_OPEN,
|
|
SUPPORT_OPEN_TILT,
|
|
SUPPORT_SET_POSITION,
|
|
SUPPORT_SET_TILT_POSITION,
|
|
SUPPORT_STOP,
|
|
SUPPORT_STOP_TILT,
|
|
CoverEntity,
|
|
)
|
|
from homeassistant.core import callback
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
from .base import AcmedaBase
|
|
from .const import ACMEDA_HUB_UPDATE, DOMAIN
|
|
from .helpers import async_add_acmeda_entities
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
"""Set up the Acmeda Rollers from a config entry."""
|
|
hub = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
current = set()
|
|
|
|
@callback
|
|
def async_add_acmeda_covers():
|
|
async_add_acmeda_entities(
|
|
hass, AcmedaCover, config_entry, current, async_add_entities
|
|
)
|
|
|
|
hub.cleanup_callbacks.append(
|
|
async_dispatcher_connect(
|
|
hass,
|
|
ACMEDA_HUB_UPDATE.format(config_entry.entry_id),
|
|
async_add_acmeda_covers,
|
|
)
|
|
)
|
|
|
|
|
|
class AcmedaCover(AcmedaBase, CoverEntity):
|
|
"""Representation of a Acmeda cover device."""
|
|
|
|
@property
|
|
def current_cover_position(self):
|
|
"""Return the current position of the roller blind.
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
"""
|
|
position = None
|
|
if self.roller.type != 7:
|
|
position = 100 - self.roller.closed_percent
|
|
return position
|
|
|
|
@property
|
|
def current_cover_tilt_position(self):
|
|
"""Return the current tilt of the roller blind.
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
"""
|
|
position = None
|
|
if self.roller.type == 7 or self.roller.type == 10:
|
|
position = 100 - self.roller.closed_percent
|
|
return position
|
|
|
|
@property
|
|
def supported_features(self):
|
|
"""Flag supported features."""
|
|
supported_features = 0
|
|
if self.current_cover_position is not None:
|
|
supported_features |= (
|
|
SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
|
|
)
|
|
if self.current_cover_tilt_position is not None:
|
|
supported_features |= (
|
|
SUPPORT_OPEN_TILT
|
|
| SUPPORT_CLOSE_TILT
|
|
| SUPPORT_STOP_TILT
|
|
| SUPPORT_SET_TILT_POSITION
|
|
)
|
|
|
|
return supported_features
|
|
|
|
@property
|
|
def is_closed(self):
|
|
"""Return if the cover is closed."""
|
|
is_closed = self.roller.closed_percent == 100
|
|
return is_closed
|
|
|
|
async def close_cover(self, **kwargs):
|
|
"""Close the roller."""
|
|
await self.roller.move_down()
|
|
|
|
async def open_cover(self, **kwargs):
|
|
"""Open the roller."""
|
|
await self.roller.move_up()
|
|
|
|
async def stop_cover(self, **kwargs):
|
|
"""Stop the roller."""
|
|
await self.roller.move_stop()
|
|
|
|
async def set_cover_position(self, **kwargs):
|
|
"""Move the roller shutter to a specific position."""
|
|
await self.roller.move_to(100 - kwargs[ATTR_POSITION])
|
|
|
|
async def close_cover_tilt(self, **kwargs):
|
|
"""Close the roller."""
|
|
await self.roller.move_down()
|
|
|
|
async def open_cover_tilt(self, **kwargs):
|
|
"""Open the roller."""
|
|
await self.roller.move_up()
|
|
|
|
async def stop_cover_tilt(self, **kwargs):
|
|
"""Stop the roller."""
|
|
await self.roller.move_stop()
|
|
|
|
async def set_cover_tilt(self, **kwargs):
|
|
"""Tilt the roller shutter to a specific position."""
|
|
await self.roller.move_to(100 - kwargs[ATTR_POSITION])
|