Skip to content

Commit

Permalink
Improve handling of errors when Somfy server is in maintenance. (#306)
Browse files Browse the repository at this point in the history
Co-authored-by: Thibaut Etienne <[email protected]>
  • Loading branch information
iMicknl and tetienne authored Oct 27, 2020
1 parent 48bef61 commit 1be9c7e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 6 deletions.
9 changes: 8 additions & 1 deletion custom_components/tahoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client, config_validation as cv
from pyhoma.client import TahomaClient
from pyhoma.exceptions import BadCredentialsException, TooManyRequestsException
from pyhoma.exceptions import (
BadCredentialsException,
MaintenanceException,
TooManyRequestsException,
)
from pyhoma.models import Command
import voluptuous as vol

Expand Down Expand Up @@ -95,6 +99,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
except (TimeoutError, ClientError, ServerDisconnectedError) as exception:
_LOGGER.error("cannot_connect")
raise ConfigEntryNotReady from exception
except MaintenanceException as exception:
_LOGGER.error("server_in_maintenance")
raise ConfigEntryNotReady from exception
except Exception as exception: # pylint: disable=broad-except
_LOGGER.exception(exception)
return False
Expand Down
11 changes: 10 additions & 1 deletion custom_components/tahoma/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
from pyhoma.client import TahomaClient
from pyhoma.exceptions import BadCredentialsException, TooManyRequestsException
from pyhoma.exceptions import (
BadCredentialsException,
MaintenanceException,
TooManyRequestsException,
)
import voluptuous as vol

from .const import CONF_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL, MIN_UPDATE_INTERVAL
Expand Down Expand Up @@ -57,6 +61,8 @@ async def async_step_user(self, user_input=None):
errors["base"] = "invalid_auth"
except (TimeoutError, ClientError):
errors["base"] = "cannot_connect"
except MaintenanceException:
errors["base"] = "server_in_maintenance"
except Exception as exception: # pylint: disable=broad-except
errors["base"] = "unknown"
_LOGGER.exception(exception)
Expand All @@ -81,6 +87,9 @@ async def async_step_import(self, import_config: dict):
except (TimeoutError, ClientError):
_LOGGER.error("cannot_connect")
return self.async_abort(reason="cannot_connect")
except MaintenanceException:
_LOGGER.error("server_in_maintenance")
return self.async_abort(reason="server_in_maintenance")
except Exception as exception: # pylint: disable=broad-except
_LOGGER.exception(exception)
return self.async_abort(reason="unknown")
Expand Down
3 changes: 3 additions & 0 deletions custom_components/tahoma/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pyhoma.enums import EventName, ExecutionState
from pyhoma.exceptions import (
BadCredentialsException,
MaintenanceException,
NotAuthenticatedException,
TooManyRequestsException,
)
Expand Down Expand Up @@ -67,6 +68,8 @@ async def _async_update_data(self) -> Dict[str, Device]:
raise UpdateFailed("invalid_auth") from exception
except TooManyRequestsException as exception:
raise UpdateFailed("too_many_requests") from exception
except MaintenanceException as exception:
raise UpdateFailed("server_in_maintenance") from exception
except (ServerDisconnectedError, NotAuthenticatedException) as exception:
_LOGGER.debug(exception)
self.executions = {}
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tahoma/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/tahoma",
"requirements": [
"pyhoma==0.5.0"
"pyhoma==0.5.1"
],
"codeowners": [
"@philklei",
"@imicknl",
"@vlebourl",
"@tetienne"
],
"codeowners": ["@philklei", "@imicknl", "@vlebourl", "@tetienne"],
"issue_tracker": "https://github.com/imicknl/ha-tahoma/issues"
}
}
1 change: 1 addition & 0 deletions custom_components/tahoma/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"too_many_requests": "Too many requests, try again later.",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"server_in_maintenance": "Server is down for maintenance",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/tahoma/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"too_many_requests": "Too many requests, try again later.",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"server_in_maintenance": "Server is down for maintenance",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/tahoma/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"cannot_connect": "Connexion impossible",
"too_many_requests": "Trop de reqûtees, veuillez réessayer plus tard.",
"invalid_auth": "Mot de passe ou nom d'utilisateur incorrect",
"server_in_maintenance": "Le serveur est en cours de maintenance",
"unknown": "Une erreur inconnue est survenue."
},
"abort": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/tahoma/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"too_many_requests": "Te veel verzoeken, probeer het later opnieuw.",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"server_in_maintenance": "De server is offline voor onderhoud",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
Expand Down
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pytest-cov<3.0.0
pytest-homeassistant

# from our manifest.json for our Custom Component
pyhoma==0.5.0
pyhoma==0.5.1

0 comments on commit 1be9c7e

Please sign in to comment.