From 708b6c52eba7d2bb853005a5acb6ce6ad11ffa7a Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Sat, 14 Jan 2023 15:32:58 -0800 Subject: [PATCH] fix: update coordinator callback to update sensors closes #1834 closes #1833 --- custom_components/alexa_media/sensor.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/custom_components/alexa_media/sensor.py b/custom_components/alexa_media/sensor.py index c1451393..4b341772 100644 --- a/custom_components/alexa_media/sensor.py +++ b/custom_components/alexa_media/sensor.py @@ -17,6 +17,7 @@ SensorStateClass, ) from homeassistant.const import UnitOfTemperature, __version__ as HA_VERSION +from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryNotReady, NoEntitySpecifiedError from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.event import async_track_point_in_utc_time @@ -266,6 +267,14 @@ def __init__(self, coordinator, entity_id, name, media_player_device_id): else None ) + @callback + def _handle_coordinator_update(self) -> None: + """Handle updated data from the coordinator.""" + self._attr_native_value = parse_temperature_from_coordinator( + self.coordinator, self.alexa_entity_id + ) + super()._handle_coordinator_update() + class AirQualitySensor(SensorEntity, CoordinatorEntity): """A air quality sensor reported by an Amazon indoor air quality monitor.""" @@ -307,6 +316,15 @@ def __init__( if media_player_device_id else None ) + self._instance = instance + + @callback + def _handle_coordinator_update(self) -> None: + """Handle updated data from the coordinator.""" + self._attr_native_value = parse_air_quality_from_coordinator( + self.coordinator, self.alexa_entity_id, self._instance + ) + super()._handle_coordinator_update() class AlexaMediaNotificationSensor(SensorEntity):