Replies: 1 comment
-
I think that you need to read some documentation again. In this section https://hacs-pyscript.readthedocs.io/en/stable/reference.html#avoiding-event-loop-i-o you can read something like "The func argument can only be a regular Python function, not a function defined in pyscript." At this point you call a function defined in pyscript. There are. This is also imported: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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