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_STATION_PW = "WINDY_STATION_PWD"
|
||||||
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
||||||
WINDY_LOGGER_ENABLED: Final = "windy_logger_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_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_SUCCESS: Final = (
|
||||||
"Windy successfully sent data and data was successfully inserted by Windy API"
|
"Windy successfully sent data and data was successfully inserted by Windy API"
|
||||||
|
|
|
||||||
|
|
@ -218,10 +218,15 @@ class WindyPush:
|
||||||
try:
|
try:
|
||||||
self.verify_windy_response(response=resp)
|
self.verify_windy_response(response=resp)
|
||||||
except WindyNotInserted:
|
except WindyNotInserted:
|
||||||
# log despite of settings
|
|
||||||
_LOGGER.error(WINDY_NOT_INSERTED)
|
|
||||||
self.invalid_response_count += 1
|
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:
|
except WindyPasswordMissing:
|
||||||
# log despite of settings
|
# log despite of settings
|
||||||
_LOGGER.critical(WINDY_INVALID_KEY)
|
_LOGGER.critical(WINDY_INVALID_KEY)
|
||||||
|
|
@ -236,11 +241,25 @@ class WindyPush:
|
||||||
self.invalid_response_count += 1
|
self.invalid_response_count += 1
|
||||||
|
|
||||||
except WindySuccess:
|
except WindySuccess:
|
||||||
|
# reset invalid_response_count
|
||||||
|
self.invalid_response_count = 0
|
||||||
if self.log:
|
if self.log:
|
||||||
_LOGGER.info(WINDY_SUCCESS)
|
_LOGGER.info(WINDY_SUCCESS)
|
||||||
else:
|
else:
|
||||||
if self.log:
|
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:
|
except ClientError as ex:
|
||||||
_LOGGER.critical(
|
_LOGGER.critical(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue