Skip to content

Commit 1be9c7e

Browse files
iMicknltetienne
andauthored
Improve handling of errors when Somfy server is in maintenance. (#306)
Co-authored-by: Thibaut Etienne <[email protected]>
1 parent 48bef61 commit 1be9c7e

File tree

9 files changed

+34
-6
lines changed

9 files changed

+34
-6
lines changed

custom_components/tahoma/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
from homeassistant.exceptions import ConfigEntryNotReady
1313
from homeassistant.helpers import aiohttp_client, config_validation as cv
1414
from pyhoma.client import TahomaClient
15-
from pyhoma.exceptions import BadCredentialsException, TooManyRequestsException
15+
from pyhoma.exceptions import (
16+
BadCredentialsException,
17+
MaintenanceException,
18+
TooManyRequestsException,
19+
)
1620
from pyhoma.models import Command
1721
import voluptuous as vol
1822

@@ -95,6 +99,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
9599
except (TimeoutError, ClientError, ServerDisconnectedError) as exception:
96100
_LOGGER.error("cannot_connect")
97101
raise ConfigEntryNotReady from exception
102+
except MaintenanceException as exception:
103+
_LOGGER.error("server_in_maintenance")
104+
raise ConfigEntryNotReady from exception
98105
except Exception as exception: # pylint: disable=broad-except
99106
_LOGGER.exception(exception)
100107
return False

custom_components/tahoma/config_flow.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from homeassistant.core import callback
88
from homeassistant.helpers import config_validation as cv
99
from pyhoma.client import TahomaClient
10-
from pyhoma.exceptions import BadCredentialsException, TooManyRequestsException
10+
from pyhoma.exceptions import (
11+
BadCredentialsException,
12+
MaintenanceException,
13+
TooManyRequestsException,
14+
)
1115
import voluptuous as vol
1216

1317
from .const import CONF_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL, MIN_UPDATE_INTERVAL
@@ -57,6 +61,8 @@ async def async_step_user(self, user_input=None):
5761
errors["base"] = "invalid_auth"
5862
except (TimeoutError, ClientError):
5963
errors["base"] = "cannot_connect"
64+
except MaintenanceException:
65+
errors["base"] = "server_in_maintenance"
6066
except Exception as exception: # pylint: disable=broad-except
6167
errors["base"] = "unknown"
6268
_LOGGER.exception(exception)
@@ -81,6 +87,9 @@ async def async_step_import(self, import_config: dict):
8187
except (TimeoutError, ClientError):
8288
_LOGGER.error("cannot_connect")
8389
return self.async_abort(reason="cannot_connect")
90+
except MaintenanceException:
91+
_LOGGER.error("server_in_maintenance")
92+
return self.async_abort(reason="server_in_maintenance")
8493
except Exception as exception: # pylint: disable=broad-except
8594
_LOGGER.exception(exception)
8695
return self.async_abort(reason="unknown")

custom_components/tahoma/coordinator.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pyhoma.enums import EventName, ExecutionState
1212
from pyhoma.exceptions import (
1313
BadCredentialsException,
14+
MaintenanceException,
1415
NotAuthenticatedException,
1516
TooManyRequestsException,
1617
)
@@ -67,6 +68,8 @@ async def _async_update_data(self) -> Dict[str, Device]:
6768
raise UpdateFailed("invalid_auth") from exception
6869
except TooManyRequestsException as exception:
6970
raise UpdateFailed("too_many_requests") from exception
71+
except MaintenanceException as exception:
72+
raise UpdateFailed("server_in_maintenance") from exception
7073
except (ServerDisconnectedError, NotAuthenticatedException) as exception:
7174
_LOGGER.debug(exception)
7275
self.executions = {}

custom_components/tahoma/manifest.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
"config_flow": true,
55
"documentation": "https://www.home-assistant.io/integrations/tahoma",
66
"requirements": [
7-
"pyhoma==0.5.0"
7+
"pyhoma==0.5.1"
8+
],
9+
"codeowners": [
10+
"@philklei",
11+
"@imicknl",
12+
"@vlebourl",
13+
"@tetienne"
814
],
9-
"codeowners": ["@philklei", "@imicknl", "@vlebourl", "@tetienne"],
1015
"issue_tracker": "https://github.com/imicknl/ha-tahoma/issues"
11-
}
16+
}

custom_components/tahoma/strings.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
1414
"too_many_requests": "Too many requests, try again later.",
1515
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
16+
"server_in_maintenance": "Server is down for maintenance",
1617
"unknown": "[%key:common::config_flow::error::unknown%]"
1718
},
1819
"abort": {

custom_components/tahoma/translations/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
1414
"too_many_requests": "Too many requests, try again later.",
1515
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
16+
"server_in_maintenance": "Server is down for maintenance",
1617
"unknown": "[%key:common::config_flow::error::unknown%]"
1718
},
1819
"abort": {

custom_components/tahoma/translations/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cannot_connect": "Connexion impossible",
1414
"too_many_requests": "Trop de reqûtees, veuillez réessayer plus tard.",
1515
"invalid_auth": "Mot de passe ou nom d'utilisateur incorrect",
16+
"server_in_maintenance": "Le serveur est en cours de maintenance",
1617
"unknown": "Une erreur inconnue est survenue."
1718
},
1819
"abort": {

custom_components/tahoma/translations/nl.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"too_many_requests": "Te veel verzoeken, probeer het later opnieuw.",
1414
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
1515
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
16+
"server_in_maintenance": "De server is offline voor onderhoud",
1617
"unknown": "[%key:common::config_flow::error::unknown%]"
1718
},
1819
"abort": {

requirements.test.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pytest-cov<3.0.0
77
pytest-homeassistant
88

99
# from our manifest.json for our Custom Component
10-
pyhoma==0.5.0
10+
pyhoma==0.5.1

0 commit comments

Comments
 (0)