2015-09-27 09:13:49 +00:00
|
|
|
"""
|
2015-10-08 09:09:00 +00:00
|
|
|
Support for RFXtrx switches.
|
2015-09-27 09:13:49 +00:00
|
|
|
|
2015-10-08 09:09:00 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 12:12:18 +00:00
|
|
|
https://home-assistant.io/components/switch.rfxtrx/
|
2015-09-27 09:13:49 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2016-02-19 05:27:50 +00:00
|
|
|
import homeassistant.components.rfxtrx as rfxtrx
|
2015-09-27 09:13:49 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
2015-11-26 06:52:37 +00:00
|
|
|
|
2015-10-07 17:04:03 +00:00
|
|
|
DEPENDENCIES = ['rfxtrx']
|
2015-09-27 09:13:49 +00:00
|
|
|
|
2015-09-29 06:20:25 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2016-04-09 03:55:31 +00:00
|
|
|
PLATFORM_SCHEMA = rfxtrx.DEFAULT_SCHEMA
|
|
|
|
|
2015-09-27 09:13:49 +00:00
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the RFXtrx platform."""
|
2015-11-26 07:27:31 +00:00
|
|
|
import RFXtrx as rfxtrxmod
|
2015-09-27 21:51:19 +00:00
|
|
|
|
2015-09-27 09:13:49 +00:00
|
|
|
# Add switch from config file
|
2017-08-29 14:22:28 +00:00
|
|
|
switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch)
|
2016-04-06 17:34:51 +00:00
|
|
|
add_devices_callback(switches)
|
2015-09-27 09:13:49 +00:00
|
|
|
|
|
|
|
def switch_update(event):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Handle sensor updates from the RFXtrx gateway."""
|
2016-02-11 13:15:51 +00:00
|
|
|
if not isinstance(event.device, rfxtrxmod.LightingDevice) or \
|
2016-06-02 07:39:58 +00:00
|
|
|
event.device.known_to_be_dimmable or \
|
|
|
|
event.device.known_to_be_rollershutter:
|
2015-10-07 17:15:50 +00:00
|
|
|
return
|
|
|
|
|
2017-08-29 14:22:28 +00:00
|
|
|
new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch)
|
2016-04-06 17:34:51 +00:00
|
|
|
if new_device:
|
|
|
|
add_devices_callback([new_device])
|
2015-11-26 06:52:37 +00:00
|
|
|
|
2016-04-06 17:34:51 +00:00
|
|
|
rfxtrx.apply_received_command(event)
|
2015-10-07 17:15:50 +00:00
|
|
|
|
2017-05-02 20:47:20 +00:00
|
|
|
# Subscribe to main RFXtrx events
|
2015-09-27 09:13:49 +00:00
|
|
|
if switch_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
|
|
|
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(switch_update)
|
|
|
|
|
|
|
|
|
2016-04-06 17:34:51 +00:00
|
|
|
class RfxtrxSwitch(rfxtrx.RfxtrxDevice, SwitchDevice):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Representation of a RFXtrx switch."""
|
|
|
|
|
2015-09-27 09:13:49 +00:00
|
|
|
def turn_on(self, **kwargs):
|
2016-03-08 12:35:39 +00:00
|
|
|
"""Turn the device on."""
|
2016-04-06 17:34:51 +00:00
|
|
|
self._send_command("turn_on")
|