Update rfxtrx component so it can be run as a custom_component (#29638)

* Updating rfxtrx component so it can be run as a custom_component

* Fix pylint errors

* Fix pylint errors

* Fix pylint error on dict.

* isort
This commit is contained in:
foxy82 authored and Martin Hjelmare committed 2019-12-11 15:58:49 +01:00
1 parent 856dd63680
commit a08e3d7352
5 files changed
+64 -46

No files matched your search

+11 -7
View File
@@ -4,7 +4,6 @@ import logging
import RFXtrx as rfxtrxmod
import voluptuous as vol
from homeassistant.components import rfxtrx
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_NAME
from homeassistant.helpers import config_validation as cv
@@ -15,6 +14,11 @@ from . import (
CONF_FIRE_EVENT,
CONF_SIGNAL_REPETITIONS,
DEFAULT_SIGNAL_REPETITIONS,
RECEIVED_EVT_SUBSCRIBERS,
RfxtrxDevice,
apply_received_command,
get_devices_from_config,
get_new_device,
)
_LOGGER = logging.getLogger(__name__)
@@ -40,7 +44,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities_callback, discovery_info=None):
"""Set up the RFXtrx platform."""
# Add switch from config file
switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch)
switches = get_devices_from_config(config, RfxtrxSwitch)
add_entities_callback(switches)
def switch_update(event):
@@ -52,18 +56,18 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None):
):
return
new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch)
new_device = get_new_device(event, config, RfxtrxSwitch)
if new_device:
add_entities_callback([new_device])
rfxtrx.apply_received_command(event)
apply_received_command(event)
# Subscribe to main RFXtrx events
if switch_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(switch_update)
if switch_update not in RECEIVED_EVT_SUBSCRIBERS:
RECEIVED_EVT_SUBSCRIBERS.append(switch_update)
class RfxtrxSwitch(rfxtrx.RfxtrxDevice, SwitchDevice):
class RfxtrxSwitch(RfxtrxDevice, SwitchDevice):
"""Representation of a RFXtrx switch."""
def turn_on(self, **kwargs):