mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Use runtime_data in gpslogger (#144884)
This commit is contained in:
parent
a9238c7577
commit
ef99658919
@ -24,6 +24,8 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type GPSLoggerConfigEntry = ConfigEntry[set[str]]
|
||||||
|
|
||||||
PLATFORMS = [Platform.DEVICE_TRACKER]
|
PLATFORMS = [Platform.DEVICE_TRACKER]
|
||||||
|
|
||||||
TRACKER_UPDATE = f"{DOMAIN}_tracker_update"
|
TRACKER_UPDATE = f"{DOMAIN}_tracker_update"
|
||||||
@ -88,9 +90,9 @@ async def handle_webhook(
|
|||||||
return web.Response(text=f"Setting location for {device}")
|
return web.Response(text=f"Setting location for {device}")
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: GPSLoggerConfigEntry) -> bool:
|
||||||
"""Configure based on config entry."""
|
"""Configure based on config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {"devices": set()})
|
entry.runtime_data = set()
|
||||||
webhook.async_register(
|
webhook.async_register(
|
||||||
hass, DOMAIN, "GPSLogger", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
hass, DOMAIN, "GPSLogger", entry.data[CONF_WEBHOOK_ID], handle_webhook
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for the GPSLogger device tracking."""
|
"""Support for the GPSLogger device tracking."""
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import TrackerEntity
|
from homeassistant.components.device_tracker import TrackerEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
ATTR_GPS_ACCURACY,
|
ATTR_GPS_ACCURACY,
|
||||||
@ -15,19 +14,20 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
|
||||||
from . import DOMAIN, TRACKER_UPDATE
|
from . import TRACKER_UPDATE, GPSLoggerConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_ACTIVITY,
|
ATTR_ACTIVITY,
|
||||||
ATTR_ALTITUDE,
|
ATTR_ALTITUDE,
|
||||||
ATTR_DIRECTION,
|
ATTR_DIRECTION,
|
||||||
ATTR_PROVIDER,
|
ATTR_PROVIDER,
|
||||||
ATTR_SPEED,
|
ATTR_SPEED,
|
||||||
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: GPSLoggerConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Configure a dispatcher connection based on a config entry."""
|
"""Configure a dispatcher connection based on a config entry."""
|
||||||
@ -35,10 +35,10 @@ async def async_setup_entry(
|
|||||||
@callback
|
@callback
|
||||||
def _receive_data(device, gps, battery, accuracy, attrs):
|
def _receive_data(device, gps, battery, accuracy, attrs):
|
||||||
"""Receive set location."""
|
"""Receive set location."""
|
||||||
if device in hass.data[DOMAIN]["devices"]:
|
if device in entry.runtime_data:
|
||||||
return
|
return
|
||||||
|
|
||||||
hass.data[DOMAIN]["devices"].add(device)
|
entry.runtime_data.add(device)
|
||||||
|
|
||||||
async_add_entities([GPSLoggerEntity(device, gps, battery, accuracy, attrs)])
|
async_add_entities([GPSLoggerEntity(device, gps, battery, accuracy, attrs)])
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for dev_id in dev_ids:
|
for dev_id in dev_ids:
|
||||||
hass.data[DOMAIN]["devices"].add(dev_id)
|
entry.runtime_data.add(dev_id)
|
||||||
entity = GPSLoggerEntity(dev_id, None, None, None, None)
|
entity = GPSLoggerEntity(dev_id, None, None, None, None)
|
||||||
entities.append(entity)
|
entities.append(entity)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user