mirror of
https://github.com/home-assistant/core
synced 2024-07-15 09:42:11 +02:00
Remove deprecated Life360 yaml configuration (#106286)
This commit is contained in:
parent
2d0325a471
commit
4bfeb87377
@ -2,128 +2,22 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import CONF_SCAN_INTERVAL
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_EXCLUDE,
|
||||
CONF_INCLUDE,
|
||||
CONF_PASSWORD,
|
||||
CONF_PREFIX,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_CIRCLES,
|
||||
CONF_DRIVING_SPEED,
|
||||
CONF_ERROR_THRESHOLD,
|
||||
CONF_MAX_GPS_ACCURACY,
|
||||
CONF_MAX_UPDATE_WAIT,
|
||||
CONF_MEMBERS,
|
||||
CONF_SHOW_AS_STATE,
|
||||
CONF_WARNING_THRESHOLD,
|
||||
DEFAULT_OPTIONS,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
SHOW_DRIVING,
|
||||
SHOW_MOVING,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
from .coordinator import Life360DataUpdateCoordinator, MissingLocReason
|
||||
|
||||
PLATFORMS = [Platform.DEVICE_TRACKER, Platform.BUTTON]
|
||||
|
||||
CONF_ACCOUNTS = "accounts"
|
||||
|
||||
SHOW_AS_STATE_OPTS = [SHOW_DRIVING, SHOW_MOVING]
|
||||
|
||||
|
||||
def _show_as_state(config: dict) -> dict:
|
||||
if opts := config.pop(CONF_SHOW_AS_STATE):
|
||||
if SHOW_DRIVING in opts:
|
||||
config[SHOW_DRIVING] = True
|
||||
if SHOW_MOVING in opts:
|
||||
LOGGER.warning(
|
||||
"%s is no longer supported as an option for %s",
|
||||
SHOW_MOVING,
|
||||
CONF_SHOW_AS_STATE,
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
def _unsupported(unsupported: set[str]) -> Callable[[dict], dict]:
|
||||
"""Warn about unsupported options and remove from config."""
|
||||
|
||||
def validator(config: dict) -> dict:
|
||||
if unsupported_keys := unsupported & set(config):
|
||||
LOGGER.warning(
|
||||
"The following options are no longer supported: %s",
|
||||
", ".join(sorted(unsupported_keys)),
|
||||
)
|
||||
return {k: v for k, v in config.items() if k not in unsupported}
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
ACCOUNT_SCHEMA = {
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}
|
||||
CIRCLES_MEMBERS = {
|
||||
vol.Optional(CONF_EXCLUDE): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_INCLUDE): vol.All(cv.ensure_list, [cv.string]),
|
||||
}
|
||||
LIFE360_SCHEMA = vol.All(
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_ACCOUNTS): vol.All(cv.ensure_list, [ACCOUNT_SCHEMA]),
|
||||
vol.Optional(CONF_CIRCLES): CIRCLES_MEMBERS,
|
||||
vol.Optional(CONF_DRIVING_SPEED): vol.Coerce(float),
|
||||
vol.Optional(CONF_ERROR_THRESHOLD): vol.Coerce(int),
|
||||
vol.Optional(CONF_MAX_GPS_ACCURACY): vol.Coerce(float),
|
||||
vol.Optional(CONF_MAX_UPDATE_WAIT): cv.time_period,
|
||||
vol.Optional(CONF_MEMBERS): CIRCLES_MEMBERS,
|
||||
vol.Optional(CONF_PREFIX): vol.Any(None, cv.string),
|
||||
vol.Optional(CONF_SCAN_INTERVAL): cv.time_period,
|
||||
vol.Optional(CONF_SHOW_AS_STATE, default=[]): vol.All(
|
||||
cv.ensure_list, [vol.In(SHOW_AS_STATE_OPTS)]
|
||||
),
|
||||
vol.Optional(CONF_WARNING_THRESHOLD): vol.Coerce(int),
|
||||
}
|
||||
),
|
||||
_unsupported(
|
||||
{
|
||||
CONF_ACCOUNTS,
|
||||
CONF_CIRCLES,
|
||||
CONF_ERROR_THRESHOLD,
|
||||
CONF_MAX_UPDATE_WAIT,
|
||||
CONF_MEMBERS,
|
||||
CONF_PREFIX,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_WARNING_THRESHOLD,
|
||||
}
|
||||
),
|
||||
_show_as_state,
|
||||
)
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
vol.All({DOMAIN: LIFE360_SCHEMA}, cv.removed(DOMAIN, raise_if_present=False)),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class IntegData:
|
||||
"""Integration data."""
|
||||
|
||||
cfg_options: dict[str, Any] | None = None
|
||||
# ConfigEntry.entry_id: Life360DataUpdateCoordinator
|
||||
coordinators: dict[str, Life360DataUpdateCoordinator] = field(
|
||||
init=False, default_factory=dict
|
||||
@ -137,34 +31,13 @@ class IntegData:
|
||||
logged_circles: list[str] = field(init=False, default_factory=list)
|
||||
logged_places: list[str] = field(init=False, default_factory=list)
|
||||
|
||||
def __post_init__(self):
|
||||
"""Finish initialization of cfg_options."""
|
||||
self.cfg_options = self.cfg_options or {}
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up integration."""
|
||||
hass.data.setdefault(DOMAIN, IntegData(config.get(DOMAIN)))
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up config entry."""
|
||||
hass.data.setdefault(DOMAIN, IntegData())
|
||||
|
||||
# Check if this entry was created when this was a "legacy" tracker. If it was,
|
||||
# update with missing data.
|
||||
if not entry.unique_id:
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
unique_id=entry.data[CONF_USERNAME].lower(),
|
||||
options=DEFAULT_OPTIONS | hass.data[DOMAIN].cfg_options,
|
||||
)
|
||||
|
||||
coordinator = Life360DataUpdateCoordinator(hass, entry)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data[DOMAIN].coordinators[entry.entry_id] = coordinator
|
||||
|
||||
# Set up components for our platforms.
|
||||
|
@ -24,17 +24,10 @@ ATTR_SPEED = "speed"
|
||||
ATTR_WIFI_ON = "wifi_on"
|
||||
|
||||
CONF_AUTHORIZATION = "authorization"
|
||||
CONF_CIRCLES = "circles"
|
||||
CONF_DRIVING_SPEED = "driving_speed"
|
||||
CONF_ERROR_THRESHOLD = "error_threshold"
|
||||
CONF_MAX_GPS_ACCURACY = "max_gps_accuracy"
|
||||
CONF_MAX_UPDATE_WAIT = "max_update_wait"
|
||||
CONF_MEMBERS = "members"
|
||||
CONF_SHOW_AS_STATE = "show_as_state"
|
||||
CONF_WARNING_THRESHOLD = "warning_threshold"
|
||||
|
||||
SHOW_DRIVING = "driving"
|
||||
SHOW_MOVING = "moving"
|
||||
|
||||
DEFAULT_OPTIONS = {
|
||||
CONF_DRIVING_SPEED: None,
|
||||
|
Loading…
Reference in New Issue
Block a user