Use assignment expressions 05 (#57785)

This commit is contained in:
Marc Mueller 2021-10-17 19:56:00 +02:00 committed by GitHub
parent d09ee11c54
commit 5048bad050
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 36 additions and 71 deletions

View file

@ -215,8 +215,7 @@ class AmcrestBinarySensor(BinarySensorEntity):
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
return
event_code = self.entity_description.event_code
if event_code is None:
if (event_code := self.entity_description.event_code) is None:
_LOGGER.error("Binary sensor %s event code not set", self.name)
return
@ -228,12 +227,10 @@ class AmcrestBinarySensor(BinarySensorEntity):
def _update_unique_id(self) -> None:
"""Set the unique id."""
if self._attr_unique_id is None:
serial_number = self._api.serial_number
if serial_number:
self._attr_unique_id = (
f"{serial_number}-{self.entity_description.key}-{self._channel}"
)
if self._attr_unique_id is None and (serial_number := self._api.serial_number):
self._attr_unique_id = (
f"{serial_number}-{self.entity_description.key}-{self._channel}"
)
async def async_on_demand_update(self) -> None:
"""Update state."""