Fix mode_callerid attributes (#57774)

* Allow mode_callerid to display number only

* alphabetize

* tweak

* only include attr if there is data
This commit is contained in:
Robert Hillis 2021-10-17 08:53:18 -04:00 committed by GitHub
parent 85c6942f55
commit f5e2960a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,18 +106,13 @@ class ModemCalleridSensor(SensorEntity):
@callback
def _async_incoming_call(self, new_state) -> None:
"""Handle new states."""
if new_state == PhoneModem.STATE_RING:
if self.native_value == PhoneModem.STATE_IDLE:
self._attr_extra_state_attributes = {
CID.CID_NUMBER: "",
CID.CID_NAME: "",
}
elif new_state == PhoneModem.STATE_CALLERID:
self._attr_extra_state_attributes = {
CID.CID_NUMBER: self.api.cid_number,
CID.CID_NAME: self.api.cid_name,
}
self._attr_extra_state_attributes[CID.CID_TIME] = self.api.cid_time
self._attr_extra_state_attributes = {}
if self.api.cid_name:
self._attr_extra_state_attributes[CID.CID_NAME] = self.api.cid_name
if self.api.cid_number:
self._attr_extra_state_attributes[CID.CID_NUMBER] = self.api.cid_number
if self.api.cid_time:
self._attr_extra_state_attributes[CID.CID_TIME] = self.api.cid_time
self._attr_native_value = self.api.state
self.async_write_ha_state()