mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Ensure rachio retries setup later when cloud service is broken (#71300)
This commit is contained in:
parent
52333bb720
commit
5a5cde690f
@ -9,7 +9,7 @@ from homeassistant.components import cloud
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, Platform
|
from homeassistant.const import CONF_API_KEY, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from .const import CONF_CLOUDHOOK_URL, CONF_MANUAL_RUN_MINS, CONF_WEBHOOK_ID, DOMAIN
|
from .const import CONF_CLOUDHOOK_URL, CONF_MANUAL_RUN_MINS, CONF_WEBHOOK_ID, DOMAIN
|
||||||
@ -73,6 +73,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
# Get the API user
|
# Get the API user
|
||||||
try:
|
try:
|
||||||
await person.async_setup(hass)
|
await person.async_setup(hass)
|
||||||
|
except ConfigEntryAuthFailed as error:
|
||||||
|
# Reauth is not yet implemented
|
||||||
|
_LOGGER.error("Authentication failed: %s", error)
|
||||||
|
return False
|
||||||
except ConnectTimeout as error:
|
except ConnectTimeout as error:
|
||||||
_LOGGER.error("Could not reach the Rachio API: %s", error)
|
_LOGGER.error("Could not reach the Rachio API: %s", error)
|
||||||
raise ConfigEntryNotReady from error
|
raise ConfigEntryNotReady from error
|
||||||
|
@ -8,6 +8,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import ServiceCall
|
from homeassistant.core import ServiceCall
|
||||||
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -125,12 +126,18 @@ class RachioPerson:
|
|||||||
rachio = self.rachio
|
rachio = self.rachio
|
||||||
|
|
||||||
response = rachio.person.info()
|
response = rachio.person.info()
|
||||||
assert int(response[0][KEY_STATUS]) == HTTPStatus.OK, "API key error"
|
if is_invalid_auth_code(int(response[0][KEY_STATUS])):
|
||||||
|
raise ConfigEntryAuthFailed(f"API key error: {response}")
|
||||||
|
if int(response[0][KEY_STATUS]) != HTTPStatus.OK:
|
||||||
|
raise ConfigEntryNotReady(f"API Error: {response}")
|
||||||
self._id = response[1][KEY_ID]
|
self._id = response[1][KEY_ID]
|
||||||
|
|
||||||
# Use user ID to get user data
|
# Use user ID to get user data
|
||||||
data = rachio.person.get(self._id)
|
data = rachio.person.get(self._id)
|
||||||
assert int(data[0][KEY_STATUS]) == HTTPStatus.OK, "User ID error"
|
if is_invalid_auth_code(int(data[0][KEY_STATUS])):
|
||||||
|
raise ConfigEntryAuthFailed(f"User ID error: {data}")
|
||||||
|
if int(data[0][KEY_STATUS]) != HTTPStatus.OK:
|
||||||
|
raise ConfigEntryNotReady(f"API Error: {data}")
|
||||||
self.username = data[1][KEY_USERNAME]
|
self.username = data[1][KEY_USERNAME]
|
||||||
devices = data[1][KEY_DEVICES]
|
devices = data[1][KEY_DEVICES]
|
||||||
for controller in devices:
|
for controller in devices:
|
||||||
@ -297,3 +304,11 @@ class RachioIro:
|
|||||||
"""Resume paused watering on this controller."""
|
"""Resume paused watering on this controller."""
|
||||||
self.rachio.device.resume_zone_run(self.controller_id)
|
self.rachio.device.resume_zone_run(self.controller_id)
|
||||||
_LOGGER.debug("Resuming watering on %s", self)
|
_LOGGER.debug("Resuming watering on %s", self)
|
||||||
|
|
||||||
|
|
||||||
|
def is_invalid_auth_code(http_status_code):
|
||||||
|
"""HTTP status codes that mean invalid auth."""
|
||||||
|
if http_status_code in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user