Skip to content

Commit

Permalink
Merge pull request #185 from YorkshireIoT/109-multiple-accounts-shown…
Browse files Browse the repository at this point in the history
…-together-in-device-view

109 multiple accounts shown together in device view
  • Loading branch information
YorkshireIoT authored Feb 8, 2024
2 parents 037768e + 18c470e commit ca8d1f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions custom_components/google_fit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OAuth2Session,
async_get_config_entry_implementation,
)
from homeassistant.helpers.device_registry import DeviceEntry

from .coordinator import Coordinator

Expand Down Expand Up @@ -79,3 +80,10 @@ async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry)


async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
) -> bool:
"""Remove Google Fit config entry."""
return True
19 changes: 14 additions & 5 deletions custom_components/google_fit/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.exceptions import InvalidStateError

from .const import DOMAIN, NAME, MANUFACTURER
from .coordinator import Coordinator
Expand All @@ -14,8 +15,16 @@ class GoogleFitEntity(CoordinatorEntity):
def __init__(self, coordinator: Coordinator) -> None:
"""Initialise."""
super().__init__(coordinator)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.unique_id)}, # type: ignore
name=NAME,
manufacturer=MANUFACTURER,
)
if coordinator.config_entry and coordinator.config_entry.unique_id:
email = coordinator.config_entry.unique_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, email)},
name=f"{NAME} - {email}",
manufacturer=MANUFACTURER,
model="fitness",
sw_version="v1",
)
else:
raise InvalidStateError(
"Unexpected exception. Trying to initialise entity but config entry is None."
)

0 comments on commit ca8d1f4

Please sign in to comment.