Use assignment expressions 32 (#58716)
This commit is contained in:
parent
a48ddcadd4
commit
887d04be60
16 changed files with 27 additions and 45 deletions
|
@ -240,9 +240,10 @@ class Counter(RestoreEntity):
|
|||
await super().async_added_to_hass()
|
||||
# __init__ will set self._state to self._initial, only override
|
||||
# if needed.
|
||||
if self._config[CONF_RESTORE]:
|
||||
state = await self.async_get_last_state()
|
||||
if state is not None:
|
||||
if (
|
||||
self._config[CONF_RESTORE]
|
||||
and (state := await self.async_get_last_state()) is not None
|
||||
):
|
||||
self._state = self.compute_next_state(int(state.state))
|
||||
self._config[CONF_INITIAL] = state.attributes.get(ATTR_INITIAL)
|
||||
self._config[CONF_MAXIMUM] = state.attributes.get(ATTR_MAXIMUM)
|
||||
|
|
|
@ -117,8 +117,7 @@ class ElkArea(ElkAttachedEntity, AlarmControlPanelEntity, RestoreEntity):
|
|||
self._element.add_callback(self._watch_area)
|
||||
|
||||
# We do not get changed_by back from resync.
|
||||
last_state = await self.async_get_last_state()
|
||||
if not last_state:
|
||||
if not (last_state := await self.async_get_last_state()):
|
||||
return
|
||||
|
||||
if ATTR_CHANGED_BY_KEYPAD in last_state.attributes:
|
||||
|
|
|
@ -102,8 +102,7 @@ class IncidentsSensor(RestoreEntity, SensorEntity):
|
|||
"""Run when about to be added to hass."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
self._state = state.state
|
||||
self._state_attributes = state.attributes
|
||||
if "id" in self._state_attributes:
|
||||
|
|
|
@ -421,9 +421,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||
_LOGGER.warning("Not connected with the supervisor / system too busy!")
|
||||
|
||||
store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
|
||||
data = await store.async_load()
|
||||
|
||||
if data is None:
|
||||
if (data := await store.async_load()) is None:
|
||||
data = {}
|
||||
|
||||
refresh_token = None
|
||||
|
|
|
@ -82,8 +82,7 @@ class AccessoryAidStorage:
|
|||
aidstore = get_aid_storage_filename_for_entry_id(self._entry)
|
||||
self.store = Store(self.hass, AID_MANAGER_STORAGE_VERSION, aidstore)
|
||||
|
||||
raw_storage = await self.store.async_load()
|
||||
if not raw_storage:
|
||||
if not (raw_storage := await self.store.async_load()):
|
||||
# There is no data about aid allocations yet
|
||||
return
|
||||
|
||||
|
|
|
@ -270,8 +270,7 @@ class InputDatetime(RestoreEntity):
|
|||
default_value = py_datetime.datetime.today().strftime("%Y-%m-%d 00:00:00")
|
||||
|
||||
# Priority 2: Old state
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is None:
|
||||
if (old_state := await self.async_get_last_state()) is None:
|
||||
self._current_datetime = dt_util.parse_datetime(default_value)
|
||||
return
|
||||
|
||||
|
|
|
@ -254,8 +254,7 @@ class BaseSwitch(BasePlatform, ToggleEntity, RestoreEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
self._attr_is_on = state.state == STATE_ON
|
||||
|
||||
async def async_turn(self, command: int) -> None:
|
||||
|
|
|
@ -41,8 +41,7 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
self._attr_is_on = state.state == STATE_ON
|
||||
|
||||
async def async_update(self, now: datetime | None = None) -> None:
|
||||
|
|
|
@ -100,8 +100,7 @@ class ModbusCover(BasePlatform, CoverEntity, RestoreEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
convert = {
|
||||
STATE_CLOSED: self._state_closed,
|
||||
STATE_CLOSING: self._state_closing,
|
||||
|
|
|
@ -53,8 +53,7 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
self._attr_native_value = state.state
|
||||
|
||||
async def async_update(self, now: datetime | None = None) -> None:
|
||||
|
|
|
@ -190,9 +190,7 @@ class MqttNumber(MqttEntity, NumberEntity, RestoreEntity):
|
|||
},
|
||||
)
|
||||
|
||||
if self._optimistic:
|
||||
last_state = await self.async_get_last_state()
|
||||
if last_state:
|
||||
if self._optimistic and (last_state := await self.async_get_last_state()):
|
||||
self._current_number = last_state.state
|
||||
|
||||
@property
|
||||
|
|
|
@ -157,9 +157,7 @@ class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
|||
},
|
||||
)
|
||||
|
||||
if self._optimistic:
|
||||
last_state = await self.async_get_last_state()
|
||||
if last_state:
|
||||
if self._optimistic and (last_state := await self.async_get_last_state()):
|
||||
self._attr_current_option = last_state.state
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
|
|
|
@ -145,9 +145,7 @@ class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
|||
},
|
||||
)
|
||||
|
||||
if self._optimistic:
|
||||
last_state = await self.async_get_last_state()
|
||||
if last_state:
|
||||
if self._optimistic and (last_state := await self.async_get_last_state()):
|
||||
self._state = last_state.state == STATE_ON
|
||||
|
||||
@property
|
||||
|
|
|
@ -66,8 +66,7 @@ class ElecPriceSensor(RestoreEntity, SensorEntity):
|
|||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
self._pvpc_data.state = state.state
|
||||
|
||||
# Update 'state' value in hour changes
|
||||
|
|
|
@ -92,7 +92,6 @@ class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
|||
if self.coordinator.last_update_success:
|
||||
return
|
||||
|
||||
last_state = await self.async_get_last_state()
|
||||
if last_state:
|
||||
if last_state := await self.async_get_last_state():
|
||||
self._state = last_state.state
|
||||
self._available = True
|
||||
|
|
|
@ -206,8 +206,7 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
|||
|
||||
if not self.zha_device.is_mains_powered:
|
||||
# mains powered devices will get real time state
|
||||
last_state = await self.async_get_last_state()
|
||||
if last_state:
|
||||
if last_state := await self.async_get_last_state():
|
||||
self.async_restore_last_state(last_state)
|
||||
|
||||
self.async_accept_signal(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue