Merge remote-tracking branch 'upstream/dev' into dev_tracker_snmp

This commit is contained in:
Tom Duijf 2015-10-08 10:01:24 +00:00
commit fe37a6aecc
5 changed files with 39 additions and 81 deletions

View File

@ -1,34 +1,36 @@
""" """
homeassistant.components.light.blinksticklight homeassistant.components.light.blinksticklight
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Blinkstick lights. Support for Blinkstick lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.blinksticklight.html
""" """
import logging
from blinkstick import blinkstick from blinkstick import blinkstick
import logging
from homeassistant.components.light import (Light, ATTR_RGB_COLOR)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
from homeassistant.components.light import (Light, ATTR_RGB_COLOR)
REQUIREMENTS = ["blinkstick==1.1.7"] REQUIREMENTS = ["blinkstick==1.1.7"]
DEPENDENCIES = [] DEPENDENCIES = []
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Add device specified by serial number """ """ Add device specified by serial number. """
stick = blinkstick.find_by_serial(config['serial']) stick = blinkstick.find_by_serial(config['serial'])
add_devices_callback([BlinkStickLight(stick, config['name'])]) add_devices_callback([BlinkStickLight(stick, config['name'])])
class BlinkStickLight(Light): class BlinkStickLight(Light):
""" Represents a BlinkStick light """ """ Represents a BlinkStick light. """
def __init__(self, stick, name): def __init__(self, stick, name):
""" Initialise """
self._stick = stick self._stick = stick
self._name = name self._name = name
self._serial = stick.get_serial() self._serial = stick.get_serial()
@ -36,20 +38,22 @@ class BlinkStickLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" Polling needed. """
return True return True
@property @property
def name(self): def name(self):
""" The name of the light. """
return self._name return self._name
@property @property
def rgb_color(self): def rgb_color(self):
""" Read back the color of the light """ """ Read back the color of the light. """
return self._rgb_color return self._rgb_color
@property @property
def is_on(self): def is_on(self):
""" Check whether any of the LEDs colors are non-zero """ """ Check whether any of the LEDs colors are non-zero. """
return sum(self._rgb_color) > 0 return sum(self._rgb_color) > 0
def update(self): def update(self):

View File

@ -1,26 +1,10 @@
""" """
homeassistant.components.light.rfxtrx homeassistant.components.light.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Rfxtrx lights. Support for RFXtrx lights.
Configuration:
To use Rfxtrx lights you will need to add the following to your
configuration.yaml file.
light:
platform: rfxtrx
devices:
ac09c4f1: Bedroom Light
ac09c4f2: Kitchen Light
ac09c4f3: Bathroom Light
*Optional*
# Automatic add new light
automatic_add: True
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.rfxtrx.html
""" """
import logging import logging
import homeassistant.components.rfxtrx as rfxtrx import homeassistant.components.rfxtrx as rfxtrx
@ -36,7 +20,6 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Setup the RFXtrx platform. """ """ Setup the RFXtrx platform. """
# Add light from config file
lights = [] lights = []
devices = config.get('devices', None) devices = config.get('devices', None)
if devices: if devices:
@ -51,7 +34,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
add_devices_callback(lights) add_devices_callback(lights)
def light_update(event): def light_update(event):
""" Callback for sensor updates from the RFXtrx gateway. """ """ Callback for light updates from the RFXtrx gateway. """
if not isinstance(event.device, rfxtrxmod.LightingDevice): if not isinstance(event.device, rfxtrxmod.LightingDevice):
return return
@ -89,7 +72,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxLight(Light): class RfxtrxLight(Light):
""" Provides a demo switch. """ """ Provides a RFXtrx light. """
def __init__(self, name, event, state): def __init__(self, name, event, state):
self._name = name self._name = name
self._event = event self._event = event
@ -97,21 +80,21 @@ class RfxtrxLight(Light):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a demo light. """ """ No polling needed for a light. """
return False return False
@property @property
def name(self): def name(self):
""" Returns the name of the device if any. """ """ Returns the name of the light if any. """
return self._name return self._name
@property @property
def is_on(self): def is_on(self):
""" True if device is on. """ """ True if light is on. """
return self._state return self._state
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
""" Turn the device on. """ """ Turn the light on. """
if hasattr(self, '_event') and self._event: if hasattr(self, '_event') and self._event:
self._event.device.send_on(rfxtrx.RFXOBJECT.transport) self._event.device.send_on(rfxtrx.RFXOBJECT.transport)
@ -120,7 +103,7 @@ class RfxtrxLight(Light):
self.update_ha_state() self.update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
""" Turn the device off. """ """ Turn the light off. """
if hasattr(self, '_event') and self._event: if hasattr(self, '_event') and self._event:
self._event.device.send_off(rfxtrx.RFXOBJECT.transport) self._event.device.send_off(rfxtrx.RFXOBJECT.transport)

View File

@ -1,6 +1,6 @@
""" """
homeassistant.components.rfxtrx homeassistant.components.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connects Home Assistant to a RFXtrx device. Connects Home Assistant to a RFXtrx device.
Configuration: Configuration:
@ -33,7 +33,7 @@ RFXOBJECT = None
def setup(hass, config): def setup(hass, config):
""" Setup the Rfxtrx component. """ """ Setup the RFXtrx component. """
# Declare the Handle event # Declare the Handle event
def handle_receive(event): def handle_receive(event):
@ -76,7 +76,7 @@ def setup(hass, config):
def get_rfx_object(packetid): def get_rfx_object(packetid):
""" return the RFXObject with the packetid""" """ Return the RFXObject with the packetid. """
try: try:
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
except ImportError: except ImportError:

View File

@ -3,21 +3,8 @@ homeassistant.components.sensor.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shows sensor values from RFXtrx sensors. Shows sensor values from RFXtrx sensors.
Configuration: For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.rfxtrx.html
To use the rfxtrx sensors you will need to add something like the following to
your configuration.yaml file.
sensor:
platform: rfxtrx
device: PATH_TO_DEVICE
Variables:
device
*Required
Path to your RFXtrx device.
E.g. /dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0
""" """
import logging import logging
from collections import OrderedDict from collections import OrderedDict
@ -51,7 +38,7 @@ 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', True) automatic_add = config.get('automatic_add', True)
if automatic_add: if automatic_add:
_LOGGER.info("Automatic add %s rfxtrx.light", entity_id) _LOGGER.info("Automatic add %s rfxtrx.sensor", entity_id)
new_sensor = RfxtrxSensor(event) new_sensor = RfxtrxSensor(event)
rfxtrx.RFX_DEVICES[entity_id] = new_sensor rfxtrx.RFX_DEVICES[entity_id] = new_sensor
add_devices_callback([new_sensor]) add_devices_callback([new_sensor])
@ -67,7 +54,6 @@ class RfxtrxSensor(Entity):
def __init__(self, event): def __init__(self, event):
self.event = event self.event = event
self._unit_of_measurement = None self._unit_of_measurement = None
self._data_type = None self._data_type = None
for data_type in DATA_TYPES: for data_type in DATA_TYPES:
@ -86,13 +72,14 @@ class RfxtrxSensor(Entity):
@property @property
def state(self): def state(self):
""" Returns the state of the device. """
if self._data_type: if self._data_type:
return self.event.values[self._data_type] return self.event.values[self._data_type]
return None return None
@property @property
def name(self): def name(self):
""" Get the mame of the sensor. """ """ Get the name of the sensor. """
return self._name return self._name
@property @property

View File

@ -1,26 +1,10 @@
""" """
homeassistant.components.switch.rfxtrx homeassistant.components.switch.rfxtrx
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Rfxtrx switch. Support for RFXtrx switches.
Configuration:
To use Rfxtrx switchs you will need to add the following to your
configuration.yaml file.
switch:
platform: rfxtrx
devices:
ac09c4f1: Bedroom Door
ac09c4f2: Kitchen Door
ac09c4f3: Bathroom Door
*Optional*
# Automatic add new switch
automatic_add: True
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.rfxtrx.html
""" """
import logging import logging
import homeassistant.components.rfxtrx as rfxtrx import homeassistant.components.rfxtrx as rfxtrx
@ -90,7 +74,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class RfxtrxSwitch(SwitchDevice): class RfxtrxSwitch(SwitchDevice):
""" Provides a demo switch. """ """ Provides a RFXtrx switch. """
def __init__(self, name, event, state): def __init__(self, name, event, state):
self._name = name self._name = name
self._event = event self._event = event
@ -98,7 +82,7 @@ class RfxtrxSwitch(SwitchDevice):
@property @property
def should_poll(self): def should_poll(self):
""" No polling needed for a demo switch. """ """ No polling needed for a RFXtrx switch. """
return False return False
@property @property