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:
@@ -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 消息处理回调
|
||||
@@ -455,6 +457,8 @@ class JackeryHomeSensor(SensorEntity):
|
||||
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]:
|
||||
"""Return the state attributes."""
|
||||
|
||||
Reference in New Issue
Block a user