diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index f96a9f7b1fa..08f3dcc7c60 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -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: diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index 60f6f7a5cd6..60736585c28 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -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) diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index 84f4df82b1f..b3d19a5db3b 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -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, diff --git a/requirements_all.txt b/requirements_all.txt index 1a032958157..26b7abbb71f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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