Skip to content

Commit

Permalink
Dev blog thru 20240805
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Nov 26, 2024
1 parent 12c8c8a commit e8a36e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
13 changes: 3 additions & 10 deletions custom_components/google_maps/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
self._create_acct_entity = entry.options[CONF_CREATE_ACCT_ENTITY]

self._api = GMLocSharing(self._username)
self._cookie_lock = Lock()
self.cookie_lock = Lock()
self._unsub_final_write = hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_FINAL_WRITE, self._save_cookies_if_changed
)
Expand All @@ -73,11 +73,6 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
if hasattr(self, "always_update"):
self.always_update = False

@property
def cookie_lock(self) -> Lock:
"""Return cookie lock."""
return self._cookie_lock

async def async_shutdown(self) -> None:
"""Cancel listeners, save cookies & close API."""
await super().async_shutdown()
Expand Down Expand Up @@ -105,8 +100,8 @@ def _unsub_expiration(self) -> None:
self._unsub_exp()
self._unsub_exp = None

async def async_config_entry_first_refresh(self) -> None:
"""Refresh data for the first time when a config entry is setup."""
async def _async_setup(self) -> None:
"""Set up the coordinator."""
# Load the cookies before first update.
async with self.cookie_lock:
try:
Expand All @@ -117,8 +112,6 @@ async def async_config_entry_first_refresh(self) -> None:
raise ConfigEntryAuthFailed(f"{err.__class__.__name__}: {err}") from err
self._cookies_file_synced()

await super().async_config_entry_first_refresh()

async def _async_update_data(self) -> GMData:
"""Fetch the latest data from the source."""
async with self.cookie_lock:
Expand Down
22 changes: 6 additions & 16 deletions custom_components/google_maps/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.device_registry import (
STORAGE_VERSION_MAJOR,
STORAGE_VERSION_MINOR,
DeviceInfo,
)
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.restore_state import RestoreEntity
Expand Down Expand Up @@ -250,6 +246,11 @@ def __init__(
)
].original_name
self._full_name = cast(str, self._attr_name).removeprefix(f"{NAME_PREFIX} ")
self._attr_device_info = DeviceInfo( # type: ignore[assignment]
identifiers={(DOMAIN, uid)},
name=self._full_name,
serial_number=uid,
)

@property
def suggested_object_id(self) -> str:
Expand All @@ -269,17 +270,6 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
attrs[ATTR_LAST_SEEN] = dt_util.as_local(self._loc.last_seen)
return dict(sorted(attrs.items()))

@property
def device_info(self) -> DeviceInfo | None:
"""Return device specific attributes."""
info = DeviceInfo(
identifiers={(DOMAIN, cast(str, self.unique_id))},
name=self._full_name,
)
if (STORAGE_VERSION_MAJOR, STORAGE_VERSION_MINOR) >= (1, 4):
info["serial_number"] = self.unique_id
return info

@property
def entity_picture(self) -> str | None:
"""Return the entity picture to use in the frontend, if any."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/google_maps/gm_loc_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Sequence
from dataclasses import dataclass
from datetime import UTC, datetime
from functools import cached_property
from functools import cached_property # pylint: disable=hass-deprecated-import
from http.cookiejar import MozillaCookieJar
import json
import logging
Expand Down

0 comments on commit e8a36e7

Please sign in to comment.