diff --git a/homeassistant/components/doods/image_processing.py b/homeassistant/components/doods/image_processing.py index 3e41c1871bf..e4398a756ec 100644 --- a/homeassistant/components/doods/image_processing.py +++ b/homeassistant/components/doods/image_processing.py @@ -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], diff --git a/homeassistant/components/gpmdp/media_player.py b/homeassistant/components/gpmdp/media_player.py index 0a26a514323..649e0283f5a 100644 --- a/homeassistant/components/gpmdp/media_player.py +++ b/homeassistant/components/gpmdp/media_player.py @@ -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}) diff --git a/homeassistant/components/hisense_aehw4a1/climate.py b/homeassistant/components/hisense_aehw4a1/climate.py index 23a3a0c1416..096b39bdbca 100644 --- a/homeassistant/components/hisense_aehw4a1/climate.py +++ b/homeassistant/components/hisense_aehw4a1/climate.py @@ -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) diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index 48896cea8a5..b30315ac77d 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -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: diff --git a/homeassistant/components/lightwave/__init__.py b/homeassistant/components/lightwave/__init__.py index 73002908ff3..9cd73d8ffea 100644 --- a/homeassistant/components/lightwave/__init__.py +++ b/homeassistant/components/lightwave/__init__.py @@ -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] diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 44e6e8761b1..4aefb2fb50e 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -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) diff --git a/homeassistant/components/lutron_caseta/device_trigger.py b/homeassistant/components/lutron_caseta/device_trigger.py index 4e378942bd8..3d1d179eac1 100644 --- a/homeassistant/components/lutron_caseta/device_trigger.py +++ b/homeassistant/components/lutron_caseta/device_trigger.py @@ -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 diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py index 9c0812af6e5..d85aee89463 100644 --- a/homeassistant/components/mediaroom/media_player.py +++ b/homeassistant/components/mediaroom/media_player.py @@ -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 ) diff --git a/homeassistant/components/nuki/__init__.py b/homeassistant/components/nuki/__init__.py index ea224612d82..99def8d4117 100644 --- a/homeassistant/components/nuki/__init__.py +++ b/homeassistant/components/nuki/__init__.py @@ -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: diff --git a/homeassistant/components/roon/media_browser.py b/homeassistant/components/roon/media_browser.py index 0d744befb5c..2f132ee9d23 100644 --- a/homeassistant/components/roon/media_browser.py +++ b/homeassistant/components/roon/media_browser.py @@ -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})" diff --git a/homeassistant/components/roon/media_player.py b/homeassistant/components/roon/media_player.py index dd8d9e83c2d..0d7f736961f 100644 --- a/homeassistant/components/roon/media_player.py +++ b/homeassistant/components/roon/media_player.py @@ -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, diff --git a/homeassistant/components/somfy_mylink/config_flow.py b/homeassistant/components/somfy_mylink/config_flow.py index ecbd9abd402..79fbf028b16 100644 --- a/homeassistant/components/somfy_mylink/config_flow.py +++ b/homeassistant/components/somfy_mylink/config_flow.py @@ -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) diff --git a/homeassistant/components/sonos/__init__.py b/homeassistant/components/sonos/__init__.py index aafcba744ea..5e02832b05a 100644 --- a/homeassistant/components/sonos/__init__.py +++ b/homeassistant/components/sonos/__init__.py @@ -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): diff --git a/homeassistant/components/steam_online/sensor.py b/homeassistant/components/steam_online/sensor.py index 18f7c6cc447..71f25afe69f 100644 --- a/homeassistant/components/steam_online/sensor.py +++ b/homeassistant/components/steam_online/sensor.py @@ -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: