Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
gickowtf committed Apr 15, 2024
2 parents c7fc3b3 + 7311f7a commit 46841ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions custom_components/divoom_pixoo/pixoo64/_pixoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ def set_custom_page(self, index):
if data['error_code'] != 0:
self.__error(data)

def play_gif(self, gif_url):
response = requests.post(self.__url, json.dumps({
'Command': 'Device/PlayTFGif',
'FileType': 2,
'FileName': gif_url
}), timeout=self.timeout)
data = response.json()
if data['error_code'] != 0:
self.__error(data)

def set_face(self, face_id):
self.set_clock(face_id)

Expand Down
15 changes: 13 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 @@ -144,13 +144,16 @@ def _render_page(self, page):
pixoo.set_visualizer(page['id'])
elif page_type == "clock":
pixoo.set_clock(page['id'])
elif page_type == "gif":
pixoo.play_gif(page['gif_url'])
elif page_type in ["custom", "components"]:
variables = page.get('variables', {})
rendered_variables = {}
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 +258,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 46841ed

Please sign in to comment.