gazoodle / geckolib

Library to interface with Gecko Alliance spa pack systems via in.touch2 module
GNU General Public License v3.0
62 stars 24 forks source link

Need help getting reminders #38

Closed rrov1 closed 1 year ago

rrov1 commented 1 year ago

Hello!

I need help with a script to read the reminders. I always get 0 reminders (for both spa controllers I have in my network) :-(. The script I use is very simple and straightforward, based on the asynchronous example. I append it here. It takes only one parameter, the guid, looks for all spa controllers on the network, connects to them and then retrieves the reminders. I currently use geckolib 0.4.8, with 0.4.7 I have the problem. Everything else works fine.

Am I doing something wrong?

import sys
import asyncio
import logging
import requests
import urllib

from geckolib import GeckoAsyncSpaMan, GeckoSpaEvent  # type: ignore
from geckolib.driver.protocol.reminders import GeckoReminderType

# Anzahl Argumente prüfen
if len(sys.argv) != 2:
    print("*** Wrong number of script arguments.\n")
    print(f"*** call example: {sys.argv[0]} clientId")
    quit(-1)

print("total arguments passed:", len(sys.argv))
CLIENT_ID = sys.argv[1]
print(f"Connect using client id: {CLIENT_ID}")

class SampleSpaMan(GeckoAsyncSpaMan):
    async def handle_event(self, event: GeckoSpaEvent, **kwargs) -> None:
        # Uncomment this line to see events generated
        print(f"{event}: {kwargs}")
        pass

async def main() -> None:

    async with SampleSpaMan(CLIENT_ID, spa_address=None) as spaman:
        print("*** looking for spas on your network ...")

        # Wait for descriptors to be available
        await spaman.wait_for_descriptors()

        if len(spaman.spa_descriptors) == 0:
            print("*** there were no spas found on your network.")
            return

        # get all spa names
        allNames = []
        for descriptor in spaman.spa_descriptors:
            allNames.append(descriptor.name)

        mySpaDescriptors = []
        # sort spa names and create a new spa descriptors array sorted by spa_name
        for myName in sorted(allNames):
            for descriptor in spaman.spa_descriptors:
                if descriptor.name == myName:
                    mySpaDescriptors.append(descriptor)

        for nSpaNum in range(len(mySpaDescriptors)):
            spa_descriptor = mySpaDescriptors[nSpaNum]
            print(f"connecting to {spa_descriptor.name} at {spa_descriptor.ipaddress} with {spa_descriptor.identifier_as_string}")

            await spaman.async_set_spa_info(
                spa_descriptor.ipaddress,
                spa_descriptor.identifier_as_string,
                spa_descriptor.name,
            )

            # Wait for the facade to be ready
            await spaman.wait_for_facade()

            print(f"spa_state {spaman.spa_state}")

            rm = spaman.facade.reminders_manager
            print(f"anzahl reminders: {len(rm.reminders)}")
            for reminder in rm.reminders:
                print(f"reminder: {reminder}")

            print(f"error sensor state {spaman.facade.error_sensor.state}")

            await asyncio.sleep(1)

        # ende
        print("*** end")
        return

if __name__ == "__main__":
    # Install logging
    stream_logger = logging.StreamHandler()
    stream_logger.setLevel(logging.DEBUG)
    stream_logger.setFormatter(
        logging.Formatter("%(asctime)s> %(levelname)s %(message)s")
    )
    logging.getLogger().addHandler(stream_logger)
    logging.getLogger().setLevel(logging.INFO)

    asyncio.run(main())

rrov1

rrov1 commented 1 year ago

I found a workaround. When I wait for 5 seconds at line 68, reminder values are available:

            rm = spaman.facade.reminders_manager
            print(f"anzahl reminders: {len(rm.reminders)}")
            # fixe Wartezeit, ansonsten sind keine Werte verfügbar
            await asyncio.sleep(5)
            print(f"anzahl reminders: {len(rm.reminders)}")

I don't know why, but it works with this.