mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Use assignment expressions 33 (#58717)
This commit is contained in:
parent
b1d49b3b66
commit
7063c05127
@ -64,8 +64,7 @@ class AbstractConfig(ABC):
|
||||
|
||||
async def async_disable_proactive_mode(self):
|
||||
"""Disable proactive mode."""
|
||||
unsub_func = await self._unsub_proactive_report
|
||||
if unsub_func:
|
||||
if unsub_func := await self._unsub_proactive_report:
|
||||
unsub_func()
|
||||
self._unsub_proactive_report = None
|
||||
|
||||
|
@ -119,8 +119,7 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
|
||||
"""Restore ATTR_CHANGED_BY on startup since it is likely no longer in the activity log."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
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 in last_state.attributes:
|
||||
|
@ -262,8 +262,7 @@ async def async_setup(hass, config):
|
||||
|
||||
async def reload_service_handler(service_call):
|
||||
"""Remove all automations and load new ones from config."""
|
||||
conf = await component.async_prepare_reload()
|
||||
if conf is None:
|
||||
if (conf := await component.async_prepare_reload()) is None:
|
||||
return
|
||||
async_get_blueprints(hass).async_reset_cache()
|
||||
await _async_process_config(hass, conf, component)
|
||||
@ -392,8 +391,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
|
||||
)
|
||||
self.action_script.update_logger(self._logger)
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
if state := await self.async_get_last_state():
|
||||
enable_automation = state.state == STATE_ON
|
||||
last_triggered = state.attributes.get("last_triggered")
|
||||
if last_triggered is not None:
|
||||
|
@ -40,9 +40,7 @@ class CameraPreferences:
|
||||
|
||||
async def async_initialize(self) -> None:
|
||||
"""Finish initializing the preferences."""
|
||||
prefs = await self._store.async_load()
|
||||
|
||||
if prefs is None:
|
||||
if (prefs := await self._store.async_load()) is None:
|
||||
prefs = {}
|
||||
|
||||
self._prefs = prefs
|
||||
|
@ -54,9 +54,7 @@ class CloudPreferences:
|
||||
|
||||
async def async_initialize(self):
|
||||
"""Finish initializing the preferences."""
|
||||
prefs = await self._store.async_load()
|
||||
|
||||
if prefs is None:
|
||||
if (prefs := await self._store.async_load()) is None:
|
||||
prefs = self._empty_config("")
|
||||
|
||||
self._prefs = prefs
|
||||
|
@ -122,8 +122,7 @@ class DerivativeSensor(RestoreEntity, SensorEntity):
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state is not None:
|
||||
if (state := await self.async_get_last_state()) is not None:
|
||||
try:
|
||||
self._state = Decimal(state.state)
|
||||
except SyntaxError as err:
|
||||
|
@ -788,8 +788,7 @@ class Device(RestoreEntity):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Add an entity."""
|
||||
await super().async_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if not state:
|
||||
if not (state := await self.async_get_last_state()):
|
||||
return
|
||||
self._state = state.state
|
||||
self.last_update_home = state.state == STATE_HOME
|
||||
|
@ -240,8 +240,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
|
||||
|
||||
# Check If we have an old state
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
if (old_state := await self.async_get_last_state()) is not None:
|
||||
# If we have no initial temperature, restore
|
||||
if self._target_temp is None:
|
||||
# If we have a previously saved temperature
|
||||
|
@ -106,9 +106,7 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
|
||||
if self._attributes:
|
||||
return
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
|
||||
if state is None:
|
||||
if (state := await self.async_get_last_state()) is None:
|
||||
self._gps = (None, None)
|
||||
return
|
||||
|
||||
|
@ -346,8 +346,7 @@ class GoogleConfigStore:
|
||||
|
||||
async def async_load(self):
|
||||
"""Store current configuration to disk."""
|
||||
data = await self._store.async_load()
|
||||
if data:
|
||||
if data := await self._store.async_load():
|
||||
self._data = data
|
||||
|
||||
|
||||
|
@ -132,8 +132,7 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
|
||||
if self._location is not None:
|
||||
return
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
if state is None:
|
||||
if (state := await self.async_get_last_state()) is None:
|
||||
self._location = (None, None)
|
||||
self._accuracy = None
|
||||
self._attributes = {
|
||||
|
@ -224,8 +224,7 @@ async def async_setup(hass, config):
|
||||
"""Remove all user-defined groups and load new ones from config."""
|
||||
auto = list(filter(lambda e: not e.user_defined, component.entities))
|
||||
|
||||
conf = await component.async_prepare_reload()
|
||||
if conf is None:
|
||||
if (conf := await component.async_prepare_reload()) is None:
|
||||
return
|
||||
await _async_process_config(hass, conf, component)
|
||||
|
||||
|
@ -34,8 +34,7 @@ class EntityMapStorage:
|
||||
|
||||
async def async_initialize(self):
|
||||
"""Get the pairing cache data."""
|
||||
raw_storage = await self.store.async_load()
|
||||
if not raw_storage:
|
||||
if not (raw_storage := await self.store.async_load()):
|
||||
# There is no cached data about HomeKit devices yet
|
||||
return
|
||||
|
||||
|
@ -37,8 +37,7 @@ PLATFORMS = "sensor", "binary_sensor", "device_tracker"
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the mobile app component."""
|
||||
store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
|
||||
app_config = await store.async_load()
|
||||
if app_config is None:
|
||||
if (app_config := await store.async_load()) is None:
|
||||
app_config = {
|
||||
DATA_CONFIG_ENTRIES: {},
|
||||
DATA_DELETED_IDS: [],
|
||||
|
@ -119,9 +119,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
||||
if self._data is not None:
|
||||
return
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
|
||||
if state is None:
|
||||
if (state := await self.async_get_last_state()) is None:
|
||||
self._data = {}
|
||||
return
|
||||
|
||||
|
@ -44,9 +44,8 @@ class MobileAppEntity(RestoreEntity):
|
||||
self.hass, SIGNAL_SENSOR_UPDATE, self._handle_update
|
||||
)
|
||||
)
|
||||
state = await self.async_get_last_state()
|
||||
|
||||
if state is None:
|
||||
if (state := await self.async_get_last_state()) is None:
|
||||
return
|
||||
|
||||
self.async_restore_last_state(state)
|
||||
|
@ -50,9 +50,7 @@ def async_is_user_onboarded(hass):
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the onboarding component."""
|
||||
store = OnboadingStorage(hass, STORAGE_VERSION, STORAGE_KEY, private=True)
|
||||
data = await store.async_load()
|
||||
|
||||
if data is None:
|
||||
if (data := await store.async_load()) is None:
|
||||
data = {"done": []}
|
||||
|
||||
if STEP_USER not in data["done"]:
|
||||
|
@ -580,9 +580,7 @@ class SwitchableRflinkDevice(RflinkCommand, RestoreEntity):
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFLink device state (ON/OFF)."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
if (old_state := await self.async_get_last_state()) is not None:
|
||||
self._state = old_state.state == STATE_ON
|
||||
|
||||
def _handle_event(self, event):
|
||||
|
@ -117,9 +117,7 @@ class RflinkCover(RflinkCommand, CoverEntity, RestoreEntity):
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFLink cover state (OPEN/CLOSE)."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
if (old_state := await self.async_get_last_state()) is not None:
|
||||
self._state = old_state.state == STATE_OPEN
|
||||
|
||||
def _handle_event(self, event):
|
||||
|
@ -172,8 +172,7 @@ async def async_setup(hass, config):
|
||||
|
||||
async def reload_service(service):
|
||||
"""Call a service to reload scripts."""
|
||||
conf = await component.async_prepare_reload()
|
||||
if conf is None:
|
||||
if (conf := await component.async_prepare_reload()) is None:
|
||||
return
|
||||
|
||||
await _async_process_config(hass, conf, component)
|
||||
|
@ -106,9 +106,7 @@ class UnifiWirelessClients:
|
||||
|
||||
async def async_load(self):
|
||||
"""Load data from file."""
|
||||
data = await self._store.async_load()
|
||||
|
||||
if data is not None:
|
||||
if (data := await self._store.async_load()) is not None:
|
||||
self.data = data
|
||||
|
||||
@callback
|
||||
|
Loading…
x
Reference in New Issue
Block a user