Catch all Ring timeout errors (#30960)
* Catch more Ring errors * Fix comment & Disable wifi entities by default
This commit is contained in:
parent
8fcd0e9a79
commit
ecef0f6e93
4 changed files with 49 additions and 11 deletions
|
@ -7,6 +7,7 @@ from pathlib import Path
|
|||
from typing import Optional
|
||||
|
||||
from oauthlib.oauth2 import AccessDeniedError
|
||||
import requests
|
||||
from ring_doorbell import Auth, Ring
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -95,13 +96,19 @@ async def async_setup_entry(hass, entry):
|
|||
"api": ring,
|
||||
"devices": ring.devices(),
|
||||
"device_data": GlobalDataUpdater(
|
||||
hass, entry.entry_id, ring, "update_devices", timedelta(minutes=1)
|
||||
hass, "device", entry.entry_id, ring, "update_devices", timedelta(minutes=1)
|
||||
),
|
||||
"dings_data": GlobalDataUpdater(
|
||||
hass, entry.entry_id, ring, "update_dings", timedelta(seconds=5)
|
||||
hass,
|
||||
"active dings",
|
||||
entry.entry_id,
|
||||
ring,
|
||||
"update_dings",
|
||||
timedelta(seconds=5),
|
||||
),
|
||||
"history_data": DeviceDataUpdater(
|
||||
hass,
|
||||
"history",
|
||||
entry.entry_id,
|
||||
ring,
|
||||
lambda device: device.history(limit=10),
|
||||
|
@ -109,6 +116,7 @@ async def async_setup_entry(hass, entry):
|
|||
),
|
||||
"health_data": DeviceDataUpdater(
|
||||
hass,
|
||||
"health",
|
||||
entry.entry_id,
|
||||
ring,
|
||||
lambda device: device.update_health_data(),
|
||||
|
@ -168,6 +176,7 @@ class GlobalDataUpdater:
|
|||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
data_type: str,
|
||||
config_entry_id: str,
|
||||
ring: Ring,
|
||||
update_method: str,
|
||||
|
@ -175,6 +184,7 @@ class GlobalDataUpdater:
|
|||
):
|
||||
"""Initialize global data updater."""
|
||||
self.hass = hass
|
||||
self.data_type = data_type
|
||||
self.config_entry_id = config_entry_id
|
||||
self.ring = ring
|
||||
self.update_method = update_method
|
||||
|
@ -215,6 +225,11 @@ class GlobalDataUpdater:
|
|||
_LOGGER.error("Ring access token is no longer valid. Set up Ring again")
|
||||
await self.hass.config_entries.async_unload(self.config_entry_id)
|
||||
return
|
||||
except requests.Timeout:
|
||||
_LOGGER.warning(
|
||||
"Time out fetching Ring %s data", self.data_type,
|
||||
)
|
||||
return
|
||||
|
||||
for update_callback in self.listeners:
|
||||
update_callback()
|
||||
|
@ -226,12 +241,14 @@ class DeviceDataUpdater:
|
|||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
data_type: str,
|
||||
config_entry_id: str,
|
||||
ring: Ring,
|
||||
update_method: str,
|
||||
update_interval: timedelta,
|
||||
):
|
||||
"""Initialize device data updater."""
|
||||
self.data_type = data_type
|
||||
self.hass = hass
|
||||
self.config_entry_id = config_entry_id
|
||||
self.ring = ring
|
||||
|
@ -282,7 +299,7 @@ class DeviceDataUpdater:
|
|||
|
||||
def refresh_all(self, _=None):
|
||||
"""Refresh all registered devices."""
|
||||
for info in self.devices.values():
|
||||
for device_id, info in self.devices.items():
|
||||
try:
|
||||
data = info["data"] = self.update_method(info["device"])
|
||||
except AccessDeniedError:
|
||||
|
@ -291,6 +308,13 @@ class DeviceDataUpdater:
|
|||
self.hass.config_entries.async_unload(self.config_entry_id)
|
||||
)
|
||||
return
|
||||
except requests.Timeout:
|
||||
_LOGGER.warning(
|
||||
"Time out fetching Ring %s data for device %s",
|
||||
self.data_type,
|
||||
device_id,
|
||||
)
|
||||
continue
|
||||
|
||||
for update_callback in info["update_callbacks"]:
|
||||
self.hass.loop.call_soon_threadsafe(update_callback, data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue