Fix LaCrosse View not updating (#79474)

This commit is contained in:
IceBotYT 2022-10-02 21:14:02 -04:00 committed by GitHub
parent da960f6ed4
commit d6a6d0d754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,7 +105,7 @@ async def async_setup_entry(
sensors: list[Sensor] = coordinator.data sensors: list[Sensor] = coordinator.data
sensor_list = [] sensor_list = []
for sensor in sensors: for i, sensor in enumerate(sensors):
for field in sensor.sensor_field_names: for field in sensor.sensor_field_names:
description = SENSOR_DESCRIPTIONS.get(field) description = SENSOR_DESCRIPTIONS.get(field)
if description is None: if description is None:
@ -125,6 +125,7 @@ async def async_setup_entry(
coordinator=coordinator, coordinator=coordinator,
description=description, description=description,
sensor=sensor, sensor=sensor,
index=i,
) )
) )
@ -144,6 +145,7 @@ class LaCrosseViewSensor(
description: LaCrosseSensorEntityDescription, description: LaCrosseSensorEntityDescription,
coordinator: DataUpdateCoordinator[list[Sensor]], coordinator: DataUpdateCoordinator[list[Sensor]],
sensor: Sensor, sensor: Sensor,
index: int,
) -> None: ) -> None:
"""Initialize.""" """Initialize."""
super().__init__(coordinator) super().__init__(coordinator)
@ -157,11 +159,11 @@ class LaCrosseViewSensor(
"model": sensor.model, "model": sensor.model,
"via_device": (DOMAIN, sensor.location.id), "via_device": (DOMAIN, sensor.location.id),
} }
self._sensor = sensor self.index = index
@property @property
def native_value(self) -> float | str: def native_value(self) -> float | str:
"""Return the sensor value.""" """Return the sensor value."""
return self.entity_description.value_fn( return self.entity_description.value_fn(
self._sensor, self.entity_description.key self.coordinator.data[self.index], self.entity_description.key
) )