Add send capability
parent
d64f0ddd41
commit
cc47e39006
|
@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
# Add light from config file
|
# Add light from config file
|
||||||
lights = []
|
lights = []
|
||||||
devices = config.get('devices')
|
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:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
_LOGGER.info("Add %s rfxtrx.light", entity_name)
|
_LOGGER.info("Add %s rfxtrx.light", entity_info['name'])
|
||||||
new_light = RfxtrxLight(entity_name, False)
|
new_light = RfxtrxLight(entity_info['name'], None, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
||||||
lights.append(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:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
automatic_add = config.get('automatic_add', False)
|
automatic_add = config.get('automatic_add', False)
|
||||||
if automatic_add:
|
if automatic_add:
|
||||||
_LOGGER.info("Automatic add %s rfxtrx.light", entity_id)
|
_LOGGER.info("Automatic add %s rfxtrx.light (class: %s subtype: %s)",
|
||||||
new_light = RfxtrxLight(entity_id, False)
|
entity_id,
|
||||||
|
event.device.__class__.__name__,
|
||||||
|
event.device.subtype
|
||||||
|
)
|
||||||
|
new_light = RfxtrxLight(entity_id, event, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
||||||
add_devices_callback([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):
|
class RfxtrxLight(Light):
|
||||||
""" Provides a demo switch. """
|
""" Provides a demo switch. """
|
||||||
def __init__(self, name, state):
|
def __init__(self, name, event, state):
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._event = event
|
||||||
self._state = state
|
self._state = state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -101,10 +106,16 @@ class RfxtrxLight(Light):
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
|
|
||||||
|
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
|
||||||
|
|
||||||
self._state = True
|
self._state = True
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
|
|
||||||
|
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
|
@ -15,7 +15,7 @@ CONF_DEVICE = 'device'
|
||||||
RECEIVED_EVT_SUBSCRIBERS = []
|
RECEIVED_EVT_SUBSCRIBERS = []
|
||||||
RFX_DEVICES = {}
|
RFX_DEVICES = {}
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
RFXOBJECT = None
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup the Rfxtrx component. """
|
""" Setup the Rfxtrx component. """
|
||||||
|
@ -34,7 +34,8 @@ def setup(hass, config):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Init the rfxtrx module
|
# Init the rfxtrx module
|
||||||
|
global RFXOBJECT
|
||||||
device = config[DOMAIN][CONF_DEVICE]
|
device = config[DOMAIN][CONF_DEVICE]
|
||||||
rfxtrxmod.Core(device, handle_receive)
|
RFXOBJECT = rfxtrxmod.Core(device, handle_receive)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -42,10 +42,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
# Add switch from config file
|
# Add switch from config file
|
||||||
switchs = []
|
switchs = []
|
||||||
devices = config.get('devices')
|
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:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
_LOGGER.info("Add %s rfxtrx.switch", entity_name)
|
_LOGGER.info("Add %s rfxtrx.switch", entity_info['name'])
|
||||||
new_switch = RfxtrxSwitch(entity_name, False)
|
new_switch = RfxtrxSwitch(entity_info['name'], None, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
||||||
switchs.append(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:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
automatic_add = config.get('automatic_add', False)
|
automatic_add = config.get('automatic_add', False)
|
||||||
if automatic_add:
|
if automatic_add:
|
||||||
_LOGGER.info("Automatic add %s rfxtrx.switch", entity_id)
|
_LOGGER.info("Automatic add %s rfxtrx.switch (class: %s subtype: %s)",
|
||||||
new_switch = RfxtrxSwitch(entity_id, False)
|
entity_id,
|
||||||
|
event.device.__class__.__name__,
|
||||||
|
event.device.subtype
|
||||||
|
)
|
||||||
|
new_switch = RfxtrxSwitch(entity_id, event, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
||||||
add_devices_callback([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):
|
class RfxtrxSwitch(SwitchDevice):
|
||||||
""" Provides a demo switch. """
|
""" Provides a demo switch. """
|
||||||
def __init__(self, name, state):
|
def __init__(self, name, event, state):
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._event = event
|
||||||
self._state = state
|
self._state = state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -101,10 +106,14 @@ class RfxtrxSwitch(SwitchDevice):
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turn the device on. """
|
""" Turn the device on. """
|
||||||
|
self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
|
||||||
|
|
||||||
self._state = True
|
self._state = True
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
|
self._event.device.send_off(rfxtrx.RFXOBJECT.transport)
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
Loading…
Reference in New Issue