Skip to content

Commit

Permalink
Simplify base entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Feb 11, 2023
1 parent acc118b commit 9daa431
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
3 changes: 3 additions & 0 deletions custom_components/integration_blueprint/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta

from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .api import IntegrationBlueprintApiClient
Expand All @@ -13,6 +14,8 @@
class BlueprintDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API."""

config_entry: ConfigEntry

def __init__(
self,
hass: HomeAssistant,
Expand Down
27 changes: 8 additions & 19 deletions custom_components/integration_blueprint/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,21 @@
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import ATTRIBUTION, DOMAIN, NAME, VERSION
from .coordinator import BlueprintDataUpdateCoordinator


class IntegrationBlueprintEntity(CoordinatorEntity):
def __init__(self, coordinator, config_entry):
super().__init__(coordinator)
self.config_entry = config_entry
"""BlueprintEntity class."""

@property
def unique_id(self):
"""Return a unique ID to use for this entity."""
return self.config_entry.entry_id
_attr_attribution = ATTRIBUTION

@property
def device_info(self):
return {
def __init__(self, coordinator: BlueprintDataUpdateCoordinator) -> None:
"""Initialize."""
super().__init__(coordinator)
self._attr_unique_id = coordinator.config_entry.entry_id
self._attr_device_info = {
"identifiers": {(DOMAIN, self.unique_id)},
"name": NAME,
"model": VERSION,
"manufacturer": NAME,
}

@property
def extra_state_attributes(self):
"""Return the state attributes."""
return {
"attribution": ATTRIBUTION,
"id": str(self.coordinator.data.get("id")),
"integration": DOMAIN,
}

0 comments on commit 9daa431

Please sign in to comment.