Danielhiversen / pyTibber

Async Python 3 library for Tibber
GNU General Public License v3.0
96 stars 36 forks source link

over time connection problems does not recover properly #240

Closed wolfc01 closed 1 year ago

wolfc01 commented 1 year ago

Hi Daniel,

I wrote the code below in order to have an async task which should deliver realtime power usage and price_info. Symptom is that over a certain time the tibber connection seems to be "not ok, lost?" and one of the await's never returns rendering the while loop stuxk giving it no chance to disconnect and to beuild up a new connection.

What am i doing wrong? Is there a suggestion to do it better? Note that I checked the queue was read on the other end, such that it cannot be full.

The following observations I found after some further investigation:

Best regards Carl.

async def tibberTask():
    #get actual info from tibber and insert this data each second in the command queue
    access_token = "removed as of privacy"
    while True:
        try:
            g_logger.debug("Start tibber login")
            tibber_connection = tibber.Tibber(access_token, user_agent="evcharger")
            await tibber_connection.update_info()
            home = tibber_connection.get_homes(only_active=False)[0]
            await home.update_info()   
            g_logger.debug(f"Tibber account:{tibber_connection.name}")
            g_logger.debug(f"Tibber address:{home.address1}")
            await home.rt_subscribe(_callback)
            while True:
                await home.update_price_info()
                await G_commandQueue.put((Command.ACTUAL_PRICE.value, home.current_price_info['total']))
                await asyncio.sleep(60)    
        except:
            try:
                await tibber_connection.rt_disconnect()
                await tibber_connection.close_connection()
            except:
                pass
            s = traceback.format_exc()
            g_logger.debug(f"handled exception: {s}, waiting for 60 seconds, then retry")
            await asyncio.sleep(60)
Danielhiversen commented 1 year ago

Could you try to update to 0.26.7 ?

wolfc01 commented 1 year ago

Hi Daniel,

I will, but it will take some time, please allow me to find time for a duration test. But I have to wait until the breaking change in the tibber API has been implemented in your library.

Br Carl

wolfc01 commented 1 year ago

Hi Daniel,

question: is the breaking change in the websocket api already supported in your code?, if so, since which version?

br Carl.

sjobergpo commented 1 year ago

Hi, what is the current status of this package, is it confirmed working with the new api at Tibber? Using the example code provide in md, no realtime data is returned using dummy user key.