Convert life360 to aiohttp (#77508)

Bump life360 package to 5.1.0.
This commit is contained in:
Phil Bruckner 2022-08-31 14:54:23 -05:00 committed by GitHub
parent c98ee412c0
commit c6b3b9fa90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 20 deletions

View file

@ -12,10 +12,10 @@ from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from .const import (
COMM_MAX_RETRIES,
COMM_TIMEOUT,
CONF_AUTHORIZATION,
CONF_DRIVING_SPEED,
@ -53,13 +53,10 @@ class Life360ConfigFlow(ConfigFlow, domain=DOMAIN):
"""Life360 integration config flow."""
VERSION = 1
def __init__(self) -> None:
"""Initialize."""
self._api = Life360(timeout=COMM_TIMEOUT, max_retries=COMM_MAX_RETRIES)
self._username: str | vol.UNDEFINED = vol.UNDEFINED
self._password: str | vol.UNDEFINED = vol.UNDEFINED
self._reauth_entry: ConfigEntry | None = None
_api: Life360 | None = None
_username: str | vol.UNDEFINED = vol.UNDEFINED
_password: str | vol.UNDEFINED = vol.UNDEFINED
_reauth_entry: ConfigEntry | None = None
@staticmethod
@callback
@ -69,10 +66,14 @@ class Life360ConfigFlow(ConfigFlow, domain=DOMAIN):
async def _async_verify(self, step_id: str) -> FlowResult:
"""Attempt to authorize the provided credentials."""
if not self._api:
self._api = Life360(
session=async_get_clientsession(self.hass), timeout=COMM_TIMEOUT
)
errors: dict[str, str] = {}
try:
authorization = await self.hass.async_add_executor_job(
self._api.get_authorization, self._username, self._password
authorization = await self._api.get_authorization(
self._username, self._password
)
except LoginError as exc:
LOGGER.debug("Login error: %s", exc)

View file

@ -7,7 +7,6 @@ DOMAIN = "life360"
LOGGER = logging.getLogger(__package__)
ATTRIBUTION = "Data provided by life360.com"
COMM_MAX_RETRIES = 2
COMM_TIMEOUT = 3.05
SPEED_FACTOR_MPH = 2.25
SPEED_DIGITS = 1

View file

@ -19,12 +19,12 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util.distance import convert
import homeassistant.util.dt as dt_util
from .const import (
COMM_MAX_RETRIES,
COMM_TIMEOUT,
CONF_AUTHORIZATION,
DOMAIN,
@ -106,8 +106,8 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
)
self._hass = hass
self._api = Life360(
session=async_get_clientsession(hass),
timeout=COMM_TIMEOUT,
max_retries=COMM_MAX_RETRIES,
authorization=entry.data[CONF_AUTHORIZATION],
)
self._missing_loc_reason = hass.data[DOMAIN].missing_loc_reason
@ -115,9 +115,7 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
async def _retrieve_data(self, func: str, *args: Any) -> list[dict[str, Any]]:
"""Get data from Life360."""
try:
return await self._hass.async_add_executor_job(
getattr(self._api, func), *args
)
return await getattr(self._api, func)(*args)
except LoginError as exc:
LOGGER.debug("Login error: %s", exc)
raise ConfigEntryAuthFailed from exc

View file

@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/life360",
"codeowners": ["@pnbruckner"],
"requirements": ["life360==4.1.1"],
"requirements": ["life360==5.1.0"],
"iot_class": "cloud_polling",
"loggers": ["life360"]
}

View file

@ -980,7 +980,7 @@ librouteros==3.2.0
libsoundtouch==0.8
# homeassistant.components.life360
life360==4.1.1
life360==5.1.0
# homeassistant.components.osramlightify
lightify==1.0.7.3

View file

@ -715,7 +715,7 @@ librouteros==3.2.0
libsoundtouch==0.8
# homeassistant.components.life360
life360==4.1.1
life360==5.1.0
# homeassistant.components.logi_circle
logi_circle==0.2.3

View file

@ -76,7 +76,9 @@ def life360_fixture():
@pytest.fixture
def life360_api():
"""Mock Life360 api."""
with patch("homeassistant.components.life360.config_flow.Life360") as mock:
with patch(
"homeassistant.components.life360.config_flow.Life360", autospec=True
) as mock:
yield mock.return_value