mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use assignment expressions 17 (#57963)
Co-authored-by: Tobias Sauerwein <cgtobi@users.noreply.github.com>
This commit is contained in:
parent
326a302c22
commit
9a58bfdf41
@ -130,8 +130,7 @@ class CompensationSensor(SensorEntity):
|
||||
@callback
|
||||
def _async_compensation_sensor_state_listener(self, event):
|
||||
"""Handle sensor state changes."""
|
||||
new_state = event.data.get("new_state")
|
||||
if new_state is None:
|
||||
if (new_state := event.data.get("new_state")) is None:
|
||||
return
|
||||
|
||||
if self._unit_of_measurement is None and self._source_attribute is None:
|
||||
|
@ -76,9 +76,7 @@ class iOSNotificationService(BaseNotificationService):
|
||||
):
|
||||
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
||||
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
if not targets:
|
||||
if not (targets := kwargs.get(ATTR_TARGET)):
|
||||
targets = ios.enabled_push_ids(self.hass)
|
||||
|
||||
if kwargs.get(ATTR_DATA) is not None:
|
||||
|
@ -146,8 +146,7 @@ async def item_payload(item, get_thumbnail_url=None):
|
||||
elif "channelid" in item:
|
||||
media_content_type = MEDIA_TYPE_CHANNEL
|
||||
media_content_id = f"{item['channelid']}"
|
||||
broadcasting = item.get("broadcastnow")
|
||||
if broadcasting:
|
||||
if broadcasting := item.get("broadcastnow"):
|
||||
show = broadcasting.get("title")
|
||||
title = f"{title} - {show}"
|
||||
can_play = True
|
||||
|
@ -57,8 +57,7 @@ async def validate_http(hass: core.HomeAssistant, data):
|
||||
|
||||
async def validate_ws(hass: core.HomeAssistant, data):
|
||||
"""Validate the user input allows us to connect over WS."""
|
||||
ws_port = data.get(CONF_WS_PORT)
|
||||
if not ws_port:
|
||||
if not (ws_port := data.get(CONF_WS_PORT)):
|
||||
return
|
||||
|
||||
host = data[CONF_HOST]
|
||||
@ -105,8 +104,7 @@ class KodiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._host = discovery_info["host"]
|
||||
self._port = int(discovery_info["port"])
|
||||
self._name = discovery_info["hostname"][: -len(".local.")]
|
||||
uuid = discovery_info["properties"].get("uuid")
|
||||
if not uuid:
|
||||
if not (uuid := discovery_info["properties"].get("uuid")):
|
||||
return self.async_abort(reason="no_uuid")
|
||||
|
||||
self._discovery_name = discovery_info["name"]
|
||||
|
@ -533,9 +533,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
if self._properties.get("live"):
|
||||
return None
|
||||
|
||||
total_time = self._properties.get("totaltime")
|
||||
|
||||
if total_time is None:
|
||||
if (total_time := self._properties.get("totaltime")) is None:
|
||||
return None
|
||||
|
||||
return (
|
||||
@ -547,9 +545,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
@property
|
||||
def media_position(self):
|
||||
"""Position of current playing media in seconds."""
|
||||
time = self._properties.get("time")
|
||||
|
||||
if time is None:
|
||||
if (time := self._properties.get("time")) is None:
|
||||
return None
|
||||
|
||||
return time["hours"] * 3600 + time["minutes"] * 60 + time["seconds"]
|
||||
@ -562,8 +558,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
@property
|
||||
def media_image_url(self):
|
||||
"""Image url of current playing media."""
|
||||
thumbnail = self._item.get("thumbnail")
|
||||
if thumbnail is None:
|
||||
if (thumbnail := self._item.get("thumbnail")) is None:
|
||||
return None
|
||||
|
||||
return self._kodi.thumbnail_url(thumbnail)
|
||||
@ -598,8 +593,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
@property
|
||||
def media_artist(self):
|
||||
"""Artist of current playing media, music track only."""
|
||||
artists = self._item.get("artist", [])
|
||||
if artists:
|
||||
if artists := self._item.get("artist"):
|
||||
return artists[0]
|
||||
|
||||
return None
|
||||
@ -607,8 +601,7 @@ class KodiEntity(MediaPlayerEntity):
|
||||
@property
|
||||
def media_album_artist(self):
|
||||
"""Album artist of current playing media, music track only."""
|
||||
artists = self._item.get("albumartist", [])
|
||||
if artists:
|
||||
if artists := self._item.get("albumartist"):
|
||||
return artists[0]
|
||||
|
||||
return None
|
||||
|
@ -66,13 +66,11 @@ class LinksysSmartWifiDeviceScanner(DeviceScanner):
|
||||
result = data["responses"][0]
|
||||
devices = result["output"]["devices"]
|
||||
for device in devices:
|
||||
macs = device["knownMACAddresses"]
|
||||
if not macs:
|
||||
if not (macs := device["knownMACAddresses"]):
|
||||
_LOGGER.warning("Skipping device without known MAC address")
|
||||
continue
|
||||
mac = macs[-1]
|
||||
connections = device["connections"]
|
||||
if not connections:
|
||||
if not device["connections"]:
|
||||
_LOGGER.debug("Device %s is not connected", mac)
|
||||
continue
|
||||
|
||||
|
@ -123,9 +123,7 @@ class LovelaceStorage(LovelaceConfig):
|
||||
if self._data is None:
|
||||
await self._load()
|
||||
|
||||
config = self._data["config"]
|
||||
|
||||
if config is None:
|
||||
if (config := self._data["config"]) is None:
|
||||
raise ConfigNotFound
|
||||
|
||||
return config
|
||||
|
@ -183,8 +183,7 @@ class QueueListener(threading.Thread):
|
||||
"""Listen to queue events, and forward them to Home Assistant event bus."""
|
||||
_LOGGER.info("Running QueueListener")
|
||||
while True:
|
||||
event = self._queue.get()
|
||||
if event is None:
|
||||
if (event := self._queue.get()) is None:
|
||||
break
|
||||
|
||||
_, file_name = os.path.split(event[ATTR_KEY])
|
||||
|
@ -109,9 +109,8 @@ async def async_setup_entry(
|
||||
discovery_info = config_entry.data
|
||||
|
||||
def get_sensor_description(type_string: str):
|
||||
description = SENSOR_TYPES_DICT.get(type_string)
|
||||
if description is None:
|
||||
description = BinarySensorEntityDescription(key=type_string)
|
||||
if (description := SENSOR_TYPES_DICT.get(type_string)) is None:
|
||||
return BinarySensorEntityDescription(key=type_string)
|
||||
return description
|
||||
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
|
@ -386,9 +386,8 @@ class OptionsFlow(config_entries.OptionsFlow):
|
||||
def _can_replace_device(self, entry_id):
|
||||
"""Check if device can be replaced with selected device."""
|
||||
device_data = self._get_device_data(entry_id)
|
||||
event_code = device_data[CONF_EVENT_CODE]
|
||||
|
||||
if event_code is not None:
|
||||
if (event_code := device_data[CONF_EVENT_CODE]) is not None:
|
||||
rfx_obj = get_rfx_object(event_code)
|
||||
if (
|
||||
rfx_obj.device.packettype
|
||||
@ -452,8 +451,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
user_selection = user_input[CONF_TYPE]
|
||||
if user_selection == "Serial":
|
||||
if user_input[CONF_TYPE] == "Serial":
|
||||
return await self.async_step_setup_serial()
|
||||
|
||||
return await self.async_step_setup_network()
|
||||
|
@ -305,11 +305,11 @@ class RfxtrxSensor(RfxtrxEntity, SensorEntity):
|
||||
"""Restore device state."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
if self._event is None:
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
event = old_state.attributes.get(ATTR_EVENT)
|
||||
if event:
|
||||
if (
|
||||
self._event is None
|
||||
and (old_state := await self.async_get_last_state()) is not None
|
||||
and (event := old_state.attributes.get(ATTR_EVENT))
|
||||
):
|
||||
self._apply_event(get_rfx_object(event))
|
||||
|
||||
@property
|
||||
|
@ -147,8 +147,7 @@ class StatisticsSensor(SensorEntity):
|
||||
@callback
|
||||
def async_stats_sensor_state_listener(event):
|
||||
"""Handle the sensor state changes."""
|
||||
new_state = event.data.get("new_state")
|
||||
if new_state is None:
|
||||
if (new_state := event.data.get("new_state")) is None:
|
||||
return
|
||||
|
||||
self._unit_of_measurement = new_state.attributes.get(
|
||||
|
@ -112,8 +112,7 @@ class SynologySrmDeviceScanner(DeviceScanner):
|
||||
if not device:
|
||||
return filtered_attributes
|
||||
for attribute, alias in ATTRIBUTE_ALIAS.items():
|
||||
value = device.get(attribute)
|
||||
if value is None:
|
||||
if (value := device.get(attribute)) is None:
|
||||
continue
|
||||
attr = alias or attribute
|
||||
filtered_attributes[attr] = value
|
||||
|
@ -247,8 +247,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
||||
|
||||
# Handle global detection area
|
||||
self._area = [0, 0, 1, 1]
|
||||
area_config = model_config.get(CONF_AREA)
|
||||
if area_config:
|
||||
if area_config := model_config.get(CONF_AREA):
|
||||
self._area = [
|
||||
area_config.get(CONF_TOP),
|
||||
area_config.get(CONF_LEFT),
|
||||
@ -334,8 +333,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
||||
|
||||
def process_image(self, image):
|
||||
"""Process the image."""
|
||||
model = self.hass.data[DOMAIN][CONF_MODEL]
|
||||
if not model:
|
||||
if not (model := self.hass.data[DOMAIN][CONF_MODEL]):
|
||||
_LOGGER.debug("Model not yet ready")
|
||||
return
|
||||
|
||||
|
@ -115,9 +115,8 @@ class XBeeConfig:
|
||||
If an address has been provided, unhexlify it, otherwise return None
|
||||
as we're talking to our local XBee device.
|
||||
"""
|
||||
address = self._config.get("address")
|
||||
if address is not None:
|
||||
address = unhexlify(address)
|
||||
if (address := self._config.get("address")) is not None:
|
||||
return unhexlify(address)
|
||||
return address
|
||||
|
||||
@property
|
||||
|
Loading…
x
Reference in New Issue
Block a user