-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add color_temp_command_template for mqtt light component #5105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
|
@@ -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, | ||
|
|
@@ -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": | ||
| config.get(CONF_COLOR_TEMP_COMMAND_TEMPLATE) | ||
| }, | ||
| config.get(CONF_QOS), | ||
| config.get(CONF_RETAIN), | ||
|
|
@@ -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) | ||
|
|
@@ -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: | ||
|
|
@@ -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"]( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you've already added it to |
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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_commandto go alongside the existing dictionary key ofcolor_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_COMMANDcould be added tohomeassistant/const.py...There was a problem hiding this comment.
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_COMMANDas key here.