Skip to content

Commit

Permalink
Merge pull request #13 from bkeiren/add_entities_to_config_entry
Browse files Browse the repository at this point in the history
Set _attr_unique_id on AttractionSensor
  • Loading branch information
danielsmith-eu authored Jun 18, 2024
2 parents 4282b45 + bbff08b commit 3e10f8e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/themeparks/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
DataUpdateCoordinator,
)

from .const import DOMAIN, NAME, TIME
from .const import DOMAIN, NAME, TIME, ID

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,7 +31,7 @@ async def async_setup_entry(
"""Set up the sensor platform."""

my_api = hass.data[DOMAIN][config_entry.entry_id]
coordinator = ThemeParksCoordinator(hass, my_api)
coordinator = ThemeParksCoordinator(hass, my_api, config_entry.entry_id)

await coordinator.async_config_entry_first_refresh()

Expand All @@ -56,6 +56,7 @@ def __init__(self, coordinator, idx):
self._attr_device_class = SensorDeviceClass.DURATION
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_native_value = self.coordinator.data[self.idx][TIME]
self._attr_unique_id = f"{coordinator.entry_id}_{coordinator.data[idx][ID]}"

_LOGGER.debug("Adding AttractionSensor called %s", self._attr_name)

Expand All @@ -75,7 +76,7 @@ def _handle_coordinator_update(self) -> None:
class ThemeParksCoordinator(DataUpdateCoordinator):
"""Theme parks coordinator."""

def __init__(self, hass, api):
def __init__(self, hass, api, entry_id):
"""Initialize theme parks coordinator."""
super().__init__(
hass,
Expand All @@ -84,6 +85,7 @@ def __init__(self, hass, api):
update_interval=timedelta(minutes=5),
)
self.api = api
self.entry_id = entry_id

async def _async_update_data(self):
"""Fetch data from API endpoint."""
Expand Down

0 comments on commit 3e10f8e

Please sign in to comment.