Feedback from pyscript's script

Hi all,
is there a way to get feedback from execution of pyscript’s script?
Let me explain. I created a custom pyscript that do some stuff. Results are logged by a “print()” in the script.
I registered my function as a @service, so i can call it by button in lovelace.
Everything it’s working.
I was wondering if i can have a feedback of script’s results on button (ex change state based on script response, or something similar).

Regards

You can access state variables and call services:

https://hacs-pyscript.readthedocs.io/en/latest/reference.html#state-variables

If that’s not clear, post your script and explain what entity you’d like to change.

Not sure if print() does anything…
You can use the logger. eg.
log.info(f"My messages myVar={myVar}")
When you open a terminal and tail config/home-assistant.log, you see the messages coming in realtime
When you install jupyter you can call your functions interactively from there and see the traces come in realtime too

Here my code. A would like to use output of print as trigger to tell HA to do something like change color of pressed button, or pop up a window telling you all message are read.

from telethon.sync import TelegramClient
from dotenv import dotenv_values
from telethon.sessions import StringSession


# Variabili
api_id=“xxxxxxxx”
api_hash=“xxxxxx”
session_token=“xxxxxxx”



@service
async def telegram_mark_msg_as_read():
    async with TelegramClient(StringSession(session_token), api_id, api_hash) as client:
        dialogs = await client.get_dialogs()
        
        for dialog in dialogs:
            try:
                await client.send_read_acknowledge(dialog.entity.id)
                print(f"Marked as read: {dialog.name}")
            except Exception as e:
                print(f"Error marking as read in {dialog.name}: {e}")
    
        await client.disconnect()
        print("Client disconnected")