Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 9 additions & 1 deletion homeassistant/components/template/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def update_brightness(self):
return
try:
brightness = self._level_template.async_render()
if brightness in ("None", ""):
self._brightness = None
return
if 0 <= int(brightness) <= 255:
Comment thread
alistairg marked this conversation as resolved.
self._brightness = int(brightness)
else:
Expand Down Expand Up @@ -415,7 +418,10 @@ def update_temperature(self):
if self._temperature_template is None:
return
try:
temperature = int(self._temperature_template.async_render())
render = self._temperature_template.async_render()
if render in ("None", ""):
return
Comment thread
alistairg marked this conversation as resolved.
temperature = int(render)
Comment thread
alistairg marked this conversation as resolved.
if self.min_mireds <= temperature <= self.max_mireds:
self._temperature = temperature
else:
Expand All @@ -439,6 +445,8 @@ def update_color(self):

try:
render = self._color_template.async_render()
if render in ("None", ""):
return
Comment thread
alistairg marked this conversation as resolved.
h_str, s_str = map(
float, render.replace("(", "").replace(")", "").split(",", 1)
)
Expand Down
19 changes: 17 additions & 2 deletions tests/components/template/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,13 @@ def test_level_action_no_template(self):

@pytest.mark.parametrize(
"expected_level,template",
[(255, "{{255}}"), (None, "{{256}}"), (None, "{{x - 12}}")],
[
(255, "{{255}}"),
(None, "{{256}}"),
(None, "{{x - 12}}"),
(None, "{{ none }}"),
(None, ""),
],
)
def test_level_template(self, expected_level, template):
"""Test the template for the level."""
Expand Down Expand Up @@ -588,7 +594,14 @@ def test_level_template(self, expected_level, template):

@pytest.mark.parametrize(
"expected_temp,template",
[(500, "{{500}}"), (None, "{{501}}"), (None, "{{x - 12}}")],
[
(500, "{{500}}"),
(None, "{{501}}"),
(None, "{{x - 12}}"),
(None, "None"),
(None, "{{ none }}"),
(None, ""),
],
)
def test_temperature_template(self, expected_temp, template):
"""Test the template for the temperature."""
Expand Down Expand Up @@ -894,6 +907,8 @@ def test_color_action_no_template(self):
(None, "{{(361, 100)}}"),
(None, "{{(360, 101)}}"),
(None, "{{x - 12}}"),
(None, ""),
(None, "{{ none }}"),
],
)
def test_color_template(self, expected_hs, template):
Expand Down