samsinnamon / airtouch4pyapi

An api allowing control of AC state (temperature, on/off, mode) of an Airtouch 4 controller locally over TCP
MIT License
27 stars 14 forks source link

Intermittent failures when querying AT5 #19

Open majurgens opened 1 year ago

majurgens commented 1 year ago

Since I just got my AT5 system I have started to develop against it and hence why I am raising a few issues ..... :)

Intermittently, I get failures for querying the AT5 system (asking it to give me its status)

eg

Traceback (most recent call last):
  File "/opt/hvac/airtouch4pyapi/control.py", line 69, in <module>
    main()
  File "/opt/hvac/airtouch4pyapi/control.py", line 65, in main
    asyncio.run(getInfo(args.address))
  File "/usr/lib64/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/opt/hvac/airtouch4pyapi/control.py", line 33, in getInfo
    await at.UpdateInfo()
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 132, in UpdateInfo
    await self.UpdateGroupNames()
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 181, in UpdateGroupNames
    await self.SendMessageToAirtouch(nameMessage)
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 409, in SendMessageToAirtouch
    return self.TranslatePacketToMessage(dataResult)
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 449, in TranslatePacketToMessage
    self.DecodeAirtouch5GroupNames(dataResult[17::]);
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 603, in DecodeAirtouch5GroupNames
    groups[zoneNumber].GroupName = zoneName
KeyError: 0

and then about 2 seconds later it works perfectly fine. I have seen other slightly different Tracebacks complaining about different things. Anyone else seen this? Can we perhaps add some retry logic into the code?

FYI: You will see control.py in the Traceback, this is just a simple script, copied from demo.py, which is doing a simple query like:

    at = AirTouch(address)
    await at.UpdateInfo()
    if(at.Status != AirTouchStatus.OK):
        print("Got an error updating info.  Exiting")
        return
    acs = at.GetAcs()
    groups = at.GetGroups()
majurgens commented 1 year ago

Here is another one I got

Traceback (most recent call last):
  File "/opt/hvac/airtouch4pyapi/control.py", line 158, in <module>
    main()
  File "/opt/hvac/airtouch4pyapi/control.py", line 151, in main
    asyncio.run(getInfo(args))
  File "/usr/lib64/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib64/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/opt/hvac/airtouch4pyapi/control.py", line 58, in getInfo
    print_all_json(groups,acs)
  File "/opt/hvac/airtouch4pyapi/control.py", line 33, in print_all_json
    ac_dicts = [ac.to_dict() for ac in acs]
  File "/opt/hvac/airtouch4pyapi/control.py", line 33, in <listcomp>
    ac_dicts = [ac.to_dict() for ac in acs]
  File "/opt/hvac/airtouch4pyapi/airtouch4pyapi/airtouch.py", line 78, in to_dict
    'PowerState': self.PowerState,
AttributeError: 'AirTouchAc' object has no attribute 'PowerState'
cemilbrowne commented 1 year ago

Cool - I’ll see what I can do. Writing the homebridge plugin definitely gave me some tips on how to make this more robust. I’ll take another pass through it.