2016-08-24 01:23:18 +00:00
|
|
|
"""
|
|
|
|
Support for RFXtrx cover components.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/cover.rfxtrx/
|
|
|
|
"""
|
2018-01-12 19:52:53 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2016-08-24 01:23:18 +00:00
|
|
|
import homeassistant.components.rfxtrx as rfxtrx
|
2018-01-12 19:52:53 +00:00
|
|
|
from homeassistant.components.cover import CoverDevice, PLATFORM_SCHEMA
|
|
|
|
from homeassistant.const import CONF_NAME
|
|
|
|
from homeassistant.components.rfxtrx import (
|
|
|
|
CONF_AUTOMATIC_ADD, CONF_FIRE_EVENT, DEFAULT_SIGNAL_REPETITIONS,
|
|
|
|
CONF_SIGNAL_REPETITIONS, CONF_DEVICES)
|
|
|
|
from homeassistant.helpers import config_validation as cv
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ['rfxtrx']
|
|
|
|
|
2018-01-12 19:52:53 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
|
|
vol.Optional(CONF_DEVICES, default={}): {
|
|
|
|
cv.string: vol.Schema({
|
|
|
|
vol.Required(CONF_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_FIRE_EVENT, default=False): cv.boolean
|
|
|
|
})
|
|
|
|
},
|
|
|
|
vol.Optional(CONF_AUTOMATIC_ADD, default=False): cv.boolean,
|
|
|
|
vol.Optional(CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS):
|
|
|
|
vol.Coerce(int),
|
|
|
|
})
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
|
2018-01-21 06:35:38 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the RFXtrx cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
import RFXtrx as rfxtrxmod
|
|
|
|
|
2017-08-29 14:22:28 +00:00
|
|
|
covers = rfxtrx.get_devices_from_config(config, RfxtrxCover)
|
2018-01-21 06:35:38 +00:00
|
|
|
add_devices(covers)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def cover_update(event):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Handle cover updates from the RFXtrx gateway."""
|
2016-08-24 01:23:18 +00:00
|
|
|
if not isinstance(event.device, rfxtrxmod.LightingDevice) or \
|
|
|
|
event.device.known_to_be_dimmable or \
|
|
|
|
not event.device.known_to_be_rollershutter:
|
|
|
|
return
|
|
|
|
|
2017-08-29 14:22:28 +00:00
|
|
|
new_device = rfxtrx.get_new_device(event, config, RfxtrxCover)
|
2016-08-24 01:23:18 +00:00
|
|
|
if new_device:
|
2018-01-21 06:35:38 +00:00
|
|
|
add_devices([new_device])
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
rfxtrx.apply_received_command(event)
|
|
|
|
|
2017-04-30 05:04:49 +00:00
|
|
|
# Subscribe to main RFXtrx events
|
2016-08-24 01:23:18 +00:00
|
|
|
if cover_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
|
|
|
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(cover_update)
|
|
|
|
|
|
|
|
|
|
|
|
class RfxtrxCover(rfxtrx.RfxtrxDevice, CoverDevice):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Representation of a RFXtrx cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Return the polling state. No polling available in RFXtrx cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
def open_cover(self, **kwargs):
|
|
|
|
"""Move the cover up."""
|
|
|
|
self._send_command("roll_up")
|
|
|
|
|
|
|
|
def close_cover(self, **kwargs):
|
|
|
|
"""Move the cover down."""
|
|
|
|
self._send_command("roll_down")
|
|
|
|
|
|
|
|
def stop_cover(self, **kwargs):
|
|
|
|
"""Stop the cover."""
|
|
|
|
self._send_command("stop_roll")
|