Skip to content

Commit

Permalink
wait for HA to load before retrieving name
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Sep 23, 2023
1 parent 230051f commit b40cc06
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/erse/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def __init__(self, hass, entry_id, tariff, meter_entity):

super().__init__(hass.data[DOMAIN][entry_id])

self._attr_name = hass.states.get(meter_entity).attributes.get("friendly_name")
self._attr_unique_id = slugify(f"{entry_id} {meter_entity} cost")

self._tariff = tariff
Expand Down Expand Up @@ -476,6 +475,7 @@ async def async_increment_cost(event):
@callback
async def initial_sync(_):
meter_state = self.hass.states.get(self._meter_entity)
self._attr_name = meter_state.attributes.get("friendly_name")
await calc_costs(meter_state)

self.async_on_remove(
Expand Down

0 comments on commit b40cc06

Please sign in to comment.