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