Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions homeassistant/components/light/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
CONF_COLOR_TEMP_STATE_TOPIC = 'color_temp_state_topic'
CONF_COLOR_TEMP_COMMAND_TOPIC = 'color_temp_command_topic'
CONF_COLOR_TEMP_VALUE_TEMPLATE = 'color_temp_value_template'
CONF_COLOR_TEMP_COMMAND_TEMPLATE = 'color_temp_command_template'

CONF_COLOR_TEMP_COMMAND = 'color_temp_command'

DEFAULT_NAME = 'MQTT Light'
DEFAULT_PAYLOAD_ON = 'ON'
Expand All @@ -51,6 +54,7 @@
vol.Optional(CONF_COLOR_TEMP_STATE_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_COLOR_TEMP_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(CONF_COLOR_TEMP_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_COLOR_TEMP_COMMAND_TEMPLATE): cv.template,
vol.Optional(CONF_RGB_STATE_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_RGB_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(CONF_RGB_VALUE_TEMPLATE): cv.template,
Expand Down Expand Up @@ -85,7 +89,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
CONF_STATE: config.get(CONF_STATE_VALUE_TEMPLATE),
CONF_BRIGHTNESS: config.get(CONF_BRIGHTNESS_VALUE_TEMPLATE),
CONF_RGB: config.get(CONF_RGB_VALUE_TEMPLATE),
CONF_COLOR_TEMP: config.get(CONF_COLOR_TEMP_VALUE_TEMPLATE)
CONF_COLOR_TEMP: config.get(CONF_COLOR_TEMP_VALUE_TEMPLATE),
CONF_COLOR_TEMP+"_COMMAND":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will become color_temp_command_COMMAND ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dictionary key will be color_temp_command to go alongside the existing dictionary key of color_temp.

Honestly, I wasn't sure how best to handle this as it seemed more far-reaching than desired to make a change in the mqtt light component that required an addition to the homeassistant.const module. If that is the standard practice, then CONF_COLOR_TEMP_COMMAND could be added to homeassistant/const.py...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use CONF_COLOR_TEMP_COMMAND as key here.

config.get(CONF_COLOR_TEMP_COMMAND_TEMPLATE)
},
config.get(CONF_QOS),
config.get(CONF_RETAIN),
Expand Down Expand Up @@ -136,6 +142,8 @@ def __init__(self, hass, name, topic, templates, qos, retain, payload,
tpl.hass = hass
templates[key] = tpl.render_with_possible_json_value

self.templates = templates

def state_received(topic, payload, qos):
"""A new MQTT message has been received."""
payload = templates[CONF_STATE](payload)
Expand Down Expand Up @@ -184,7 +192,10 @@ def rgb_received(topic, payload, qos):

def color_temp_received(topic, payload, qos):
"""A new MQTT message for color temp has been received."""
self._color_temp = int(templates[CONF_COLOR_TEMP](payload))
self._color_temp = \
int(float((templates[CONF_COLOR_TEMP](payload))))
_LOGGER.debug("Received color temp: %f, converts to %d",
float(payload), self._color_temp)
self.update_ha_state()

if self._topic[CONF_COLOR_TEMP_STATE_TOPIC] is not None:
Expand Down Expand Up @@ -266,7 +277,11 @@ def turn_on(self, **kwargs):

if ATTR_COLOR_TEMP in kwargs and \
self._topic[CONF_COLOR_TEMP_COMMAND_TOPIC] is not None:
color_temp = int(kwargs[ATTR_COLOR_TEMP])
color_temp = int(float((
self.templates[CONF_COLOR_TEMP+"_COMMAND"](
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CONF_COLOR_TEMP_COMMAND as key here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MartinHjelmare -- doesn't CONF_COLOR_TEMP_COMMAND have to be added to https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/const.py ? Is that the change you are calling for?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you've already added it to homeassistant/components/light/mqtt.py which is fine. Constants that are only used in one module don't need to be in const.py. Just use the constant now in the two places where it's needed.

str(kwargs[ATTR_COLOR_TEMP])))))
_LOGGER.debug("Command temp %f mired, coverts to %d K",
kwargs[ATTR_COLOR_TEMP], color_temp)
mqtt.publish(
self._hass, self._topic[CONF_COLOR_TEMP_COMMAND_TOPIC],
color_temp, self._qos, self._retain)
Expand Down