Skip to content

Commit 9275402

Browse files
WIP
1 parent d905369 commit 9275402

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

custom_components/battery_notes/sensor.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,29 @@ async def async_state_reported_listener(
397397
if not self.coordinator.wrapped_battery:
398398
return
399399

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+
400423
self.coordinator.last_reported = datetime.utcnow()
401424

402425
_LOGGER.debug(
@@ -407,6 +430,8 @@ async def async_state_reported_listener(
407430
await self.coordinator.async_request_refresh()
408431

409432
self._attr_available = True
433+
self._attr_native_value = self.coordinator.rounded_battery_level
434+
self._wrapped_attributes = wrapped_battery_state.attributes
410435

411436
self.async_write_ha_state()
412437

0 commit comments

Comments
 (0)