1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Use assignment expressions 16 (#57962)

This commit is contained in:
Marc Mueller 2021-10-19 04:36:35 +02:00 committed by GitHub
parent 2bae113748
commit 9561c51276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 29 additions and 57 deletions

View File

@ -154,8 +154,7 @@ class Doods(ImageProcessingEntity):
continue
# If label confidence is not specified, use global confidence
label_confidence = label.get(CONF_CONFIDENCE)
if not label_confidence:
if not (label_confidence := label.get(CONF_CONFIDENCE)):
label_confidence = confidence
if label_name not in dconfig or dconfig[label_name] > label_confidence:
dconfig[label_name] = label_confidence
@ -187,8 +186,7 @@ class Doods(ImageProcessingEntity):
# Handle global detection area
self._area = [0, 0, 1, 1]
self._covers = True
area_config = config.get(CONF_AREA)
if area_config:
if area_config := config.get(CONF_AREA):
self._area = [
area_config[CONF_TOP],
area_config[CONF_LEFT],

View File

@ -109,8 +109,7 @@ def request_configuration(hass, config, url, add_entities_callback):
"the desktop player and try again"
)
break
code = tmpmsg["payload"]
if code == "CODE_REQUIRED":
if (code := tmpmsg["payload"]) == "CODE_REQUIRED":
continue
setup_gpmdp(hass, config, code, add_entities_callback)
save_json(hass.config.path(GPMDP_CONFIG_FILE), {"CODE": code})

View File

@ -325,8 +325,7 @@ class ClimateAehW4a1(ClimateEntity):
"AC at %s is off, could not set temperature", self._unique_id
)
return
temp = kwargs.get(ATTR_TEMPERATURE)
if temp is not None:
if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
_LOGGER.debug("Setting temp of %s to %s", self._unique_id, temp)
if self._preset_mode != PRESET_NONE:
await self.async_set_preset_mode(PRESET_NONE)

View File

@ -166,8 +166,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up LIFX from a config entry."""
# Priority 1: manual config
interfaces = hass.data[LIFX_DOMAIN].get(DOMAIN)
if not interfaces:
if not (interfaces := hass.data[LIFX_DOMAIN].get(DOMAIN)):
# Priority 2: scanned interfaces
lifx_ip_addresses = await aiolifx().LifxScan(hass.loop).scan()
interfaces = [{CONF_SERVER: ip} for ip in lifx_ip_addresses]
@ -251,17 +250,14 @@ class LIFXManager:
def start_discovery(self, interface):
"""Start discovery on a network interface."""
kwargs = {"discovery_interval": DISCOVERY_INTERVAL}
broadcast_ip = interface.get(CONF_BROADCAST)
if broadcast_ip:
if broadcast_ip := interface.get(CONF_BROADCAST):
kwargs["broadcast_ip"] = broadcast_ip
lifx_discovery = aiolifx().LifxDiscovery(self.hass.loop, self, **kwargs)
kwargs = {}
listen_ip = interface.get(CONF_SERVER)
if listen_ip:
if listen_ip := interface.get(CONF_SERVER):
kwargs["listen_ip"] = listen_ip
listen_port = interface.get(CONF_PORT)
if listen_port:
if listen_port := interface.get(CONF_PORT):
kwargs["listen_port"] = listen_port
lifx_discovery.start(**kwargs)
@ -692,8 +688,7 @@ class LIFXStrip(LIFXColor):
bulb = self.bulb
num_zones = len(bulb.color_zones)
zones = kwargs.get(ATTR_ZONES)
if zones is None:
if (zones := kwargs.get(ATTR_ZONES)) is None:
# Fast track: setting all zones to the same brightness and color
# can be treated as a single-zone bulb.
if hsbk[2] is not None and hsbk[3] is not None:

View File

@ -64,20 +64,17 @@ async def async_setup(hass, config):
lwlink = LWLink(host)
hass.data[LIGHTWAVE_LINK] = lwlink
lights = config[DOMAIN][CONF_LIGHTS]
if lights:
if lights := config[DOMAIN][CONF_LIGHTS]:
hass.async_create_task(
async_load_platform(hass, "light", DOMAIN, lights, config)
)
switches = config[DOMAIN][CONF_SWITCHES]
if switches:
if switches := config[DOMAIN][CONF_SWITCHES]:
hass.async_create_task(
async_load_platform(hass, "switch", DOMAIN, switches, config)
)
trv = config[DOMAIN][CONF_TRV]
if trv:
if trv := config[DOMAIN][CONF_TRV]:
trvs = trv[CONF_TRVS]
proxy_ip = trv[CONF_PROXY_IP]
proxy_port = trv[CONF_PROXY_PORT]

View File

@ -193,8 +193,7 @@ def _async_merge_lip_leap_data(lip_devices, bridge):
if leap_device_data is None:
continue
for key in ("type", "model", "serial"):
val = leap_device_data.get(key)
if val is not None:
if (val := leap_device_data.get(key)) is not None:
device[key] = val
_LOGGER.debug("Button Devices: %s", button_devices_by_id)

View File

@ -220,9 +220,7 @@ async def async_validate_trigger_config(hass: HomeAssistant, config: ConfigType)
if not device:
return config
schema = DEVICE_TYPE_SCHEMA_MAP.get(device["type"])
if not schema:
if not (schema := DEVICE_TYPE_SCHEMA_MAP.get(device["type"])):
raise InvalidDeviceAutomationConfig(
f"Device type {device['type']} not supported: {config[CONF_DEVICE_ID]}"
)
@ -290,8 +288,7 @@ def get_button_device_by_dr_id(hass: HomeAssistant, device_id: str):
for config_entry in hass.data[DOMAIN]:
button_devices = hass.data[DOMAIN][config_entry][BUTTON_DEVICES]
device = button_devices.get(device_id)
if device:
if device := button_devices.get(device_id):
return device
return None

View File

@ -75,11 +75,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Mediaroom platform."""
known_hosts = hass.data.get(DATA_MEDIAROOM)
if known_hosts is None:
if (known_hosts := hass.data.get(DATA_MEDIAROOM)) is None:
known_hosts = hass.data[DATA_MEDIAROOM] = []
host = config.get(CONF_HOST)
if host:
if host := config.get(CONF_HOST):
async_add_entities(
[
MediaroomDevice(
@ -90,18 +88,18 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
)
]
)
hass.data[DATA_MEDIAROOM].append(host)
known_hosts.append(host)
_LOGGER.debug("Trying to discover Mediaroom STB")
def callback_notify(notify):
"""Process NOTIFY message from STB."""
if notify.ip_address in hass.data[DATA_MEDIAROOM]:
if notify.ip_address in known_hosts:
dispatcher_send(hass, SIGNAL_STB_NOTIFY, notify)
return
_LOGGER.debug("Discovered new stb %s", notify.ip_address)
hass.data[DATA_MEDIAROOM].append(notify.ip_address)
known_hosts.append(notify.ip_address)
new_stb = MediaroomDevice(
host=notify.ip_address, device_id=notify.device_uuid, optimistic=False
)

View File

@ -55,8 +55,7 @@ async def async_setup(hass, config):
hass.data.setdefault(DOMAIN, {})
for platform in PLATFORMS:
confs = config.get(platform)
if confs is None:
if (confs := config.get(platform)) is None:
continue
for conf in confs:

View File

@ -55,8 +55,7 @@ def item_payload(roon_server, item, list_image_id):
"""Create response payload for a single media item."""
title = item["title"]
subtitle = item.get("subtitle")
if subtitle is None:
if (subtitle := item.get("subtitle")) is None:
display_title = title
else:
display_title = f"{title} ({subtitle})"
@ -123,8 +122,7 @@ def library_payload(roon_server, zone_id, media_content_id):
header = result_header["list"]
title = header.get("title")
subtitle = header.get("subtitle")
if subtitle is None:
if (subtitle := header.get("subtitle")) is None:
list_title = title
else:
list_title = f"{title} ({subtitle})"

View File

@ -552,8 +552,7 @@ class RoonDevice(MediaPlayerEntity):
if output["display_name"] != self.name
}
transfer_id = zone_ids.get(name)
if transfer_id is None:
if (transfer_id := zone_ids.get(name)) is None:
_LOGGER.error(
"Can't transfer from %s to %s because destination is not known %s",
self.name,

View File

@ -149,8 +149,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
return self.async_abort(reason="cannot_connect")
if user_input is not None:
target_id = user_input.get(CONF_TARGET_ID)
if target_id:
if target_id := user_input.get(CONF_TARGET_ID):
return await self.async_step_target_config(None, target_id)
return self.async_create_entry(title="", data=self.options)

View File

@ -121,8 +121,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hosts = config.get(CONF_HOSTS, [])
_LOGGER.debug("Reached async_setup_entry, config=%s", config)
advertise_addr = config.get(CONF_ADVERTISE_ADDR)
if advertise_addr:
if advertise_addr := config.get(CONF_ADVERTISE_ADDR):
soco_config.EVENT_ADVERTISE_IP = advertise_addr
if deprecated_address := config.get(CONF_INTERFACE_ADDR):

View File

@ -145,13 +145,10 @@ class SteamSensor(SensorEntity):
def _get_current_game(self):
"""Gather current game name from APP ID."""
game_id = self._profile.current_game[0]
game_extra_info = self._profile.current_game[2]
if game_extra_info:
if game_extra_info := self._profile.current_game[2]:
return game_extra_info
if not game_id:
if not (game_id := self._profile.current_game[0]):
return None
app_list = self.hass.data[APP_LIST_KEY]
@ -174,8 +171,7 @@ class SteamSensor(SensorEntity):
return repr(game_id)
def _get_game_info(self):
game_id = self._profile.current_game[0]
if game_id is not None:
if (game_id := self._profile.current_game[0]) is not None:
for game in self._owned_games["response"]["games"]:
if game["appid"] == game_id: