simbaja / gehome

Python SDK for GE smart appliances
MIT License
43 stars 29 forks source link

Client stops communicating with GE appliance after several hours #6

Closed Mr-jreeves closed 3 years ago

Mr-jreeves commented 3 years ago

I hacked up a client to continuously poll for updates ... it runs fine for many hours but then I start getting errors:

/home/pi/ge_poll_laundry-0.3.py:112: DeprecationWarning: The object should be created within an async function
  session = aiohttp.ClientSession()
2021-06-07 08:22:13,168 INFO     Starting GE Appliances client
2021-06-07 08:22:14,063 INFO     Send this DRYER event: ErdCode.LAUNDRY_TIME_REMAINING is  0:37:00
2021-06-07 08:22:14,115 INFO     Send this WASHER event: ErdCode.LAUNDRY_TIME_REMAINING is  0:34:45
2021-06-07 08:22:14,420 INFO     Send this DRYER event: ErdCode.LAUNDRY_CYCLE is  Mixed
2021-06-07 08:22:14,426 INFO     Send this WASHER event: ErdCode.LAUNDRY_CYCLE is  Colors
2021-06-07 08:22:14,473 INFO     Send this DRYER event: ErdCode.LAUNDRY_END_OF_CYCLE is  True
2021-06-07 08:22:14,499 INFO     Send this WASHER event: ErdCode.LAUNDRY_END_OF_CYCLE is  False
2021-06-07 08:22:14,516 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Closed
2021-06-07 08:22:14,535 INFO     Send this WASHER event: ErdCode.LAUNDRY_DOOR is  Open
2021-06-07 08:28:41,937 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Open
2021-06-07 08:34:06,799 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Closed
2021-06-07 08:36:22,180 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Open
2021-06-07 08:41:27,327 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Closed
2021-06-07 08:52:13,270 INFO     Starting GE Appliances client
.
.
.

2021-06-07 09:52:13,089 INFO     Starting GE Appliances client
2021-06-07 10:22:13,440 INFO     Starting GE Appliances client
2021-06-07 10:50:11,927 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Closed
2021-06-07 10:52:13,253 INFO     Starting GE Appliances client
2021-06-07 11:22:13,035 INFO     Starting GE Appliances client
2021-06-07 11:52:13,291 INFO     Starting GE Appliances client
2021-06-07 12:22:13,049 INFO     Starting GE Appliances client
2021-06-07 12:52:13,325 INFO     Starting GE Appliances client
2021-06-07 13:12:15,279 INFO     Tried to send a message, but connection already closed.
2021-06-07 13:12:15,280 INFO     Tried to send a message, but connection already closed.
2021-06-07 13:17:15,310 INFO     Tried to send a message, but connection already closed.
2021-06-07 13:17:15,312 INFO     Tried to send a message, but connection already closed.
2021-06-07 13:22:13,161 INFO     Starting GE Appliances client
2021-06-07 13:31:52,093 INFO     Tried to send a message, but connection already closed.
2021-06-07 13:38:47,695 INFO     Send this WASHER event: ErdCode.LAUNDRY_DOOR is  Closed
2021-06-07 13:39:36,808 INFO     Send this DRYER event: ErdCode.LAUNDRY_DOOR is  Open
2021-06-07 13:52:13,198 INFO     Starting GE Appliances client
2021-06-07 14:14:19,739 ERROR    Unknown error reading socket
2021-06-07 14:14:44,060 ERROR    Unknown error reading socket
2021-06-07 14:22:13,102 INFO     Starting GE Appliances client

Here's the main loop, I'm trying to avoid completely resetting the GeWebsocketClient but perhaps that is the issue? (GE_REFRESH is set to 30 minutes)

if __name__ == "__main__":

    FORMAT = '%(asctime)-15s %(levelname)-8s %(message)s'
    logging.basicConfig(level=logging.INFO, format=FORMAT)
    loop = asyncio.get_event_loop()
    client = GeWebsocketClient(USERNAME, PASSWORD, loop)
    client.add_event_handler(EVENT_APPLIANCE_STATE_CHANGE, log_state_change)
    client.add_event_handler(EVENT_ADD_APPLIANCE, do_periodic_update)

    while(True):
        session = aiohttp.ClientSession()
        asyncio.ensure_future(client.async_get_credentials_and_run(session), loop=loop)
        loop.run_until_complete(asyncio.sleep(GE_REFRESH))

Any ideas would be appreciated.

simbaja commented 3 years ago

Unfortunately, that's a limit of the websocket, it won't run indefinitely. Basically, you'll need to re-open a connection whenever you run into this. Please see the gehome HA component repository for an example of the retry logic I implemented to handle this situation (it's in the update_coordinatory.py file).