Add send capability

pull/483/head
badele 2015-09-29 22:47:22 +02:00
parent d64f0ddd41
commit cc47e39006
3 changed files with 35 additions and 14 deletions

View File

@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# Add light from config file
lights = []
devices = config.get('devices')
for entity_id, entity_name in devices.items():
for entity_id, entity_info in devices.items():
if entity_id not in rfxtrx.RFX_DEVICES:
_LOGGER.info("Add %s rfxtrx.light", entity_name)
new_light = RfxtrxLight(entity_name, False)
_LOGGER.info("Add %s rfxtrx.light", entity_info['name'])
new_light = RfxtrxLight(entity_info['name'], None, False)
rfxtrx.RFX_DEVICES[entity_id] = new_light
lights.append(new_light)
@ -60,8 +60,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
if entity_id not in rfxtrx.RFX_DEVICES:
automatic_add = config.get('automatic_add', False)
if automatic_add:
_LOGGER.info("Automatic add %s rfxtrx.light", entity_id)
new_light = RfxtrxLight(entity_id, False)
_LOGGER.info("Automatic add %s rfxtrx.light (class: %s subtype: %s)",
entity_id,
event.device.__class__.__name__,
event.device.subtype
)
new_light = RfxtrxLight(entity_id, event, False)
rfxtrx.RFX_DEVICES[entity_id] = new_light
add_devices_callback([new_light])
@ -80,8 +84,9 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxLight(Light):
""" Provides a demo switch. """
def __init__(self, name, state):
def __init__(self, name, event, state):
self._name = name
self._event = event
self._state = state
@property
@ -101,10 +106,16 @@ class RfxtrxLight(Light):
def turn_on(self, **kwargs):
""" Turn the device on. """
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
self._state = True
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn the device off. """
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
self._state = False
self.update_ha_state()

View File

@ -15,7 +15,7 @@ CONF_DEVICE = 'device'
RECEIVED_EVT_SUBSCRIBERS = []
RFX_DEVICES = {}
_LOGGER = logging.getLogger(__name__)
RFXOBJECT = None
def setup(hass, config):
""" Setup the Rfxtrx component. """
@ -34,7 +34,8 @@ def setup(hass, config):
return False
# Init the rfxtrx module
global RFXOBJECT
device = config[DOMAIN][CONF_DEVICE]
rfxtrxmod.Core(device, handle_receive)
RFXOBJECT = rfxtrxmod.Core(device, handle_receive)
return True

View File

@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
# Add switch from config file
switchs = []
devices = config.get('devices')
for entity_id, entity_name in devices.items():
for entity_id, entity_info in devices.items():
if entity_id not in rfxtrx.RFX_DEVICES:
_LOGGER.info("Add %s rfxtrx.switch", entity_name)
new_switch = RfxtrxSwitch(entity_name, False)
_LOGGER.info("Add %s rfxtrx.switch", entity_info['name'])
new_switch = RfxtrxSwitch(entity_info['name'], None, False)
rfxtrx.RFX_DEVICES[entity_id] = new_switch
switchs.append(new_switch)
@ -60,8 +60,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
if entity_id not in rfxtrx.RFX_DEVICES:
automatic_add = config.get('automatic_add', False)
if automatic_add:
_LOGGER.info("Automatic add %s rfxtrx.switch", entity_id)
new_switch = RfxtrxSwitch(entity_id, False)
_LOGGER.info("Automatic add %s rfxtrx.switch (class: %s subtype: %s)",
entity_id,
event.device.__class__.__name__,
event.device.subtype
)
new_switch = RfxtrxSwitch(entity_id, event, False)
rfxtrx.RFX_DEVICES[entity_id] = new_switch
add_devices_callback([new_switch])
@ -80,8 +84,9 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxSwitch(SwitchDevice):
""" Provides a demo switch. """
def __init__(self, name, state):
def __init__(self, name, event, state):
self._name = name
self._event = event
self._state = state
@property
@ -101,10 +106,14 @@ class RfxtrxSwitch(SwitchDevice):
def turn_on(self, **kwargs):
""" Turn the device on. """
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
self._state = True
self.update_ha_state()
def turn_off(self, **kwargs):
""" Turn the device off. """
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
self._state = False
self.update_ha_state()