Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/cover/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the RFXtrx cover."""
import RFXtrx as rfxtrxmod

covers = rfxtrx.get_devices_from_config(config, RfxtrxCover, hass)
covers = rfxtrx.get_devices_from_config(config, RfxtrxCover)
add_devices_callback(covers)

def cover_update(event):
Expand All @@ -26,7 +26,7 @@ def cover_update(event):
not event.device.known_to_be_rollershutter:
return

new_device = rfxtrx.get_new_device(event, config, RfxtrxCover, hass)
new_device = rfxtrx.get_new_device(event, config, RfxtrxCover)
if new_device:
add_devices_callback([new_device])

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/light/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the RFXtrx platform."""
import RFXtrx as rfxtrxmod

lights = rfxtrx.get_devices_from_config(config, RfxtrxLight, hass)
lights = rfxtrx.get_devices_from_config(config, RfxtrxLight)
add_devices(lights)

def light_update(event):
Expand All @@ -32,7 +32,7 @@ def light_update(event):
not event.device.known_to_be_dimmable:
return

new_device = rfxtrx.get_new_device(event, config, RfxtrxLight, hass)
new_device = rfxtrx.get_new_device(event, config, RfxtrxLight)
if new_device:
add_devices([new_device])

Expand Down
47 changes: 26 additions & 21 deletions homeassistant/components/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/rfxtrx/
"""

import logging
from collections import OrderedDict
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.util import slugify
from homeassistant.const import (
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
ATTR_ENTITY_ID, TEMP_CELSIUS,
CONF_DEVICE_CLASS, CONF_COMMAND_ON, CONF_COMMAND_OFF
)
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['pyRFXtrx==0.19.0']
REQUIREMENTS = ['pyRFXtrx==0.20.0']

DOMAIN = 'rfxtrx'

Expand Down Expand Up @@ -54,7 +56,7 @@
RECEIVED_EVT_SUBSCRIBERS = []
RFX_DEVICES = {}
_LOGGER = logging.getLogger(__name__)
RFXOBJECT = None
RFXOBJECT = 'rfxobject'


def _valid_device(value, device_type):
Expand Down Expand Up @@ -171,24 +173,24 @@ def handle_receive(event):
# Try to load the RFXtrx module.
import RFXtrx as rfxtrxmod

# Init the rfxtrx module.
global RFXOBJECT

device = config[DOMAIN][ATTR_DEVICE]
debug = config[DOMAIN][ATTR_DEBUG]
dummy_connection = config[DOMAIN][ATTR_DUMMY]

if dummy_connection:
RFXOBJECT =\
rfxtrxmod.Connect(device, handle_receive, debug=debug,
hass.data[RFXOBJECT] =\
rfxtrxmod.Connect(device, None, debug=debug,
transport_protocol=rfxtrxmod.DummyTransport2)
else:
RFXOBJECT = rfxtrxmod.Connect(device, handle_receive, debug=debug)
hass.data[RFXOBJECT] = rfxtrxmod.Connect(device, None, debug=debug)

def _start_rfxtrx(event):
hass.data[RFXOBJECT].event_callback = handle_receive
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, _start_rfxtrx)

def _shutdown_rfxtrx(event):
"""Close connection with RFXtrx."""
RFXOBJECT.close_connection()

hass.data[RFXOBJECT].close_connection()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown_rfxtrx)

return True
Expand Down Expand Up @@ -285,7 +287,7 @@ def find_possible_pt2262_device(device_id):
return None


def get_devices_from_config(config, device, hass):
def get_devices_from_config(config, device):
"""Read rfxtrx configuration."""
signal_repetitions = config[CONF_SIGNAL_REPETITIONS]

Expand All @@ -303,13 +305,12 @@ def get_devices_from_config(config, device, hass):

new_device = device(entity_info[ATTR_NAME], event, datas,
signal_repetitions)
new_device.hass = hass
RFX_DEVICES[device_id] = new_device
devices.append(new_device)
return devices


def get_new_device(event, config, device, hass):
def get_new_device(event, config, device):
"""Add entity if not exist and the automatic_add is True."""
device_id = slugify(event.device.id_string.lower())
if device_id in RFX_DEVICES:
Expand All @@ -330,7 +331,6 @@ def get_new_device(event, config, device, hass):
signal_repetitions = config[CONF_SIGNAL_REPETITIONS]
new_device = device(pkt_id, event, datas,
signal_repetitions)
new_device.hass = hass
RFX_DEVICES[device_id] = new_device
return new_device

Expand Down Expand Up @@ -438,31 +438,36 @@ def _send_command(self, command, brightness=0):

if command == "turn_on":
for _ in range(self.signal_repetitions):
self._event.device.send_on(RFXOBJECT.transport)
self._event.device.send_on(self.hass.data[RFXOBJECT]
.transport)
self._state = True

elif command == "dim":
for _ in range(self.signal_repetitions):
self._event.device.send_dim(RFXOBJECT.transport,
brightness)
self._event.device.send_dim(self.hass.data[RFXOBJECT]
.transport, brightness)
self._state = True

elif command == 'turn_off':
for _ in range(self.signal_repetitions):
self._event.device.send_off(RFXOBJECT.transport)
self._event.device.send_off(self.hass.data[RFXOBJECT]
.transport)
self._state = False
self._brightness = 0

elif command == "roll_up":
for _ in range(self.signal_repetitions):
self._event.device.send_open(RFXOBJECT.transport)
self._event.device.send_open(self.hass.data[RFXOBJECT]
.transport)

elif command == "roll_down":
for _ in range(self.signal_repetitions):
self._event.device.send_close(RFXOBJECT.transport)
self._event.device.send_close(self.hass.data[RFXOBJECT]
.transport)

elif command == "stop_roll":
for _ in range(self.signal_repetitions):
self._event.device.send_stop(RFXOBJECT.transport)
self._event.device.send_stop(self.hass.data[RFXOBJECT]
.transport)

self.schedule_update_ha_state()
4 changes: 2 additions & 2 deletions homeassistant/components/switch/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
import RFXtrx as rfxtrxmod

# Add switch from config file
switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch, hass)
switches = rfxtrx.get_devices_from_config(config, RfxtrxSwitch)
add_devices_callback(switches)

def switch_update(event):
Expand All @@ -31,7 +31,7 @@ def switch_update(event):
event.device.known_to_be_rollershutter:
return

new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch, hass)
new_device = rfxtrx.get_new_device(event, config, RfxtrxSwitch)
if new_device:
add_devices_callback([new_device])

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ pyCEC==0.4.13
pyHS100==0.2.4.2

# homeassistant.components.rfxtrx
pyRFXtrx==0.19.0
pyRFXtrx==0.20.0

# homeassistant.components.switch.dlink
pyW215==0.5.1
Expand Down