Add color to light template#28141
Conversation
|
Hey there @PhracturedBlue, mind taking a look at this pull request as its been labeled with a integration ( |
6db5ee9 to
01c6d03
Compare
01c6d03 to
423e503
Compare
|
Checks failed because of black. When I run on it on my machine, everything is fine. |
|
@tetienne Please rebase your PR onto the latest dev, that should fix the issue. https://developers.home-assistant.io/docs/en/development_catching_up.html |
d77421e to
80e7684
Compare
|
Documentation added. |
d10770b to
887dbf3
Compare
|
Hi, this PR is ready for review. |
|
@frenck Doc is not anymore missing. |
|
@MartinHjelmare Hi, can someone review my PR please? |
|
When someone has time, someone will review this PR. |
44e0e5d to
009de07
Compare
|
@PhracturedBlue @grillp What do you think about my enhancements? |
009de07 to
f0d2cfe
Compare
|
@balloob @MartinHjelmare @frenck I'm really sorry to ping you again, but it become really difficult to maintain and rebase my PR. Can someone have a look please? |
f0d2cfe to
7fac622
Compare
|
|
||
| return 0 | ||
| supported_features |= SUPPORT_BRIGHTNESS | ||
| if self._temperature_script is not None: |
There was a problem hiding this comment.
Interesting that this is based off the existence of a script, not on a value template ?
There was a problem hiding this comment.
Indeed, I just follow the existing solution. But IMO it seems logic: you need an action to be able to change the brightness/color/temperature.
| ) | ||
| elif ATTR_HS_COLOR in kwargs and self._color_script: | ||
| hs_value = kwargs[ATTR_HS_COLOR] | ||
| await self._color_script.async_run( |
There was a problem hiding this comment.
Why are all these different scripts? Since it is all done inside the async_turn_on method, shouldn't there just be a generic turn_on script ?
There was a problem hiding this comment.
All these scripts map the actions to call when the brightness/color/temperature is updated. See https://www.home-assistant.io/integrations/light.template
| _LOGGER.error(ex) | ||
| self._state = None | ||
| """Update from templates.""" | ||
| await self.update_state() |
There was a problem hiding this comment.
Instead of making these awaitable, you can mark them as @callback which means you don't need to yield.
There was a problem hiding this comment.
So, I can make update_state() not async also?
@callback
def update_state(self):
"""Update the state from the template."""
if self._template is not None:
...
``
There was a problem hiding this comment.
I don't get the magic behind, but indeed it works well. Thx.
|
@balloob I've fixed your remarks. |
|
@balloob Can you pleare continue the review of my PR? |
|
I will split this PR in smaller ones. First one: #30455 |
| try: | ||
| render = self._color_template.async_render() | ||
| h_str, s_str = map( | ||
| int, render.replace("(", "").replace(")", "").split(",", 1) |
There was a problem hiding this comment.
Oh I didn't know. I will change this.
|
2nd PR: #30595 |
|
3rd PR: #31435 |

Description:
Currently light template only support brightness. This PR adds colour and temperature support.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11108
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: