Modify import of template and PEP257
This commit is contained in:
1 parent
213cc920d0
commit
582394bc3b
25 files changed
+152
-182
No files matched your search
@@ -1,7 +1,5 @@
|
||||
"""
|
||||
homeassistant.components.light.mqtt
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Allows to configure a MQTT light.
|
||||
Support for MQTT lights.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.mqtt/
|
||||
@@ -12,7 +10,7 @@ from functools import partial
|
||||
import homeassistant.components.mqtt as mqtt
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, Light)
|
||||
from homeassistant.util.template import render_with_possible_json_value
|
||||
from homeassistant.helpers.template import render_with_possible_json_value
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,7 +24,7 @@ DEPENDENCIES = ['mqtt']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
""" Add MQTT Light. """
|
||||
"""Add MQTT Light."""
|
||||
|
||||
if config.get('command_topic') is None:
|
||||
_LOGGER.error("Missing required variable: command_topic")
|
||||
@@ -50,7 +48,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
||||
|
||||
class MqttLight(Light):
|
||||
""" Provides a MQTT light. """
|
||||
"""Provides a MQTT light."""
|
||||
|
||||
# pylint: disable=too-many-arguments,too-many-instance-attributes
|
||||
def __init__(self, hass, name, topic, templates, qos, payload, optimistic):
|
||||
@@ -71,7 +69,7 @@ class MqttLight(Light):
|
||||
for key, tpl in templates.items()}
|
||||
|
||||
def state_received(topic, payload, qos):
|
||||
""" A new MQTT message has been received. """
|
||||
"""A new MQTT message has been received."""
|
||||
payload = templates['state'](payload)
|
||||
if payload == self._payload["on"]:
|
||||
self._state = True
|
||||
@@ -85,7 +83,7 @@ class MqttLight(Light):
|
||||
state_received, self._qos)
|
||||
|
||||
def brightness_received(topic, payload, qos):
|
||||
""" A new MQTT message for the brightness has been received. """
|
||||
"""A new MQTT message for the brightness has been received."""
|
||||
self._brightness = int(templates['brightness'](payload))
|
||||
self.update_ha_state()
|
||||
|
||||
@@ -97,7 +95,7 @@ class MqttLight(Light):
|
||||
self._brightness = None
|
||||
|
||||
def rgb_received(topic, payload, qos):
|
||||
""" A new MQTT message has been received. """
|
||||
"""A new MQTT message has been received."""
|
||||
self._rgb = [int(val) for val in
|
||||
templates['rgb'](payload).split(',')]
|
||||
self.update_ha_state()
|
||||
@@ -111,27 +109,27 @@ class MqttLight(Light):
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
""" Brightness of this light between 0..255. """
|
||||
"""Brightness of this light between 0..255."""
|
||||
return self._brightness
|
||||
|
||||
@property
|
||||
def rgb_color(self):
|
||||
""" RGB color value. """
|
||||
"""RGB color value."""
|
||||
return self._rgb
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling needed for a MQTT light. """
|
||||
"""No polling needed for a MQTT light."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the device if any. """
|
||||
"""Returns the name of the device if any."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if device is on. """
|
||||
"""True if device is on."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
@@ -140,7 +138,7 @@ class MqttLight(Light):
|
||||
return self._optimistic
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turn the device on. """
|
||||
"""Turn the device on."""
|
||||
should_update = False
|
||||
|
||||
if ATTR_RGB_COLOR in kwargs and \
|
||||
@@ -166,7 +164,7 @@ class MqttLight(Light):
|
||||
self._payload["on"], self._qos)
|
||||
|
||||
if self._optimistic:
|
||||
# optimistically assume that switch has changed state
|
||||
# Optimistically assume that switch has changed state.
|
||||
self._state = True
|
||||
should_update = True
|
||||
|
||||
@@ -174,11 +172,11 @@ class MqttLight(Light):
|
||||
self.update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" Turn the device off. """
|
||||
"""Turn the device off."""
|
||||
mqtt.publish(self._hass, self._topic["command_topic"],
|
||||
self._payload["off"], self._qos)
|
||||
|
||||
if self._optimistic:
|
||||
# optimistically assume that switch has changed state
|
||||
# Optimistically assume that switch has changed state.
|
||||
self._state = False
|
||||
self.update_ha_state()
|
||||
Reference in new issue
Block a user