mirror of
https://github.com/home-assistant/core
synced 2024-09-12 15:16:21 +02:00
Add Life360 Location Update Button (#99559)
Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: alexyao2015 <alexyao2015@users.noreply.github.com>
This commit is contained in:
parent
da13afbd3c
commit
5ba573a1b4
@ -654,6 +654,7 @@ omit =
|
||||
homeassistant/components/lg_soundbar/__init__.py
|
||||
homeassistant/components/lg_soundbar/media_player.py
|
||||
homeassistant/components/life360/__init__.py
|
||||
homeassistant/components/life360/button.py
|
||||
homeassistant/components/life360/coordinator.py
|
||||
homeassistant/components/life360/device_tracker.py
|
||||
homeassistant/components/lightwave/*
|
||||
|
@ -39,7 +39,7 @@ from .const import (
|
||||
)
|
||||
from .coordinator import Life360DataUpdateCoordinator, MissingLocReason
|
||||
|
||||
PLATFORMS = [Platform.DEVICE_TRACKER]
|
||||
PLATFORMS = [Platform.DEVICE_TRACKER, Platform.BUTTON]
|
||||
|
||||
CONF_ACCOUNTS = "accounts"
|
||||
|
||||
|
56
homeassistant/components/life360/button.py
Normal file
56
homeassistant/components/life360/button.py
Normal file
@ -0,0 +1,56 @@
|
||||
"""Support for Life360 buttons."""
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import Life360DataUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Life360 buttons."""
|
||||
coordinator: Life360DataUpdateCoordinator = hass.data[DOMAIN].coordinators[
|
||||
config_entry.entry_id
|
||||
]
|
||||
for member_id, member in coordinator.data.members.items():
|
||||
async_add_entities(
|
||||
[
|
||||
Life360UpdateLocationButton(coordinator, member.circle_id, member_id),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class Life360UpdateLocationButton(
|
||||
CoordinatorEntity[Life360DataUpdateCoordinator], ButtonEntity
|
||||
):
|
||||
"""Represent an Life360 Update Location button."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_translation_key = "update_location"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: Life360DataUpdateCoordinator,
|
||||
circle_id: str,
|
||||
member_id: str,
|
||||
) -> None:
|
||||
"""Initialize a new Life360 Update Location button."""
|
||||
super().__init__(coordinator)
|
||||
self._circle_id = circle_id
|
||||
self._member_id = member_id
|
||||
self._attr_unique_id = f"{member_id}-update-location"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, member_id)},
|
||||
name=coordinator.data.members[member_id].name,
|
||||
)
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
await self.coordinator.update_location(self._circle_id, self._member_id)
|
@ -65,6 +65,7 @@ class Life360Member:
|
||||
at_loc_since: datetime
|
||||
battery_charging: bool
|
||||
battery_level: int
|
||||
circle_id: str
|
||||
driving: bool
|
||||
entity_picture: str
|
||||
gps_accuracy: int
|
||||
@ -118,6 +119,10 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
|
||||
LOGGER.debug("%s: %s", exc.__class__.__name__, exc)
|
||||
raise UpdateFailed(exc) from exc
|
||||
|
||||
async def update_location(self, circle_id: str, member_id: str) -> None:
|
||||
"""Update location for given Circle and Member."""
|
||||
await self._retrieve_data("update_location", circle_id, member_id)
|
||||
|
||||
async def _async_update_data(self) -> Life360Data:
|
||||
"""Get & process data from Life360."""
|
||||
|
||||
@ -214,6 +219,7 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
|
||||
dt_util.utc_from_timestamp(int(loc["since"])),
|
||||
bool(int(loc["charge"])),
|
||||
int(float(loc["battery"])),
|
||||
circle_id,
|
||||
bool(int(loc["isDriving"])),
|
||||
member["avatar"],
|
||||
# Life360 reports accuracy in feet, but Device Tracker expects
|
||||
|
@ -27,6 +27,13 @@
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"button": {
|
||||
"update_location": {
|
||||
"name": "Update Location"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
|
Loading…
Reference in New Issue
Block a user