mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Add sensor attributes restore to modem_callerid integration (#147753)
This commit is contained in:
parent
8ef6b62d9a
commit
11c75d7ef2
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from phone_modem import PhoneModem
|
from phone_modem import PhoneModem
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import RestoreSensor
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_IDLE
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, STATE_IDLE
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
@ -40,7 +40,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ModemCalleridSensor(SensorEntity):
|
class ModemCalleridSensor(RestoreSensor):
|
||||||
"""Implementation of USB modem caller ID sensor."""
|
"""Implementation of USB modem caller ID sensor."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
@ -62,9 +62,21 @@ class ModemCalleridSensor(SensorEntity):
|
|||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when the modem sensor is added to Home Assistant."""
|
"""Call when the modem sensor is added to Home Assistant."""
|
||||||
self.api.registercallback(self._async_incoming_call)
|
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
|
if (last_state := await self.async_get_last_state()) is not None:
|
||||||
|
self._attr_extra_state_attributes[CID.CID_NAME] = last_state.attributes.get(
|
||||||
|
CID.CID_NAME, ""
|
||||||
|
)
|
||||||
|
self._attr_extra_state_attributes[CID.CID_NUMBER] = (
|
||||||
|
last_state.attributes.get(CID.CID_NUMBER, "")
|
||||||
|
)
|
||||||
|
self._attr_extra_state_attributes[CID.CID_TIME] = last_state.attributes.get(
|
||||||
|
CID.CID_TIME, 0
|
||||||
|
)
|
||||||
|
|
||||||
|
self.api.registercallback(self._async_incoming_call)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_incoming_call(self, new_state: str) -> None:
|
def _async_incoming_call(self, new_state: str) -> None:
|
||||||
"""Handle new states."""
|
"""Handle new states."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user