Add native Python types support to templates (#41227)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
cbb4324c84
commit
ee914366a8
29 changed files with 349 additions and 282 deletions
|
@ -412,7 +412,7 @@ class LightTemplate(TemplateEntity, LightEntity):
|
|||
self._available = True
|
||||
return
|
||||
|
||||
state = result.lower()
|
||||
state = str(result).lower()
|
||||
if state in _VALID_STATES:
|
||||
self._state = state in ("true", STATE_ON)
|
||||
else:
|
||||
|
@ -451,12 +451,17 @@ class LightTemplate(TemplateEntity, LightEntity):
|
|||
@callback
|
||||
def _update_color(self, render):
|
||||
"""Update the hs_color from the template."""
|
||||
if render in ("None", ""):
|
||||
self._color = None
|
||||
return
|
||||
h_str, s_str = map(
|
||||
float, render.replace("(", "").replace(")", "").split(",", 1)
|
||||
)
|
||||
h_str = s_str = None
|
||||
if isinstance(render, str):
|
||||
if render in ("None", ""):
|
||||
self._color = None
|
||||
return
|
||||
h_str, s_str = map(
|
||||
float, render.replace("(", "").replace(")", "").split(",", 1)
|
||||
)
|
||||
elif isinstance(render, (list, tuple)) and len(render) == 2:
|
||||
h_str, s_str = render
|
||||
|
||||
if (
|
||||
h_str is not None
|
||||
and s_str is not None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue