@@ -49,7 +49,12 @@ async def async_setup_entry(
4949 sensors = [
5050 MoonPhaseSensor (coordinator , config_entry ),
5151 MoonAgeSensor (
52- coordinator , config_entry , STATE_ATTR_AGE , "Moon Age" , "moon_age"
52+ coordinator ,
53+ config_entry ,
54+ STATE_ATTR_AGE ,
55+ "Moon Age" ,
56+ "moon_age" ,
57+ "mdi:progress-clock" ,
5358 ),
5459 MoonDistanceSensor (
5560 coordinator ,
@@ -219,6 +224,11 @@ class MoonTimestampSensor(MoonAttributeSensor):
219224
220225 _attr_device_class = SensorDeviceClass .TIMESTAMP
221226
227+ @callback
228+ def _handle_coordinator_update (self ) -> None :
229+ """Update sensor with latest data from coordinator."""
230+ self .async_write_ha_state ()
231+
222232 @property
223233 def native_value (self ):
224234 """Return the state of the sensor."""
@@ -236,16 +246,52 @@ class MoonDistanceSensor(MoonAttributeSensor):
236246 _attr_native_unit_of_measurement = UnitOfLength .KILOMETERS
237247 _attr_state_class = SensorStateClass .MEASUREMENT
238248
249+ @callback
250+ def _handle_coordinator_update (self ) -> None :
251+ """Update sensor with latest data from coordinator."""
252+ self .async_write_ha_state ()
253+
254+ @property
255+ def native_value (self ):
256+ """Return the state of the sensor."""
257+ attributes = self .coordinator .data .get ("attributes" , {})
258+ return attributes .get (self ._attribute )
259+
239260
240261class MoonAgeSensor (MoonAttributeSensor ):
241262 """Representation of a Moon Age sensor."""
242263
243- _attr_device_class = SensorDeviceClass . DURATION
264+ _attr_state_class = SensorStateClass . MEASUREMENT
244265 _attr_native_unit_of_measurement = UnitOfTime .DAYS
245266
267+ @callback
268+ def _handle_coordinator_update (self ) -> None :
269+ """Update sensor with latest data from coordinator."""
270+ self .async_write_ha_state ()
271+
272+ @property
273+ def native_value (self ):
274+ """Return the state of the sensor."""
275+ attributes = self .coordinator .data .get ("attributes" , {})
276+ value_in_days = attributes .get (self ._attribute )
277+ if value_in_days is not None :
278+ return round (value_in_days , 2 )
279+ return None
280+
246281
247282class MoonIlluminationFractionSensor (MoonAttributeSensor ):
248283 """Representation of a Moon Illumination Fraction sensor."""
249284
250285 _attr_native_unit_of_measurement = PERCENTAGE
251286 _attr_state_class = SensorStateClass .MEASUREMENT
287+
288+ @callback
289+ def _handle_coordinator_update (self ) -> None :
290+ """Update sensor with latest data from coordinator."""
291+ self .async_write_ha_state ()
292+
293+ @property
294+ def native_value (self ):
295+ """Return the state of the sensor."""
296+ attributes = self .coordinator .data .get ("attributes" , {})
297+ return attributes .get (self ._attribute )
0 commit comments