Use assignment expressions [K-Z] (#66881)
parent
d76687d672
commit
6e49b0e122
|
@ -225,9 +225,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Load a config entry."""
|
||||
conf = hass.data.get(DATA_KNX_CONFIG)
|
||||
# `conf` is None when reloading the integration or no `knx` key in configuration.yaml
|
||||
if conf is None:
|
||||
if (conf := hass.data.get(DATA_KNX_CONFIG)) is None:
|
||||
_conf = await async_integration_yaml_config(hass, DOMAIN)
|
||||
if not _conf or DOMAIN not in _conf:
|
||||
_LOGGER.warning(
|
||||
|
|
|
@ -123,9 +123,7 @@ class DataUpdateCoordinatorMixin:
|
|||
|
||||
async def async_read_data(self, module_id: str, data_id: str) -> list[str, bool]:
|
||||
"""Write settings back to Plenticore."""
|
||||
client = self._plenticore.client
|
||||
|
||||
if client is None:
|
||||
if (client := self._plenticore.client) is None:
|
||||
return False
|
||||
|
||||
try:
|
||||
|
@ -137,9 +135,7 @@ class DataUpdateCoordinatorMixin:
|
|||
|
||||
async def async_write_data(self, module_id: str, value: dict[str, str]) -> bool:
|
||||
"""Write settings back to Plenticore."""
|
||||
client = self._plenticore.client
|
||||
|
||||
if client is None:
|
||||
if (client := self._plenticore.client) is None:
|
||||
return False
|
||||
|
||||
try:
|
||||
|
@ -272,9 +268,7 @@ class SelectDataUpdateCoordinator(
|
|||
"""Implementation of PlenticoreUpdateCoordinator for select data."""
|
||||
|
||||
async def _async_update_data(self) -> dict[str, dict[str, str]]:
|
||||
client = self._plenticore.client
|
||||
|
||||
if client is None:
|
||||
if self._plenticore.client is None:
|
||||
return {}
|
||||
|
||||
_LOGGER.debug("Fetching select %s for %s", self.name, self._fetch)
|
||||
|
|
|
@ -56,8 +56,7 @@ async def async_get_triggers(
|
|||
) -> list[dict[str, Any]]:
|
||||
"""List device triggers for LCN devices."""
|
||||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(device_id)
|
||||
if device is None:
|
||||
if (device := device_registry.async_get(device_id)) is None:
|
||||
return []
|
||||
|
||||
identifier = next(iter(device.identifiers))
|
||||
|
|
|
@ -152,8 +152,7 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity):
|
|||
# an educated guess.
|
||||
#
|
||||
meteo_data: MeteoSensor = self._meteo_coordinator.data
|
||||
current_temp = meteo_data.temperature
|
||||
if not current_temp:
|
||||
if not (current_temp := meteo_data.temperature):
|
||||
self._climate.hvac_mode = lookin_index.index(HVAC_MODE_AUTO)
|
||||
elif current_temp >= self._climate.temp_celsius:
|
||||
self._climate.hvac_mode = lookin_index.index(HVAC_MODE_COOL)
|
||||
|
|
|
@ -221,9 +221,7 @@ def _async_subscribe_pico_remote_events(
|
|||
|
||||
@callback
|
||||
def _async_button_event(button_id, event_type):
|
||||
device = button_devices_by_id.get(button_id)
|
||||
|
||||
if not device:
|
||||
if not (device := button_devices_by_id.get(button_id)):
|
||||
return
|
||||
|
||||
if event_type == BUTTON_STATUS_PRESSED:
|
||||
|
|
|
@ -101,8 +101,7 @@ class Alpha2Climate(CoordinatorEntity, ClimateEntity):
|
|||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
"""Set new target temperatures."""
|
||||
target_temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if target_temperature is None:
|
||||
if (target_temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
||||
await self.coordinator.async_set_target_temperature(
|
||||
|
|
|
@ -205,9 +205,8 @@ class MoldIndicator(SensorEntity):
|
|||
return None
|
||||
|
||||
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
temp = util.convert(state.state, float)
|
||||
|
||||
if temp is None:
|
||||
if (temp := util.convert(state.state, float)) is None:
|
||||
_LOGGER.error(
|
||||
"Unable to parse temperature sensor %s with state: %s",
|
||||
state.entity_id,
|
||||
|
|
|
@ -134,8 +134,7 @@ class MotionEyeMediaSource(MediaSource):
|
|||
def _get_device_or_raise(self, device_id: str) -> dr.DeviceEntry:
|
||||
"""Get a config entry from a URL."""
|
||||
device_registry = dr.async_get(self.hass)
|
||||
device = device_registry.async_get(device_id)
|
||||
if not device:
|
||||
if not (device := device_registry.async_get(device_id)):
|
||||
raise MediaSourceError(f"Unable to find device with id: {device_id}")
|
||||
return device
|
||||
|
||||
|
|
|
@ -356,8 +356,7 @@ class NestEventMediaThumbnailView(NestEventViewBase):
|
|||
async def handle_media(self, media: Media) -> web.StreamResponse:
|
||||
"""Start a GET request."""
|
||||
contents = media.contents
|
||||
content_type = media.content_type
|
||||
if content_type == "image/jpeg":
|
||||
if (content_type := media.content_type) == "image/jpeg":
|
||||
image = Image(media.event_image_type.content_type, contents)
|
||||
contents = img_util.scale_jpeg_camera_image(
|
||||
image, THUMBNAIL_SIZE_PX, THUMBNAIL_SIZE_PX
|
||||
|
|
|
@ -319,8 +319,7 @@ class NestFlowHandler(
|
|||
if user_input is not None and not errors:
|
||||
# Create the subscriber id and/or verify it already exists. Note that
|
||||
# the existing id is used, and create call below is idempotent
|
||||
subscriber_id = data.get(CONF_SUBSCRIBER_ID, "")
|
||||
if not subscriber_id:
|
||||
if not (subscriber_id := data.get(CONF_SUBSCRIBER_ID, "")):
|
||||
subscriber_id = _generate_subscription_id(cloud_project_id)
|
||||
_LOGGER.debug("Creating subscriber id '%s'", subscriber_id)
|
||||
# Create a placeholder ConfigEntry to use since with the auth we've already created.
|
||||
|
|
|
@ -134,8 +134,7 @@ class NestEventMediaStore(EventMediaStore):
|
|||
"""Load data."""
|
||||
if self._data is None:
|
||||
self._devices = await self._get_devices()
|
||||
data = await self._store.async_load()
|
||||
if data is None:
|
||||
if (data := await self._store.async_load()) is None:
|
||||
_LOGGER.debug("Loaded empty event store")
|
||||
self._data = {}
|
||||
elif isinstance(data, dict):
|
||||
|
|
|
@ -28,8 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
open_meteo = OpenMeteo(session=session)
|
||||
|
||||
async def async_update_forecast() -> Forecast:
|
||||
zone = hass.states.get(entry.data[CONF_ZONE])
|
||||
if zone is None:
|
||||
if (zone := hass.states.get(entry.data[CONF_ZONE])) is None:
|
||||
raise UpdateFailed(f"Zone '{entry.data[CONF_ZONE]}' not found")
|
||||
|
||||
try:
|
||||
|
|
|
@ -59,9 +59,7 @@ class PicnicUpdateCoordinator(DataUpdateCoordinator):
|
|||
def fetch_data(self):
|
||||
"""Fetch the data from the Picnic API and return a flat dict with only needed sensor data."""
|
||||
# Fetch from the API and pre-process the data
|
||||
cart = self.picnic_api_client.get_cart()
|
||||
|
||||
if not cart:
|
||||
if not (cart := self.picnic_api_client.get_cart()):
|
||||
raise UpdateFailed("API response doesn't contain expected data.")
|
||||
|
||||
last_order = self._get_last_order()
|
||||
|
|
|
@ -45,8 +45,7 @@ async def async_setup_services(hass: HomeAssistant) -> None:
|
|||
return
|
||||
|
||||
if call.service in [SERVICE_REBOOT, SERVICE_SHUTDOWN]:
|
||||
dsm_device = hass.data[DOMAIN].get(serial)
|
||||
if not dsm_device:
|
||||
if not (dsm_device := hass.data[DOMAIN].get(serial)):
|
||||
LOGGER.error("DSM with specified serial %s not found", serial)
|
||||
return
|
||||
LOGGER.debug("%s DSM with serial %s", call.service, serial)
|
||||
|
|
|
@ -144,8 +144,7 @@ class SaunaClimate(ToloSaunaCoordinatorEntity, ClimateEntity):
|
|||
|
||||
def set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set desired target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
||||
self.coordinator.client.set_target_temperature(round(temperature))
|
||||
|
|
|
@ -75,8 +75,7 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entities: list[Entity] = []
|
||||
|
||||
sensors = coordinator.client.get_sensor_list()
|
||||
if not sensors:
|
||||
if not (sensors := coordinator.client.get_sensor_list()):
|
||||
return
|
||||
|
||||
for sensor_name in sensors:
|
||||
|
|
|
@ -79,9 +79,7 @@ async def async_attach_trigger(
|
|||
automation_info: AutomationTriggerInfo,
|
||||
) -> CALLBACK_TYPE | None:
|
||||
"""Attach a trigger."""
|
||||
trigger_type = config[CONF_TYPE]
|
||||
|
||||
if trigger_type == TURN_ON_PLATFORM_TYPE:
|
||||
if (trigger_type := config[CONF_TYPE]) == TURN_ON_PLATFORM_TYPE:
|
||||
trigger_config = {
|
||||
CONF_PLATFORM: trigger_type,
|
||||
CONF_DEVICE_ID: config[CONF_DEVICE_ID],
|
||||
|
|
|
@ -20,9 +20,7 @@ def async_get_device_entry_by_device_id(
|
|||
Raises ValueError if device ID is invalid.
|
||||
"""
|
||||
device_reg = dr.async_get(hass)
|
||||
device = device_reg.async_get(device_id)
|
||||
|
||||
if device is None:
|
||||
if (device := device_reg.async_get(device_id)) is None:
|
||||
raise ValueError(f"Device {device_id} is not a valid {DOMAIN} device.")
|
||||
|
||||
return device
|
||||
|
|
|
@ -248,8 +248,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity):
|
|||
if maj_v and min_v:
|
||||
self._attr_device_info["sw_version"] = f"{maj_v}.{min_v}"
|
||||
|
||||
model = self._client.system_info.get("modelName")
|
||||
if model:
|
||||
if model := self._client.system_info.get("modelName"):
|
||||
self._attr_device_info["model"] = model
|
||||
|
||||
self._attr_extra_state_attributes = {}
|
||||
|
|
|
@ -333,8 +333,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity):
|
|||
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 is None:
|
||||
if (state := await self.async_get_last_state()) is None:
|
||||
return
|
||||
|
||||
self._state = state.state == "on"
|
||||
|
|
Loading…
Reference in New Issue