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'm asking if anyone can help me get a Python script that runs from the command line into a service that can run under pyscript? The script is a Telnet client to wake up my Tivo box.
I've added the @service to the main() method, and I'm not seeing pyscript.main in the developer tools as a runnable script, most likely because of a missing dependency (telnetlib3).
My script uses the telnetlib3, asyncio, and time libraries. I'm not really sure how to install telnetlib3 into HA. Does it allow something like below in the shell?
pip install telnetlib3
This error originated from a custom integration.
Logger: custom_components.pyscript.file.TivoCommandClient
Source: custom_components/pyscript/global_ctx.py:341
Integration: Pyscript Python scripting (documentation, issues)
First occurred: 11:22:53 PM (1 occurrences)
Last logged: 11:22:53 PM
Exception in </config/pyscript/TivoCommandClient.py> line 2: import telnetlib3 ^ ModuleNotFoundError: No module named 'telnetlib3'
Also, I'm not sure my script will run as is. Here is the code:
import asyncio
import telnetlib3
import time
async def shell(reader, writer):
rules = [
('COMMAND_TIMEOUT', 'IRCODE LIVETV'),
]
ruleiter = iter(rules)
expect, send = next(ruleiter)
writer.write('IRCODE TIVO')
writer.write('\r\n')
time.sleep(10) # Makes Python wait for 10 seconds
while True:
outp = await reader.read(1024)
print(outp, flush=True)
if not outp:
break
if expect in outp:
writer.write(send)
writer.write('\r\n')
try:
expect, send = next(ruleiter)
except StopIteration:
break
# display all server output
print(outp, flush=True)
# EOF
print()
@service
async def main():
reader, writer = await telnetlib3.open_connection('192.168.186.191', 31339, shell=shell)
await writer.protocol.waiter_closed
if __name__ == '__main__':
asyncio.run(main())
The text was updated successfully, but these errors were encountered:
royf007
changed the title
Newbie Help with Running Python Script to Run under pyscript as a Service
Newbie help running Python script under pyscript as a service
Feb 29, 2024
I'm asking if anyone can help me get a Python script that runs from the command line into a service that can run under pyscript? The script is a Telnet client to wake up my Tivo box.
I've added the @service to the main() method, and I'm not seeing pyscript.main in the developer tools as a runnable script, most likely because of a missing dependency (telnetlib3).
My configuration.yaml:
My script uses the telnetlib3, asyncio, and time libraries. I'm not really sure how to install telnetlib3 into HA. Does it allow something like below in the shell?
pip install telnetlib3
Exception in </config/pyscript/TivoCommandClient.py> line 2: import telnetlib3 ^ ModuleNotFoundError: No module named 'telnetlib3'
Also, I'm not sure my script will run as is. Here is the code:
The text was updated successfully, but these errors were encountered: