Add hass object on entity items

This commit is contained in:
2021-04-10 12:43:43 +02:00
parent af1df1cd84
commit bcaa4bf957
5 changed files with 34 additions and 20 deletions

View File

@@ -25,7 +25,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
odometer_switch_entities = []
for tracker in trackers:
entity = GeoRideOdometerSensorEntity(tracker.tracker_id, georide_context.get_token,
entity = GeoRideOdometerSensorEntity(hass, tracker.tracker_id, georide_context.get_token,
georide_context.get_tracker, data=tracker)
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
odometer_switch_entities.append(entity)
@@ -37,7 +37,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
class GeoRideOdometerSensorEntity(SwitchEntity):
"""Represent a tracked device."""
def __init__(self, tracker_id, get_token_callback, get_tracker_callback, data):
def __init__(self, hass, tracker_id, get_token_callback, get_tracker_callback, data):
"""Set up Georide entity."""
self._tracker_id = tracker_id
self._data = data or {}
@@ -48,6 +48,7 @@ class GeoRideOdometerSensorEntity(SwitchEntity):
self.entity_id = ENTITY_ID_FORMAT.format("odometer") + "." + str(tracker_id)
self._state = 0
self._hass = hass
async def async_update(self):