mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
Add mysensors light platform
* Make light controllable independently with types V_LIGHT, V_DIMMER,
V_RGB and V_RGBW. V_RGBW is not implemented in the frontend yet.
* Add discovery for light platform.
* Add optimistic mode config setting for switch and light
to allow feedback state from actuator.
* Move S_LIGHT, V_LIGHT, V_STATUS types from switch to light platform.
* Change node update logging to debug from info level.
* Fix some inaccurate comments.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""
|
||||
homeassistant.components.mysensors
|
||||
homeassistant.components.mysensors.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
MySensors component that connects to a MySensors gateway via pymysensors
|
||||
API.
|
||||
@@ -25,6 +26,7 @@ CONF_PERSISTENCE = 'persistence'
|
||||
CONF_PERSISTENCE_FILE = 'persistence_file'
|
||||
CONF_VERSION = 'version'
|
||||
CONF_BAUD_RATE = 'baud_rate'
|
||||
CONF_OPTIMISTIC = 'optimistic'
|
||||
DEFAULT_VERSION = '1.4'
|
||||
DEFAULT_BAUD_RATE = 115200
|
||||
|
||||
@@ -40,13 +42,15 @@ ATTR_PORT = 'port'
|
||||
|
||||
GATEWAYS = None
|
||||
|
||||
DISCOVER_SENSORS = "mysensors.sensors"
|
||||
DISCOVER_SWITCHES = "mysensors.switches"
|
||||
DISCOVER_SENSORS = 'mysensors.sensors'
|
||||
DISCOVER_SWITCHES = 'mysensors.switches'
|
||||
DISCOVER_LIGHTS = 'mysensors.lights'
|
||||
|
||||
# Maps discovered services to their platforms
|
||||
DISCOVERY_COMPONENTS = [
|
||||
('sensor', DISCOVER_SENSORS),
|
||||
('switch', DISCOVER_SWITCHES),
|
||||
('light', DISCOVER_LIGHTS),
|
||||
]
|
||||
|
||||
|
||||
@@ -76,7 +80,8 @@ def setup(hass, config):
|
||||
baud=baud_rate)
|
||||
gateway.metric = is_metric
|
||||
gateway.debug = config[DOMAIN].get(CONF_DEBUG, False)
|
||||
gateway = GatewayWrapper(gateway, version)
|
||||
optimistic = config[DOMAIN].get(CONF_OPTIMISTIC, False)
|
||||
gateway = GatewayWrapper(gateway, version, optimistic)
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
gateway.event_callback = gateway.callback_factory()
|
||||
|
||||
@@ -154,12 +159,13 @@ def pf_callback_factory(map_sv_types, devices, add_devices, entity_class):
|
||||
class GatewayWrapper(object):
|
||||
"""Gateway wrapper class, by subclassing serial gateway."""
|
||||
|
||||
def __init__(self, gateway, version):
|
||||
def __init__(self, gateway, version, optimistic):
|
||||
"""Setup class attributes on instantiation.
|
||||
|
||||
Args:
|
||||
gateway (mysensors.SerialGateway): Gateway to wrap.
|
||||
version (str): Version of mysensors API.
|
||||
optimistic (bool): Send values to actuators without feedback state.
|
||||
|
||||
Attributes:
|
||||
_wrapped_gateway (mysensors.SerialGateway): Wrapped gateway.
|
||||
@@ -172,6 +178,7 @@ class GatewayWrapper(object):
|
||||
self.version = version
|
||||
self.platform_callbacks = []
|
||||
self.const = self.get_const()
|
||||
self.optimistic = optimistic
|
||||
self.__initialised = True
|
||||
|
||||
def __getattr__(self, name):
|
||||
@@ -204,7 +211,7 @@ class GatewayWrapper(object):
|
||||
"""Return a new callback function."""
|
||||
def node_update(update_type, node_id):
|
||||
"""Callback for node updates from the MySensors gateway."""
|
||||
_LOGGER.info('update %s: node %s', update_type, node_id)
|
||||
_LOGGER.debug('update %s: node %s', update_type, node_id)
|
||||
for callback in self.platform_callbacks:
|
||||
callback(self, node_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user