Update ring integration imports (#113397)
Update ring imports for patching where library is created
This commit is contained in:
parent
9eea786411
commit
4aec48d358
10 changed files with 30 additions and 39 deletions
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
from functools import partial
|
||||
import logging
|
||||
|
||||
import ring_doorbell
|
||||
from ring_doorbell import Auth, Ring
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import APPLICATION_NAME, CONF_TOKEN, __version__
|
||||
|
@ -39,10 +39,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
)
|
||||
|
||||
auth = ring_doorbell.Auth(
|
||||
auth = Auth(
|
||||
f"{APPLICATION_NAME}/{__version__}", entry.data[CONF_TOKEN], token_updater
|
||||
)
|
||||
ring = ring_doorbell.Ring(auth)
|
||||
ring = Ring(auth)
|
||||
|
||||
devices_coordinator = RingDataCoordinator(hass, ring)
|
||||
notifications_coordinator = RingNotificationsCoordinator(hass, ring)
|
||||
|
|
|
@ -4,7 +4,7 @@ from collections.abc import Mapping
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
import ring_doorbell
|
||||
from ring_doorbell import Auth, AuthenticationError, Requires2FAError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
|
@ -31,7 +31,7 @@ STEP_REAUTH_DATA_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
|
|||
async def validate_input(hass: HomeAssistant, data):
|
||||
"""Validate the user input allows us to connect."""
|
||||
|
||||
auth = ring_doorbell.Auth(f"{APPLICATION_NAME}/{ha_version}")
|
||||
auth = Auth(f"{APPLICATION_NAME}/{ha_version}")
|
||||
|
||||
try:
|
||||
token = await hass.async_add_executor_job(
|
||||
|
@ -40,9 +40,9 @@ async def validate_input(hass: HomeAssistant, data):
|
|||
data[CONF_PASSWORD],
|
||||
data.get(CONF_2FA),
|
||||
)
|
||||
except ring_doorbell.Requires2FAError as err:
|
||||
except Requires2FAError as err:
|
||||
raise Require2FA from err
|
||||
except ring_doorbell.AuthenticationError as err:
|
||||
except AuthenticationError as err:
|
||||
raise InvalidAuth from err
|
||||
|
||||
return token
|
||||
|
|
|
@ -6,8 +6,7 @@ from dataclasses import dataclass
|
|||
import logging
|
||||
from typing import Any, Optional
|
||||
|
||||
import ring_doorbell
|
||||
from ring_doorbell.generic import RingGeneric
|
||||
from ring_doorbell import AuthenticationError, Ring, RingError, RingGeneric, RingTimeout
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
|
@ -23,15 +22,15 @@ async def _call_api(
|
|||
):
|
||||
try:
|
||||
return await hass.async_add_executor_job(target, *args)
|
||||
except ring_doorbell.AuthenticationError as err:
|
||||
except AuthenticationError as err:
|
||||
# Raising ConfigEntryAuthFailed will cancel future updates
|
||||
# and start a config flow with SOURCE_REAUTH (async_step_reauth)
|
||||
raise ConfigEntryAuthFailed from err
|
||||
except ring_doorbell.RingTimeout as err:
|
||||
except RingTimeout as err:
|
||||
raise UpdateFailed(
|
||||
f"Timeout communicating with API{msg_suffix}: {err}"
|
||||
) from err
|
||||
except ring_doorbell.RingError as err:
|
||||
except RingError as err:
|
||||
raise UpdateFailed(f"Error communicating with API{msg_suffix}: {err}") from err
|
||||
|
||||
|
||||
|
@ -49,7 +48,7 @@ class RingDataCoordinator(DataUpdateCoordinator[dict[int, RingDeviceData]]):
|
|||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
ring_api: ring_doorbell.Ring,
|
||||
ring_api: Ring,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(
|
||||
|
@ -58,7 +57,7 @@ class RingDataCoordinator(DataUpdateCoordinator[dict[int, RingDeviceData]]):
|
|||
logger=_LOGGER,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
self.ring_api: ring_doorbell.Ring = ring_api
|
||||
self.ring_api: Ring = ring_api
|
||||
self.first_call: bool = True
|
||||
|
||||
async def _async_update_data(self):
|
||||
|
@ -105,7 +104,7 @@ class RingDataCoordinator(DataUpdateCoordinator[dict[int, RingDeviceData]]):
|
|||
class RingNotificationsCoordinator(DataUpdateCoordinator[None]):
|
||||
"""Global notifications coordinator."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, ring_api: ring_doorbell.Ring) -> None:
|
||||
def __init__(self, hass: HomeAssistant, ring_api: Ring) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
|
@ -113,7 +112,7 @@ class RingNotificationsCoordinator(DataUpdateCoordinator[None]):
|
|||
name="active dings",
|
||||
update_interval=NOTIFICATIONS_SCAN_INTERVAL,
|
||||
)
|
||||
self.ring_api: ring_doorbell.Ring = ring_api
|
||||
self.ring_api: Ring = ring_api
|
||||
|
||||
async def _async_update_data(self):
|
||||
"""Fetch data from API endpoint."""
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
import ring_doorbell
|
||||
from ring_doorbell import Ring
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -33,7 +33,7 @@ async def async_get_config_entry_diagnostics(
|
|||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
ring: ring_doorbell.Ring = hass.data[DOMAIN][entry.entry_id]["api"]
|
||||
ring: Ring = hass.data[DOMAIN][entry.entry_id]["api"]
|
||||
devices_raw = [
|
||||
ring.devices_data[device_type][device_id]
|
||||
for device_type in ring.devices_data
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from collections.abc import Callable
|
||||
from typing import Any, Concatenate, ParamSpec, TypeVar
|
||||
|
||||
import ring_doorbell
|
||||
from ring_doorbell import AuthenticationError, RingError, RingGeneric, RingTimeout
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -32,16 +32,16 @@ def exception_wrap(
|
|||
def _wrap(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None:
|
||||
try:
|
||||
return func(self, *args, **kwargs)
|
||||
except ring_doorbell.AuthenticationError as err:
|
||||
except AuthenticationError as err:
|
||||
self.hass.loop.call_soon_threadsafe(
|
||||
self.coordinator.config_entry.async_start_reauth, self.hass
|
||||
)
|
||||
raise HomeAssistantError(err) from err
|
||||
except ring_doorbell.RingTimeout as err:
|
||||
except RingTimeout as err:
|
||||
raise HomeAssistantError(
|
||||
f"Timeout communicating with API {func}: {err}"
|
||||
) from err
|
||||
except ring_doorbell.RingError as err:
|
||||
except RingError as err:
|
||||
raise HomeAssistantError(
|
||||
f"Error communicating with API{func}: {err}"
|
||||
) from err
|
||||
|
@ -58,7 +58,7 @@ class RingEntity(CoordinatorEntity[_RingCoordinatorT]):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
device: ring_doorbell.RingGeneric,
|
||||
device: RingGeneric,
|
||||
coordinator: _RingCoordinatorT,
|
||||
) -> None:
|
||||
"""Initialize a sensor for Ring device."""
|
||||
|
@ -79,7 +79,7 @@ class RingEntity(CoordinatorEntity[_RingCoordinatorT]):
|
|||
return device_data
|
||||
return None
|
||||
|
||||
def _get_coordinator_device(self) -> ring_doorbell.RingGeneric | None:
|
||||
def _get_coordinator_device(self) -> RingGeneric | None:
|
||||
if (device_data := self._get_coordinator_device_data()) and (
|
||||
device := device_data.device
|
||||
):
|
||||
|
|
|
@ -4,8 +4,7 @@ from datetime import timedelta
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from ring_doorbell import RingStickUpCam
|
||||
from ring_doorbell.generic import RingGeneric
|
||||
from ring_doorbell import RingGeneric, RingStickUpCam
|
||||
|
||||
from homeassistant.components.light import ColorMode, LightEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
|
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from ring_doorbell.generic import RingGeneric
|
||||
from ring_doorbell import RingGeneric
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from ring_doorbell import RingGeneric
|
||||
from ring_doorbell.const import CHIME_TEST_SOUND_KINDS, KIND_DING
|
||||
from ring_doorbell.generic import RingGeneric
|
||||
|
||||
from homeassistant.components.siren import ATTR_TONE, SirenEntity, SirenEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
|
|
@ -4,8 +4,7 @@ from datetime import timedelta
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from ring_doorbell import RingStickUpCam
|
||||
from ring_doorbell.generic import RingGeneric
|
||||
from ring_doorbell import RingGeneric, RingStickUpCam
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
|
|
@ -27,20 +27,15 @@ def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
|||
@pytest.fixture
|
||||
def mock_ring_auth():
|
||||
"""Mock ring_doorbell.Auth."""
|
||||
with patch("ring_doorbell.Auth", autospec=True) as mock_ring_auth:
|
||||
with patch(
|
||||
"homeassistant.components.ring.config_flow.Auth", autospec=True
|
||||
) as mock_ring_auth:
|
||||
mock_ring_auth.return_value.fetch_token.return_value = {
|
||||
"access_token": "mock-token"
|
||||
}
|
||||
yield mock_ring_auth.return_value
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_ring():
|
||||
"""Mock ring_doorbell.Ring."""
|
||||
with patch("ring_doorbell.Ring", autospec=True) as mock_ring:
|
||||
yield mock_ring.return_value
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Mock ConfigEntry."""
|
||||
|
@ -60,7 +55,6 @@ async def mock_added_config_entry(
|
|||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_ring_auth: Mock,
|
||||
mock_ring: Mock,
|
||||
) -> MockConfigEntry:
|
||||
"""Mock ConfigEntry that's been added to HA."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue