mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve the robustness of the rfxtrx module, and solve issue #1116
This commit is contained in:
parent
a5db23afa4
commit
cdf0e80773
@ -40,6 +40,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
datas = {ATTR_STATE: False, ATTR_FIREEVENT: fire_event}
|
||||
|
||||
rfxobject = rfxtrx.get_rfx_object(entity_info[ATTR_PACKETID])
|
||||
if not isinstance(rfxobject.device, rfxtrxmod.LightDevice):
|
||||
_LOGGER.exception("%s is not a light",
|
||||
entity_info[ATTR_NAME])
|
||||
return
|
||||
new_light = RfxtrxLight(
|
||||
entity_info[ATTR_NAME], rfxobject, datas
|
||||
)
|
||||
@ -50,7 +54,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
def light_update(event):
|
||||
""" Callback for light updates from the RFXtrx gateway. """
|
||||
if not isinstance(event.device, rfxtrxmod.LightingDevice):
|
||||
if not isinstance(event.device, rfxtrxmod.LightDevice):
|
||||
return
|
||||
|
||||
# Add entity if not exist and the automatic_add is True
|
||||
@ -74,13 +78,13 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
add_devices_callback([new_light])
|
||||
|
||||
# Check if entity exists or previously added automatically
|
||||
if entity_id in rfxtrx.RFX_DEVICES \
|
||||
and isinstance(rfxtrx.RFX_DEVICES[entity_id], RfxtrxLight):
|
||||
if entity_id in rfxtrx.RFX_DEVICES:
|
||||
_LOGGER.debug(
|
||||
"EntityID: %s light_update. Command: %s",
|
||||
entity_id,
|
||||
event.values['Command']
|
||||
)
|
||||
|
||||
if event.values['Command'] == 'On'\
|
||||
or event.values['Command'] == 'Off':
|
||||
|
||||
@ -90,15 +94,27 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
rfxtrx.RFX_DEVICES[entity_id]._state = is_on
|
||||
rfxtrx.RFX_DEVICES[entity_id].update_ha_state()
|
||||
|
||||
# Fire event
|
||||
if rfxtrx.RFX_DEVICES[entity_id].should_fire_event:
|
||||
rfxtrx.RFX_DEVICES[entity_id].hass.bus.fire(
|
||||
EVENT_BUTTON_PRESSED, {
|
||||
ATTR_ENTITY_ID:
|
||||
rfxtrx.RFX_DEVICES[entity_id].entity_id,
|
||||
ATTR_STATE: event.values['Command'].lower()
|
||||
}
|
||||
)
|
||||
elif event.values['Command'] == 'Set level':
|
||||
# pylint: disable=protected-access
|
||||
rfxtrx.RFX_DEVICES[entity_id]._brightness = \
|
||||
(event.values['Dim level'] * 255 // 100)
|
||||
|
||||
# Update the rfxtrx device state
|
||||
is_on = rfxtrx.RFX_DEVICES[entity_id]._brightness > 0
|
||||
rfxtrx.RFX_DEVICES[entity_id]._state = is_on
|
||||
rfxtrx.RFX_DEVICES[entity_id].update_ha_state()
|
||||
else:
|
||||
return
|
||||
|
||||
# Fire event
|
||||
if rfxtrx.RFX_DEVICES[entity_id].should_fire_event:
|
||||
rfxtrx.RFX_DEVICES[entity_id].hass.bus.fire(
|
||||
EVENT_BUTTON_PRESSED, {
|
||||
ATTR_ENTITY_ID:
|
||||
rfxtrx.RFX_DEVICES[entity_id].entity_id,
|
||||
ATTR_STATE: event.values['Command'].lower()
|
||||
}
|
||||
)
|
||||
|
||||
# Subscribe to main rfxtrx events
|
||||
if light_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
||||
|
@ -9,8 +9,8 @@ https://home-assistant.io/components/rfxtrx/
|
||||
import logging
|
||||
from homeassistant.util import slugify
|
||||
|
||||
REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip' +
|
||||
'#RFXtrx==0.2']
|
||||
REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.3.zip' +
|
||||
'#RFXtrx==0.3']
|
||||
|
||||
DOMAIN = "rfxtrx"
|
||||
|
||||
@ -37,6 +37,8 @@ def setup(hass, config):
|
||||
""" Callback all subscribers for RFXtrx gateway. """
|
||||
|
||||
# Log RFXCOM event
|
||||
if not event.device.id_string:
|
||||
return
|
||||
entity_id = slugify(event.device.id_string.lower())
|
||||
packet_id = "".join("{0:02x}".format(x) for x in event.data)
|
||||
entity_name = "%s : %s" % (entity_id, packet_id)
|
||||
|
@ -49,7 +49,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
def switch_update(event):
|
||||
""" Callback for sensor updates from the RFXtrx gateway. """
|
||||
if not isinstance(event.device, rfxtrxmod.LightingDevice):
|
||||
if not isinstance(event.device, rfxtrxmod.SwitchDevice) or \
|
||||
isinstance(event.device, rfxtrxmod.LightDevice):
|
||||
return
|
||||
|
||||
# Add entity if not exist and the automatic_add is True
|
||||
@ -73,8 +74,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
add_devices_callback([new_switch])
|
||||
|
||||
# Check if entity exists or previously added automatically
|
||||
if entity_id in rfxtrx.RFX_DEVICES \
|
||||
and isinstance(rfxtrx.RFX_DEVICES[entity_id], RfxtrxSwitch):
|
||||
if entity_id in rfxtrx.RFX_DEVICES:
|
||||
_LOGGER.debug(
|
||||
"EntityID: %s switch_update. Command: %s",
|
||||
entity_id,
|
||||
|
@ -61,7 +61,7 @@ hikvision==0.4
|
||||
# http://github.com/mala-zaba/Adafruit_Python_DHT/archive/4101340de8d2457dd194bca1e8d11cbfc237e919.zip#Adafruit_DHT==1.1.0
|
||||
|
||||
# homeassistant.components.rfxtrx
|
||||
https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip#RFXtrx==0.2
|
||||
https://github.com/Danielhiversen/pyRFXtrx/archive/0.3.zip#RFXtrx==0.3
|
||||
|
||||
# homeassistant.components.sensor.netatmo
|
||||
https://github.com/HydrelioxGitHub/netatmo-api-python/archive/43ff238a0122b0939a0dc4e8836b6782913fb6e2.zip#lnetatmo==0.4.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user