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 continue
# If label confidence is not specified, use global confidence # If label confidence is not specified, use global confidence
label_confidence = label.get(CONF_CONFIDENCE) if not (label_confidence := label.get(CONF_CONFIDENCE)):
if not label_confidence:
label_confidence = confidence label_confidence = confidence
if label_name not in dconfig or dconfig[label_name] > label_confidence: if label_name not in dconfig or dconfig[label_name] > label_confidence:
dconfig[label_name] = label_confidence dconfig[label_name] = label_confidence
@ -187,8 +186,7 @@ class Doods(ImageProcessingEntity):
# Handle global detection area # Handle global detection area
self._area = [0, 0, 1, 1] self._area = [0, 0, 1, 1]
self._covers = True self._covers = True
area_config = config.get(CONF_AREA) if area_config := config.get(CONF_AREA):
if area_config:
self._area = [ self._area = [
area_config[CONF_TOP], area_config[CONF_TOP],
area_config[CONF_LEFT], 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" "the desktop player and try again"
) )
break break
code = tmpmsg["payload"] if (code := tmpmsg["payload"]) == "CODE_REQUIRED":
if code == "CODE_REQUIRED":
continue continue
setup_gpmdp(hass, config, code, add_entities_callback) setup_gpmdp(hass, config, code, add_entities_callback)
save_json(hass.config.path(GPMDP_CONFIG_FILE), {"CODE": code}) 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 "AC at %s is off, could not set temperature", self._unique_id
) )
return return
temp = kwargs.get(ATTR_TEMPERATURE) if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
if temp is not None:
_LOGGER.debug("Setting temp of %s to %s", self._unique_id, temp) _LOGGER.debug("Setting temp of %s to %s", self._unique_id, temp)
if self._preset_mode != PRESET_NONE: if self._preset_mode != PRESET_NONE:
await self.async_set_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): async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up LIFX from a config entry.""" """Set up LIFX from a config entry."""
# Priority 1: manual config # Priority 1: manual config
interfaces = hass.data[LIFX_DOMAIN].get(DOMAIN) if not (interfaces := hass.data[LIFX_DOMAIN].get(DOMAIN)):
if not interfaces:
# Priority 2: scanned interfaces # Priority 2: scanned interfaces
lifx_ip_addresses = await aiolifx().LifxScan(hass.loop).scan() lifx_ip_addresses = await aiolifx().LifxScan(hass.loop).scan()
interfaces = [{CONF_SERVER: ip} for ip in lifx_ip_addresses] interfaces = [{CONF_SERVER: ip} for ip in lifx_ip_addresses]
@ -251,17 +250,14 @@ class LIFXManager:
def start_discovery(self, interface): def start_discovery(self, interface):
"""Start discovery on a network interface.""" """Start discovery on a network interface."""
kwargs = {"discovery_interval": DISCOVERY_INTERVAL} kwargs = {"discovery_interval": DISCOVERY_INTERVAL}
broadcast_ip = interface.get(CONF_BROADCAST) if broadcast_ip := interface.get(CONF_BROADCAST):
if broadcast_ip:
kwargs["broadcast_ip"] = broadcast_ip kwargs["broadcast_ip"] = broadcast_ip
lifx_discovery = aiolifx().LifxDiscovery(self.hass.loop, self, **kwargs) lifx_discovery = aiolifx().LifxDiscovery(self.hass.loop, self, **kwargs)
kwargs = {} kwargs = {}
listen_ip = interface.get(CONF_SERVER) if listen_ip := interface.get(CONF_SERVER):
if listen_ip:
kwargs["listen_ip"] = listen_ip kwargs["listen_ip"] = listen_ip
listen_port = interface.get(CONF_PORT) if listen_port := interface.get(CONF_PORT):
if listen_port:
kwargs["listen_port"] = listen_port kwargs["listen_port"] = listen_port
lifx_discovery.start(**kwargs) lifx_discovery.start(**kwargs)
@ -692,8 +688,7 @@ class LIFXStrip(LIFXColor):
bulb = self.bulb bulb = self.bulb
num_zones = len(bulb.color_zones) num_zones = len(bulb.color_zones)
zones = kwargs.get(ATTR_ZONES) if (zones := kwargs.get(ATTR_ZONES)) is None:
if zones is None:
# Fast track: setting all zones to the same brightness and color # Fast track: setting all zones to the same brightness and color
# can be treated as a single-zone bulb. # can be treated as a single-zone bulb.
if hsbk[2] is not None and hsbk[3] is not None: 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) lwlink = LWLink(host)
hass.data[LIGHTWAVE_LINK] = lwlink hass.data[LIGHTWAVE_LINK] = lwlink
lights = config[DOMAIN][CONF_LIGHTS] if lights := config[DOMAIN][CONF_LIGHTS]:
if lights:
hass.async_create_task( hass.async_create_task(
async_load_platform(hass, "light", DOMAIN, lights, config) async_load_platform(hass, "light", DOMAIN, lights, config)
) )
switches = config[DOMAIN][CONF_SWITCHES] if switches := config[DOMAIN][CONF_SWITCHES]:
if switches:
hass.async_create_task( hass.async_create_task(
async_load_platform(hass, "switch", DOMAIN, switches, config) async_load_platform(hass, "switch", DOMAIN, switches, config)
) )
trv = config[DOMAIN][CONF_TRV] if trv := config[DOMAIN][CONF_TRV]:
if trv:
trvs = trv[CONF_TRVS] trvs = trv[CONF_TRVS]
proxy_ip = trv[CONF_PROXY_IP] proxy_ip = trv[CONF_PROXY_IP]
proxy_port = trv[CONF_PROXY_PORT] 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: if leap_device_data is None:
continue continue
for key in ("type", "model", "serial"): for key in ("type", "model", "serial"):
val = leap_device_data.get(key) if (val := leap_device_data.get(key)) is not None:
if val is not None:
device[key] = val device[key] = val
_LOGGER.debug("Button Devices: %s", button_devices_by_id) _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: if not device:
return config return config
schema = DEVICE_TYPE_SCHEMA_MAP.get(device["type"]) if not (schema := DEVICE_TYPE_SCHEMA_MAP.get(device["type"])):
if not schema:
raise InvalidDeviceAutomationConfig( raise InvalidDeviceAutomationConfig(
f"Device type {device['type']} not supported: {config[CONF_DEVICE_ID]}" 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]: for config_entry in hass.data[DOMAIN]:
button_devices = hass.data[DOMAIN][config_entry][BUTTON_DEVICES] button_devices = hass.data[DOMAIN][config_entry][BUTTON_DEVICES]
device = button_devices.get(device_id) if device := button_devices.get(device_id):
if device:
return device return device
return None 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): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Mediaroom platform.""" """Set up the Mediaroom platform."""
known_hosts = hass.data.get(DATA_MEDIAROOM) if (known_hosts := hass.data.get(DATA_MEDIAROOM)) is None:
if known_hosts is None:
known_hosts = hass.data[DATA_MEDIAROOM] = [] known_hosts = hass.data[DATA_MEDIAROOM] = []
host = config.get(CONF_HOST) if host := config.get(CONF_HOST):
if host:
async_add_entities( async_add_entities(
[ [
MediaroomDevice( 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") _LOGGER.debug("Trying to discover Mediaroom STB")
def callback_notify(notify): def callback_notify(notify):
"""Process NOTIFY message from STB.""" """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) dispatcher_send(hass, SIGNAL_STB_NOTIFY, notify)
return return
_LOGGER.debug("Discovered new stb %s", notify.ip_address) _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( new_stb = MediaroomDevice(
host=notify.ip_address, device_id=notify.device_uuid, optimistic=False 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, {}) hass.data.setdefault(DOMAIN, {})
for platform in PLATFORMS: for platform in PLATFORMS:
confs = config.get(platform) if (confs := config.get(platform)) is None:
if confs is None:
continue continue
for conf in confs: 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.""" """Create response payload for a single media item."""
title = item["title"] title = item["title"]
subtitle = item.get("subtitle") if (subtitle := item.get("subtitle")) is None:
if subtitle is None:
display_title = title display_title = title
else: else:
display_title = f"{title} ({subtitle})" display_title = f"{title} ({subtitle})"
@ -123,8 +122,7 @@ def library_payload(roon_server, zone_id, media_content_id):
header = result_header["list"] header = result_header["list"]
title = header.get("title") title = header.get("title")
subtitle = header.get("subtitle") if (subtitle := header.get("subtitle")) is None:
if subtitle is None:
list_title = title list_title = title
else: else:
list_title = f"{title} ({subtitle})" list_title = f"{title} ({subtitle})"

View File

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

View File

@ -149,8 +149,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
return self.async_abort(reason="cannot_connect") return self.async_abort(reason="cannot_connect")
if user_input is not None: if user_input is not None:
target_id = user_input.get(CONF_TARGET_ID) if target_id := user_input.get(CONF_TARGET_ID):
if target_id:
return await self.async_step_target_config(None, target_id) return await self.async_step_target_config(None, target_id)
return self.async_create_entry(title="", data=self.options) 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, []) hosts = config.get(CONF_HOSTS, [])
_LOGGER.debug("Reached async_setup_entry, config=%s", config) _LOGGER.debug("Reached async_setup_entry, config=%s", config)
advertise_addr = config.get(CONF_ADVERTISE_ADDR) if advertise_addr := config.get(CONF_ADVERTISE_ADDR):
if advertise_addr:
soco_config.EVENT_ADVERTISE_IP = advertise_addr soco_config.EVENT_ADVERTISE_IP = advertise_addr
if deprecated_address := config.get(CONF_INTERFACE_ADDR): if deprecated_address := config.get(CONF_INTERFACE_ADDR):

View File

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