Skip to content
Snippets Groups Projects
Commit 3c582d1e authored by Paulus Schoutsen's avatar Paulus Schoutsen
Browse files

Merge pull request #1143 from balloob/rfxtrx

Rfxtrx
parents 19d12716 f9381340
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,8 @@ 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.LightingDevice) or \
not event.device.known_to_be_dimmable:
return
# Add entity if not exist and the automatic_add is True
......@@ -74,13 +75,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 +91,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.4.zip' +
'#RFXtrx==0.4']
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.LightingDevice) or \
event.device.known_to_be_dimmable:
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,
......
......@@ -64,7 +64,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.4.zip#RFXtrx==0.4
# homeassistant.components.sensor.netatmo
https://github.com/HydrelioxGitHub/netatmo-api-python/archive/43ff238a0122b0939a0dc4e8836b6782913fb6e2.zip#lnetatmo==0.4.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment