refactor: enhance sensor lifecycle management in JackeryHome component

- Added calls to `super().async_added_to_hass()` and `super().async_will_remove_from_hass()` for improved lifecycle handling.
- Ensured proper logging during sensor addition and removal from Home Assistant.
This commit is contained in:
不求圣剑
2025-11-18 16:33:03 +08:00
parent 27d7a0b7ee
commit d92fb9781a

View File

@@ -315,6 +315,8 @@ class JackeryHomeSensor(SensorEntity):
async def async_added_to_hass(self) -> None:
"""Set up the sensor."""
await super().async_added_to_hass()
_LOGGER.info(f"JackeryHome sensor {self._sensor_id} added to Home Assistant")
# 创建 LWT 消息处理回调
@@ -454,6 +456,8 @@ class JackeryHomeSensor(SensorEntity):
except asyncio.CancelledError:
pass
_LOGGER.info(f"JackeryHome sensor {self._sensor_id} removed from Home Assistant")
await super().async_will_remove_from_hass()
@property
def extra_state_attributes(self) -> dict[str, Any]: