Skip to content

Add color_temp_command_template for mqtt light component#5105

Closed
jonfink wants to merge 4 commits into
home-assistant:devfrom
jonfink:mqtt_light_color_temp
Closed

Add color_temp_command_template for mqtt light component#5105
jonfink wants to merge 4 commits into
home-assistant:devfrom
jonfink:mqtt_light_color_temp

Conversation

@jonfink
Copy link
Copy Markdown

@jonfink jonfink commented Dec 29, 2016

Description:

Home assistant internal unit for color temperature is Mired but some
systems (e.g., SmartThings through mqtt bridge) use Kelvin. Conversion
between these types can be handled with the value template
concept (used previously to unpack json values).

Added a "color_temp_command_template" configuration option for MQTT
lights that specifies a function to be applied to the HA-internal
color temperature value to get a light-compatible value.

Related issue (if applicable):

n/a

Pull request in home-assistant.github.io with documentation (if applicable):

home-assistant/home-assistant.io#1673

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:
n/a code interacts with mqtt devices

@mention-bot
Copy link
Copy Markdown

@jonfink, thanks for your PR! By analyzing the history of the files in this pull request, we identified @robbiet480, @pvizeli and @fabaff to be potential reviewers.

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (107 > 79 characters)

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (111 > 79 characters)

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (102 > 79 characters)

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (84 > 79 characters)

Comment thread homeassistant/components/light/mqtt.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SyntaxError: invalid syntax

Comment thread homeassistant/components/light/mqtt.py Outdated
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.

Comment thread homeassistant/components/light/mqtt.py Outdated
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.

please change this back.

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.

Done in 66012e9

Comment thread homeassistant/components/light/mqtt.py Outdated
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.

please change this back.

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.

Done in 66012e9

@balloob balloob self-assigned this Jan 8, 2017
@jjensn
Copy link
Copy Markdown
Contributor

jjensn commented Jan 12, 2017

What needs to be done here to get this approved? @jonfink how can I help?

Home assistant internal unit for color temperature is Mired but some
systems (e.g., SmartThings through mqtt bridge) use Kelvin. Conversion
between these types can be handled with the value template
concept (used previously to unpack json values).

Added a "color_temp_command_template" configuration option for MQTT
lights that specifies a function to be applied to the HA-internal
color temperature value to get a light-compatible value.
@jonfink jonfink force-pushed the mqtt_light_color_temp branch from 66012e9 to 8b88d77 Compare January 13, 2017 18:56
@jonfink
Copy link
Copy Markdown
Author

jonfink commented Jan 13, 2017

I think I've addressed all of the above comments with the exception of the dictionary keys used to instantiate the MqttLight class template argument. I'm not entirely sure on the rationale in general for these keys coming from homeassistant.const since they are entirely internal to the mqtt light component, but if that part is important it would be a relatively small change to add an additional value to the const module.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

See comments. There was a unit test failing also. Fix that and add test(s) for the new functionality.

Comment thread homeassistant/components/light/mqtt.py Outdated
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.

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.

@jjensn
Copy link
Copy Markdown
Contributor

jjensn commented Jan 20, 2017

How do the collaborators feel about this approach vs using a configuration option and doing the conversion from mired to kelvin there?

I ask because, someone (me) is going to want to add RGB templating next, and you can't quite do RGB -> hue/sat very well in a template (as far as I know, the math would be too complex).

So why not just add two more variables, color_temp_mode (similar to flux component: https://home-assistant.io/components/switch.flux/), and color_mode (rgb vs xy vs hue/sat) ?

I think really, the only reason @jonfink is adding the support for this, is so we can convert HA's default color_temp (mired) to kelvin. I can't see any other use for templating out the command other than that conversion.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 24, 2017

@jjensn I like that approach 👍

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @jonfink,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@andrey-git
Copy link
Copy Markdown
Contributor

@jonfink any updates on this?

@balloob
Copy link
Copy Markdown
Member

balloob commented Feb 12, 2017

This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it.

@balloob balloob closed this Feb 12, 2017
@raccettura
Copy link
Copy Markdown
Contributor

Any chance on resurrecting this? Would be handy to control osram bulbs via HA->ST.

@home-assistant home-assistant locked and limited conversation to collaborators Jul 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants