Skip to content

Commit

Permalink
Merge pull request #67 from Mrredstone5230/feat/templatable-component
Browse files Browse the repository at this point in the history
[Feature] Added the templatable component
  • Loading branch information
gickowtf authored Apr 15, 2024
2 parents c149229 + 07d40cc commit 05129b8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions custom_components/divoom_pixoo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def _async_next_page(self):
self._current_page_index = (self._current_page_index + 1) % len(self._pages)
iteration_count += 1

def _render_page(self, page):
def _render_page(self, page: dict):
pixoo = self._pixoo
pixoo.clear()

Expand All @@ -150,7 +150,8 @@ def _render_page(self, page):
for var_name in variables:
rendered_variables[var_name] = Template(str(variables[var_name]), self.hass).async_render()

for component in page['components']:
components: list = page['components'].copy() # Copy the list so we can add new items to it.
for index, component in enumerate(components):

if component['type'] == "text":
try:
Expand Down Expand Up @@ -255,6 +256,14 @@ def _render_page(self, page):

except TemplateError as e:
_LOGGER.error("Template render error: %s", e)
elif component["type"] == "templatable":
try:
rendered_list = list(Template(str(component.get("template", [])), self.hass).async_render(variables=rendered_variables))
for item in rendered_list[::-1]: # Reverse the list so that the order is correct.
components.insert(index + 1, item)

except TemplateError as e:
_LOGGER.error("Template render error: %s", e)

pixoo.push()

Expand Down

0 comments on commit 05129b8

Please sign in to comment.