You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been struggling with pyscript code for a while now. I have a script that takes in the name of a jpeg file and then calls some compiled python code to overwrite a theme with this name (hopefully to replace the lovelace background).
The current code is below:
`import fileinput
import sys
import os
import time
from contextlib import chdir
Logger: custom_components.pyscript.file.edit_myhouse_theme.changefilepyscript
Source: custom_components/pyscript/eval.py:510
integration: Pyscript Python scripting (documentation, issues)
First occurred: 10:45:20 (1 occurrences)
Last logged: 10:45:20
Exception in <file.edit_myhouse_theme.changefilepyscript> line 21: contents, exception = task.executor(changetheme, currentbackground) ^ TypeError: cannot unpack non-iterable object`
I am struggling to understand this error. Note: I did attempt to use Jupyter but my laptop browser has consistently failed to attach to the hass pyscript kernel so I am stuck with manual debugging in Home Assistant.
Also, apologies for how the formatted code looks. This discussion template doesn't seem to format as expected and whatever I do, it seems to be applying its own formatting
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have been struggling with pyscript code for a while now. I have a script that takes in the name of a jpeg file and then calls some compiled python code to overwrite a theme with this name (hopefully to replace the lovelace background).
The current code is below:
`import fileinput
import sys
import os
import time
from contextlib import chdir
@service
def changefilepyscript(currentbackground):
contents, exception = task.executor(changetheme, currentbackground)
if exception:
raise exception
log.info(f"contents = {contents}")
@pyscript_compile
def changetheme(file_selected):
path = '/config/themes/myhouse'
yamlfile = 'myhouse.yaml'
with chdir(path):
with open(yamlfile) as file:
data = file.readlines()
data[13] = f' lovelace-background: "center / cover no-repeat url('local/images/backgrounds/{ file_selected }')"\n'
with open(yamlfile, 'w') as file:
file.writelines(data)`
For the time being, I have commented out the actual overwrite until I am sure the rest of the code works.
I have run it with the following action:
action: pyscript.changefilepyscript data: currentbackground: housedayverycloudy.jpg
Currently, the error I am getting is:
`This error originated from a custom integration.
Logger: custom_components.pyscript.file.edit_myhouse_theme.changefilepyscript
Source: custom_components/pyscript/eval.py:510
integration: Pyscript Python scripting (documentation, issues)
First occurred: 10:45:20 (1 occurrences)
Last logged: 10:45:20
Exception in <file.edit_myhouse_theme.changefilepyscript> line 21: contents, exception = task.executor(changetheme, currentbackground) ^ TypeError: cannot unpack non-iterable object`
I am struggling to understand this error. Note: I did attempt to use Jupyter but my laptop browser has consistently failed to attach to the hass pyscript kernel so I am stuck with manual debugging in Home Assistant.
Also, apologies for how the formatted code looks. This discussion template doesn't seem to format as expected and whatever I do, it seems to be applying its own formatting
Beta Was this translation helpful? Give feedback.
All reactions