Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from thomasgermain/release_1_2_2
Browse files Browse the repository at this point in the history
release 1.2.2
  • Loading branch information
thomasgermain authored May 3, 2020
2 parents 7bbebc5 + c250665 commit 85c6348
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ First release using config flow
- adding some none check
### [1.2.1](https://github.com/thomasgermain/vaillant-component/releases/tag/1.2.1)
- warning log fix
### [1.2.2](https://github.com/thomasgermain/vaillant-component/releases/tag/1.2.2)
- Better error handling
- Component does a reconnection every time an error occurs

## Provided entities
- 1 water_heater entity, if any water heater: `water_heater.vaillant_<water heater id>`, basically `water_heater.vaillant_control_dhw`
Expand Down
14 changes: 2 additions & 12 deletions vaillant/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Config flow for vaillant integration."""
import logging

from pymultimatic.api import ApiError
import voluptuous as vol

from homeassistant import config_entries, core, exceptions
Expand Down Expand Up @@ -37,17 +36,8 @@ async def validate_input(hass: core.HomeAssistant, data):
async def validate_authentication(hass, username, password, serial):
"""Ensure provided credentials are working."""
hub: ApiHub = ApiHub(hass, username, password, serial)
try:
if not await hub.authenticate():
raise InvalidAuth
except ApiError as err:
resp = await err.response.json()
_LOGGER.exception(
"Unable to authenticate, API says: %s, status: %s",
resp,
err.response.status,
)
raise InvalidAuth from err
if not await hub.authenticate():
raise InvalidAuth


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand Down
35 changes: 17 additions & 18 deletions vaillant/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def __init__(self, hass, username, password, serial):

async def authenticate(self):
"""Try to authenticate to the API."""
return await self._manager.login(True)
try:
return await self._manager.login(True)
except ApiError as err:
await self._handle_api_error(err)
return False

async def _hvac_update(self, trigger=None) -> None:
"""Request is not on the classic update since it won't fetch data.
Expand All @@ -50,15 +54,8 @@ async def _hvac_update(self, trigger=None) -> None:
_LOGGER.debug("Will request_hvac_update")
await self._manager.request_hvac_update()
except ApiError as err:
resp = await err.response.json()
_LOGGER.warning(
"Unable to fetch data from vaillant API, API says: %s, status: %s",
resp,
err.response.status,
exc_info=True,
)
if err.response.status == 409:
await self.authenticate()
await self._handle_api_error(err)
await self.authenticate()

async def _update_system(self):
"""Fetch vaillant system."""
Expand All @@ -70,14 +67,8 @@ async def _update_system(self):
# update_system can is called by all entities, if it fails for
# one entity, it will certainly fail for others.
# catching exception so the throttling is occurring
resp = await err.response.json()
_LOGGER.exception(
"Unable to fetch data from vaillant API, API says: %s, status: %s",
resp,
err.response.status,
)
if err.response.status == 409:
await self.authenticate()
await self._handle_api_error(err)
await self.authenticate()

async def logout(self):
"""Logout from API."""
Expand All @@ -89,6 +80,14 @@ async def logout(self):
return False
return True

async def _handle_api_error(self, api_err):
resp = await api_err.response.json()
_LOGGER.exception(
"Unable to fetch data from vaillant, API says: %s, status: %s",
resp,
api_err.response.status,
)

def find_component(self, comp):
"""Find a component in the system with the given id, no IO is done."""
from pymultimatic.model import Zone, Room, HotWater, Circulation
Expand Down

0 comments on commit 85c6348

Please sign in to comment.