thomasgermain / pymultiMATIC

Python interface with Vaillant multiMATIC
MIT License
56 stars 11 forks source link

Error capture documentation #89

Closed cambronf closed 1 year ago

cambronf commented 2 years ago

Regarding the Wiki comment: "In case of error coming from the API, a pymultimtic.api.Error is raised, containing the response and the payload sent to the API."

Is the correct usage of try/except as follows?

async def vaillant_daytemp(user, passw, zone, temp): ....async with aiohttp.ClientSession() as session: ........try: ............manager = SystemManager(user, passw, session) ............system = await manager.set_zone_heating_setpoint_temperature(zone, temp) ........except pymultimatic.api.ApiError as err: ............logger.error(err)

and in main program:

Control Heatpump

try: ....event_loop = asyncio.get_event_loop() except RuntimeError: ....event_loop = asyncio.new_event_loop() ....asyncio.set_event_loop(event_loop)

event_loop.run_until_complete(vaillant_daytemp(vaillantUsername, vaillantPassword, "Control_ZO2", 20.5))

event_loop.close()

So instead of pymultimtic.api.Error => pymultimatic.api.ApiError

My main goal is to catch and handle all Vaillant issues, as their service is far from stable & reliable.

thomasgermain commented 1 year ago

Hello,

Sorry for the late reply.

So yes, this is the correct usage:

async def vaillant_daytemp(user, passw, zone, temp):
....async with aiohttp.ClientSession() as session:
........try:
............manager = SystemManager(user, passw, session)
............system = await manager.set_zone_heating_setpoint_temperature(zone, temp)
........except pymultimatic.api.ApiError as err:
............logger.error(err)