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:
1 parent
856dd63680
commit
a08e3d7352
5 files changed
+64
-46
No files matched your search
@@ -4,7 +4,6 @@ import logging
|
||||
from RFXtrx import SensorEvent
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import rfxtrx
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_NAME, CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -19,6 +18,9 @@ from . import (
|
||||
CONF_DEVICES,
|
||||
CONF_FIRE_EVENT,
|
||||
DATA_TYPES,
|
||||
RECEIVED_EVT_SUBSCRIBERS,
|
||||
RFX_DEVICES,
|
||||
get_rfx_object,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -46,9 +48,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the RFXtrx platform."""
|
||||
sensors = []
|
||||
for packet_id, entity_info in config[CONF_DEVICES].items():
|
||||
event = rfxtrx.get_rfx_object(packet_id)
|
||||
event = get_rfx_object(packet_id)
|
||||
device_id = "sensor_{}".format(slugify(event.device.id_string.lower()))
|
||||
if device_id in rfxtrx.RFX_DEVICES:
|
||||
if device_id in RFX_DEVICES:
|
||||
continue
|
||||
_LOGGER.info("Add %s rfxtrx.sensor", entity_info[ATTR_NAME])
|
||||
|
||||
@@ -66,7 +68,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
)
|
||||
sensors.append(new_sensor)
|
||||
sub_sensors[_data_type] = new_sensor
|
||||
rfxtrx.RFX_DEVICES[device_id] = sub_sensors
|
||||
RFX_DEVICES[device_id] = sub_sensors
|
||||
add_entities(sensors)
|
||||
|
||||
def sensor_update(event):
|
||||
@@ -76,8 +78,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
device_id = "sensor_" + slugify(event.device.id_string.lower())
|
||||
|
||||
if device_id in rfxtrx.RFX_DEVICES:
|
||||
sensors = rfxtrx.RFX_DEVICES[device_id]
|
||||
if device_id in RFX_DEVICES:
|
||||
sensors = RFX_DEVICES[device_id]
|
||||
for data_type in sensors:
|
||||
# Some multi-sensor devices send individual messages for each
|
||||
# of their sensors. Update only if event contains the
|
||||
@@ -108,11 +110,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
new_sensor = RfxtrxSensor(event, pkt_id, data_type)
|
||||
sub_sensors = {}
|
||||
sub_sensors[new_sensor.data_type] = new_sensor
|
||||
rfxtrx.RFX_DEVICES[device_id] = sub_sensors
|
||||
RFX_DEVICES[device_id] = sub_sensors
|
||||
add_entities([new_sensor])
|
||||
|
||||
if sensor_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
||||
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(sensor_update)
|
||||
if sensor_update not in RECEIVED_EVT_SUBSCRIBERS:
|
||||
RECEIVED_EVT_SUBSCRIBERS.append(sensor_update)
|
||||
|
||||
|
||||
class RfxtrxSensor(Entity):
|
||||
|
||||
Reference in new issue
Block a user