File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
custom_components/battery_notes Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -397,6 +397,29 @@ async def async_state_reported_listener(
397
397
if not self .coordinator .wrapped_battery :
398
398
return
399
399
400
+ if (
401
+ (
402
+ wrapped_battery_state := self .hass .states .get (
403
+ self .coordinator .wrapped_battery .entity_id
404
+ )
405
+ )
406
+ is None
407
+ or wrapped_battery_state .state
408
+ in [
409
+ STATE_UNAVAILABLE ,
410
+ STATE_UNKNOWN ,
411
+ ]
412
+ or not validate_is_float (wrapped_battery_state .state )
413
+ ):
414
+ self ._attr_native_value = None
415
+ self ._attr_available = False
416
+ self .async_write_ha_state ()
417
+ return
418
+
419
+ self .coordinator .current_battery_level = wrapped_battery_state .state
420
+
421
+ await self .coordinator .async_request_refresh ()
422
+
400
423
self .coordinator .last_reported = datetime .utcnow ()
401
424
402
425
_LOGGER .debug (
@@ -407,6 +430,8 @@ async def async_state_reported_listener(
407
430
await self .coordinator .async_request_refresh ()
408
431
409
432
self ._attr_available = True
433
+ self ._attr_native_value = self .coordinator .rounded_battery_level
434
+ self ._wrapped_attributes = wrapped_battery_state .attributes
410
435
411
436
self .async_write_ha_state ()
412
437
You can’t perform that action at this time.
0 commit comments