mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add DeviceInfo to Bring integration (#122419)
* Add DeviceInfo to Bring integration * deeplink to shopping list * Move device info to a entity base class
This commit is contained in:
parent
1ffd797e0a
commit
5b434aae6e
37
homeassistant/components/bring/entity.py
Normal file
37
homeassistant/components/bring/entity.py
Normal file
@ -0,0 +1,37 @@
|
||||
"""Base entity for the Bring! integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import BringData, BringDataUpdateCoordinator
|
||||
|
||||
|
||||
class BringBaseEntity(CoordinatorEntity[BringDataUpdateCoordinator]):
|
||||
"""Bring base entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: BringDataUpdateCoordinator,
|
||||
bring_list: BringData,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._list_uuid = bring_list["listUuid"]
|
||||
self._attr_unique_id = f"{coordinator.config_entry.unique_id}_{self._list_uuid}"
|
||||
|
||||
self.device_info = DeviceInfo(
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
name=bring_list["name"],
|
||||
identifiers={
|
||||
(DOMAIN, f"{coordinator.config_entry.unique_id}_{self._list_uuid}")
|
||||
},
|
||||
manufacturer="Bring! Labs AG",
|
||||
model="Bring! Grocery Shopping List",
|
||||
configuration_url=f"https://web.getbring.com/app/lists/{list(self.coordinator.data.keys()).index(self._list_uuid)}",
|
||||
)
|
@ -23,7 +23,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import BringConfigEntry
|
||||
from .const import (
|
||||
@ -32,7 +31,8 @@ from .const import (
|
||||
DOMAIN,
|
||||
SERVICE_PUSH_NOTIFICATION,
|
||||
)
|
||||
from .coordinator import BringData, BringDataUpdateCoordinator
|
||||
from .coordinator import BringData
|
||||
from .entity import BringBaseEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -43,16 +43,10 @@ async def async_setup_entry(
|
||||
"""Set up the sensor from a config entry created in the integrations UI."""
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
unique_id = config_entry.unique_id
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert unique_id
|
||||
|
||||
async_add_entities(
|
||||
BringTodoListEntity(
|
||||
coordinator,
|
||||
bring_list=bring_list,
|
||||
unique_id=unique_id,
|
||||
)
|
||||
for bring_list in coordinator.data.values()
|
||||
)
|
||||
@ -71,13 +65,11 @@ async def async_setup_entry(
|
||||
)
|
||||
|
||||
|
||||
class BringTodoListEntity(
|
||||
CoordinatorEntity[BringDataUpdateCoordinator], TodoListEntity
|
||||
):
|
||||
class BringTodoListEntity(BringBaseEntity, TodoListEntity):
|
||||
"""A To-do List representation of the Bring! Shopping List."""
|
||||
|
||||
_attr_translation_key = "shopping_list"
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = None
|
||||
_attr_supported_features = (
|
||||
TodoListEntityFeature.CREATE_TODO_ITEM
|
||||
| TodoListEntityFeature.UPDATE_TODO_ITEM
|
||||
@ -85,18 +77,6 @@ class BringTodoListEntity(
|
||||
| TodoListEntityFeature.SET_DESCRIPTION_ON_ITEM
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: BringDataUpdateCoordinator,
|
||||
bring_list: BringData,
|
||||
unique_id: str,
|
||||
) -> None:
|
||||
"""Initialize BringTodoListEntity."""
|
||||
super().__init__(coordinator)
|
||||
self._list_uuid = bring_list["listUuid"]
|
||||
self._attr_name = bring_list["name"]
|
||||
self._attr_unique_id = f"{unique_id}_{self._list_uuid}"
|
||||
|
||||
@property
|
||||
def todo_items(self) -> list[TodoItem]:
|
||||
"""Return the todo items."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user