Improve Windy error handling and retry logic
parent
3e573087a2
commit
995f607cf7
|
|
@ -130,7 +130,9 @@ WINDY_STATION_ID = "WINDY_STATION_ID"
|
|||
WINDY_STATION_PW = "WINDY_STATION_PWD"
|
||||
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
||||
WINDY_LOGGER_ENABLED: Final = "windy_logger_checkbox"
|
||||
WINDY_NOT_INSERTED: Final = "Data was succefuly sent to Windy, but not inserted by Windy API. Does anyone else sent data to Windy?"
|
||||
WINDY_NOT_INSERTED: Final = (
|
||||
"Windy responded with 400 error. Invalid ID/password combination?"
|
||||
)
|
||||
WINDY_INVALID_KEY: Final = "Windy API KEY is invalid. Send data to Windy is now disabled. Check your API KEY and try again."
|
||||
WINDY_SUCCESS: Final = (
|
||||
"Windy successfully sent data and data was successfully inserted by Windy API"
|
||||
|
|
|
|||
|
|
@ -218,10 +218,15 @@ class WindyPush:
|
|||
try:
|
||||
self.verify_windy_response(response=resp)
|
||||
except WindyNotInserted:
|
||||
# log despite of settings
|
||||
_LOGGER.error(WINDY_NOT_INSERTED)
|
||||
self.invalid_response_count += 1
|
||||
|
||||
# log despite of settings
|
||||
_LOGGER.error(
|
||||
"%s Max retries before disable resend function: %s",
|
||||
WINDY_NOT_INSERTED,
|
||||
(WINDY_MAX_RETRIES - self.invalid_response_count),
|
||||
)
|
||||
|
||||
except WindyPasswordMissing:
|
||||
# log despite of settings
|
||||
_LOGGER.critical(WINDY_INVALID_KEY)
|
||||
|
|
@ -236,11 +241,25 @@ class WindyPush:
|
|||
self.invalid_response_count += 1
|
||||
|
||||
except WindySuccess:
|
||||
# reset invalid_response_count
|
||||
self.invalid_response_count = 0
|
||||
if self.log:
|
||||
_LOGGER.info(WINDY_SUCCESS)
|
||||
else:
|
||||
if self.log:
|
||||
_LOGGER.debug(WINDY_NOT_INSERTED)
|
||||
self.invalid_response_count += 1
|
||||
_LOGGER.debug(
|
||||
"Unexpected response from Windy. Max retries before disabling resend function: %s",
|
||||
(WINDY_MAX_RETRIES - self.invalid_response_count),
|
||||
)
|
||||
finally:
|
||||
if self.invalid_response_count >= 3:
|
||||
_LOGGER.critical(
|
||||
"Invalid response from Windy 3 times. Disabling resend option."
|
||||
)
|
||||
await self._disable_windy(
|
||||
reason="Unable to send data to Windy (3 times). Disabling resend option for now. Please check your Windy configuration and enable this feature afterwards."
|
||||
)
|
||||
|
||||
except ClientError as ex:
|
||||
_LOGGER.critical(
|
||||
|
|
|
|||
Loading…
Reference in New Issue