diff --git a/homeassistant/components/ddwrt/device_tracker.py b/homeassistant/components/ddwrt/device_tracker.py index bc52e7712b6..bc4ef7f8f82 100644 --- a/homeassistant/components/ddwrt/device_tracker.py +++ b/homeassistant/components/ddwrt/device_tracker.py @@ -88,9 +88,7 @@ class DdWrtDeviceScanner(DeviceScanner): if not data: return None - dhcp_leases = data.get("dhcp_leases") - - if not dhcp_leases: + if not (dhcp_leases := data.get("dhcp_leases")): return None # Remove leading and trailing quotes and spaces diff --git a/homeassistant/components/denonavr/config_flow.py b/homeassistant/components/denonavr/config_flow.py index 1005858e729..ffb73327d31 100644 --- a/homeassistant/components/denonavr/config_flow.py +++ b/homeassistant/components/denonavr/config_flow.py @@ -111,8 +111,7 @@ class DenonAvrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): errors = {} if user_input is not None: # check if IP address is set manually - host = user_input.get(CONF_HOST) - if host: + if host := user_input.get(CONF_HOST): self.host = host return await self.async_step_connect() diff --git a/homeassistant/components/digital_ocean/binary_sensor.py b/homeassistant/components/digital_ocean/binary_sensor.py index 9a9f82c36d2..b5188092862 100644 --- a/homeassistant/components/digital_ocean/binary_sensor.py +++ b/homeassistant/components/digital_ocean/binary_sensor.py @@ -36,8 +36,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Digital Ocean droplet sensor.""" - digital = hass.data.get(DATA_DIGITAL_OCEAN) - if not digital: + if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): return False droplets = config[CONF_DROPLETS] diff --git a/homeassistant/components/digital_ocean/switch.py b/homeassistant/components/digital_ocean/switch.py index 0678b9ab1a1..d52c223c866 100644 --- a/homeassistant/components/digital_ocean/switch.py +++ b/homeassistant/components/digital_ocean/switch.py @@ -33,8 +33,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Digital Ocean droplet switch.""" - digital = hass.data.get(DATA_DIGITAL_OCEAN) - if not digital: + if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): return False droplets = config[CONF_DROPLETS] diff --git a/homeassistant/components/dovado/notify.py b/homeassistant/components/dovado/notify.py index 02ce994b1df..c599ad918e8 100644 --- a/homeassistant/components/dovado/notify.py +++ b/homeassistant/components/dovado/notify.py @@ -22,9 +22,7 @@ class DovadoSMSNotificationService(BaseNotificationService): def send_message(self, message, **kwargs): """Send SMS to the specified target phone number.""" - target = kwargs.get(ATTR_TARGET) - - if not target: + if not (target := kwargs.get(ATTR_TARGET)): _LOGGER.error("One target is required") return diff --git a/homeassistant/components/econet/water_heater.py b/homeassistant/components/econet/water_heater.py index ed31e78af7c..7ea4d7740a5 100644 --- a/homeassistant/components/econet/water_heater.py +++ b/homeassistant/components/econet/water_heater.py @@ -113,8 +113,7 @@ class EcoNetWaterHeater(EcoNetEntity, WaterHeaterEntity): def set_temperature(self, **kwargs): """Set new target temperature.""" - target_temp = kwargs.get(ATTR_TEMPERATURE) - if target_temp is not None: + if (target_temp := kwargs.get(ATTR_TEMPERATURE)) is not None: self.water_heater.set_set_point(target_temp) else: _LOGGER.error("A target temperature must be provided") diff --git a/homeassistant/components/greeneye_monitor/__init__.py b/homeassistant/components/greeneye_monitor/__init__.py index 51471739e98..cc7b8955756 100644 --- a/homeassistant/components/greeneye_monitor/__init__.py +++ b/homeassistant/components/greeneye_monitor/__init__.py @@ -157,8 +157,7 @@ async def async_setup(hass, config): } ) - sensor_configs = monitor_config[CONF_TEMPERATURE_SENSORS] - if sensor_configs: + if sensor_configs := monitor_config[CONF_TEMPERATURE_SENSORS]: temperature_unit = { CONF_TEMPERATURE_UNIT: sensor_configs[CONF_TEMPERATURE_UNIT] } diff --git a/homeassistant/components/habitica/sensor.py b/homeassistant/components/habitica/sensor.py index ae27e0a51fc..64494fb9694 100644 --- a/homeassistant/components/habitica/sensor.py +++ b/homeassistant/components/habitica/sensor.py @@ -213,8 +213,7 @@ class HabitipyTaskSensor(SensorEntity): task_id = received_task[TASKS_MAP_ID] task = {} for map_key, map_value in TASKS_MAP.items(): - value = received_task.get(map_value) - if value: + if value := received_task.get(map_value): task[map_key] = value attrs[task_id] = task return attrs diff --git a/homeassistant/components/icloud/__init__.py b/homeassistant/components/icloud/__init__.py index 865b77b4ddf..7054a0f0ad1 100644 --- a/homeassistant/components/icloud/__init__.py +++ b/homeassistant/components/icloud/__init__.py @@ -88,9 +88,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up iCloud from legacy config file.""" - - conf = config.get(DOMAIN) - if conf is None: + if (conf := config.get(DOMAIN)) is None: return True for account_conf in conf: @@ -169,9 +167,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: def update_account(service: ServiceDataType) -> None: """Call the update function of an iCloud account.""" - account = service.data.get(ATTR_ACCOUNT) - - if account is None: + if (account := service.data.get(ATTR_ACCOUNT)) is None: for account in hass.data[DOMAIN].values(): account.keep_alive() else: diff --git a/homeassistant/components/intesishome/climate.py b/homeassistant/components/intesishome/climate.py index b93babf534e..afe0fb519a8 100644 --- a/homeassistant/components/intesishome/climate.py +++ b/homeassistant/components/intesishome/climate.py @@ -259,13 +259,10 @@ class IntesisAC(ClimateEntity): async def async_set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - hvac_mode = kwargs.get(ATTR_HVAC_MODE) - - if hvac_mode: + if hvac_mode := kwargs.get(ATTR_HVAC_MODE): await self.async_set_hvac_mode(hvac_mode) - if temperature: + if temperature := kwargs.get(ATTR_TEMPERATURE): _LOGGER.debug("Setting %s to %s degrees", self._device_type, temperature) await self._controller.set_temperature(self._device_id, temperature) self._target_temp = temperature diff --git a/homeassistant/components/lcn/climate.py b/homeassistant/components/lcn/climate.py index 4254a5e5480..c3882033caf 100644 --- a/homeassistant/components/lcn/climate.py +++ b/homeassistant/components/lcn/climate.py @@ -176,8 +176,7 @@ class LcnClimate(LcnEntity, ClimateEntity): async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return if not await self.device_connection.var_abs( diff --git a/homeassistant/components/lcn/helpers.py b/homeassistant/components/lcn/helpers.py index 5aaede430c5..b62f8474470 100644 --- a/homeassistant/components/lcn/helpers.py +++ b/homeassistant/components/lcn/helpers.py @@ -208,8 +208,7 @@ def has_unique_host_names(hosts: list[ConfigType]) -> list[ConfigType]: """ suffix = 0 for host in hosts: - host_name = host.get(CONF_NAME) - if host_name is None: + if host.get(CONF_NAME) is None: if suffix == 0: host[CONF_NAME] = DEFAULT_NAME else: diff --git a/homeassistant/components/lcn/services.py b/homeassistant/components/lcn/services.py index 8c305d68403..c55e6586edf 100644 --- a/homeassistant/components/lcn/services.py +++ b/homeassistant/components/lcn/services.py @@ -307,8 +307,7 @@ class SendKeys(LcnServiceCall): key_id = int(key) - 1 keys[table_id][key_id] = True - delay_time = service.data[CONF_TIME] - if delay_time != 0: + if (delay_time := service.data[CONF_TIME]) != 0: hit = pypck.lcn_defs.SendKeyCommand.HIT if pypck.lcn_defs.SendKeyCommand[service.data[CONF_STATE]] != hit: raise ValueError( @@ -347,8 +346,7 @@ class LockKeys(LcnServiceCall): ] table_id = ord(service.data[CONF_TABLE]) - 65 - delay_time = service.data[CONF_TIME] - if delay_time != 0: + if (delay_time := service.data[CONF_TIME]) != 0: if table_id != 0: raise ValueError( "Only table A is allowed when locking keys for a specific time." diff --git a/homeassistant/components/lock/reproduce_state.py b/homeassistant/components/lock/reproduce_state.py index cdd538c88be..b6eefcfac63 100644 --- a/homeassistant/components/lock/reproduce_state.py +++ b/homeassistant/components/lock/reproduce_state.py @@ -32,9 +32,7 @@ async def _async_reproduce_state( reproduce_options: dict[str, Any] | None = None, ) -> None: """Reproduce a single state.""" - cur_state = hass.states.get(state.entity_id) - - if cur_state is None: + if (cur_state := hass.states.get(state.entity_id)) is None: _LOGGER.warning("Unable to find entity %s", state.entity_id) return diff --git a/homeassistant/components/opnsense/device_tracker.py b/homeassistant/components/opnsense/device_tracker.py index 936872f7a86..0bce00a8e82 100644 --- a/homeassistant/components/opnsense/device_tracker.py +++ b/homeassistant/components/opnsense/device_tracker.py @@ -56,7 +56,6 @@ class OPNSenseDeviceScanner(DeviceScanner): """Return the extra attrs of the given device.""" if device not in self.last_results: return None - mfg = self.last_results[device].get("manufacturer") - if not mfg: + if not (mfg := self.last_results[device].get("manufacturer")): return {} return {"manufacturer": mfg} diff --git a/homeassistant/components/owntracks/__init__.py b/homeassistant/components/owntracks/__init__.py index d51566718d6..24c7cc74d52 100644 --- a/homeassistant/components/owntracks/__init__.py +++ b/homeassistant/components/owntracks/__init__.py @@ -242,9 +242,7 @@ class OwnTracksContext: @callback def async_valid_accuracy(self, message): """Check if we should ignore this message.""" - acc = message.get("acc") - - if acc is None: + if (acc := message.get("acc")) is None: return False try: diff --git a/homeassistant/components/panasonic_viera/__init__.py b/homeassistant/components/panasonic_viera/__init__.py index ab63b535e80..419181da2d9 100644 --- a/homeassistant/components/panasonic_viera/__init__.py +++ b/homeassistant/components/panasonic_viera/__init__.py @@ -73,8 +73,7 @@ async def async_setup_entry(hass, config_entry): host = config[CONF_HOST] port = config[CONF_PORT] - on_action = config[CONF_ON_ACTION] - if on_action is not None: + if (on_action := config[CONF_ON_ACTION]) is not None: on_action = Script(hass, on_action, config[CONF_NAME], DOMAIN) params = {} diff --git a/homeassistant/components/risco/alarm_control_panel.py b/homeassistant/components/risco/alarm_control_panel.py index 705ec50db28..9b2f603ce8a 100644 --- a/homeassistant/components/risco/alarm_control_panel.py +++ b/homeassistant/components/risco/alarm_control_panel.py @@ -164,8 +164,7 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity): _LOGGER.warning("Wrong code entered for %s", mode) return - risco_state = self._ha_to_risco[mode] - if not risco_state: + if not (risco_state := self._ha_to_risco[mode]): _LOGGER.warning("No mapping for mode %s", mode) return diff --git a/homeassistant/components/squeezebox/browse_media.py b/homeassistant/components/squeezebox/browse_media.py index 294a1105a71..81d0231ae70 100644 --- a/homeassistant/components/squeezebox/browse_media.py +++ b/homeassistant/components/squeezebox/browse_media.py @@ -97,8 +97,7 @@ async def build_item_response(entity, player, payload): item_id = str(item["id"]) item_thumbnail = None - artwork_track_id = item.get("artwork_track_id") - if artwork_track_id: + if artwork_track_id := item.get("artwork_track_id"): if internal_request: item_thumbnail = player.generate_image_url_from_track_id( artwork_track_id diff --git a/homeassistant/components/squeezebox/media_player.py b/homeassistant/components/squeezebox/media_player.py index 1ba406097d7..a0904c3178d 100644 --- a/homeassistant/components/squeezebox/media_player.py +++ b/homeassistant/components/squeezebox/media_player.py @@ -561,8 +561,7 @@ class SqueezeBoxEntity(MediaPlayerEntity): player_ids = { p.entity_id: p.unique_id for p in self.hass.data[DOMAIN][KNOWN_PLAYERS] } - other_player_id = player_ids.get(other_player) - if other_player_id: + if other_player_id := player_ids.get(other_player): await self._player.async_sync(other_player_id) else: _LOGGER.info("Could not find player_id for %s. Not syncing", other_player) diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 84b7249d203..7fd83141b7d 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -329,8 +329,7 @@ async def async_setup(hass, config): """Handle sending Telegram Bot message service calls.""" def _render_template_attr(data, attribute): - attribute_templ = data.get(attribute) - if attribute_templ: + if attribute_templ := data.get(attribute): if any( isinstance(attribute_templ, vtype) for vtype in (float, int, str) ): diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index d78398fb46f..44637c530ef 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -76,8 +76,7 @@ def setup(hass, config): kwargs = {"mid": ring_id} - ring_vol = call.data.get(ATTR_RINGTONE_VOL) - if ring_vol is not None: + if (ring_vol := call.data.get(ATTR_RINGTONE_VOL)) is not None: kwargs["vol"] = ring_vol gateway.write_to_hub(gateway.sid, **kwargs) @@ -379,8 +378,7 @@ def _add_gateway_to_schema(hass, schema): raise vol.Invalid(f"Unknown gateway sid {sid}") kwargs = {} - xiaomi_data = hass.data.get(DOMAIN) - if xiaomi_data is not None: + if (xiaomi_data := hass.data.get(DOMAIN)) is not None: gateways = list(xiaomi_data[GATEWAYS_KEY].values()) # If the user has only 1 gateway, make it the default for services. diff --git a/homeassistant/components/xiaomi_aqara/config_flow.py b/homeassistant/components/xiaomi_aqara/config_flow.py index 68c688d3eb1..3fbe7a71496 100644 --- a/homeassistant/components/xiaomi_aqara/config_flow.py +++ b/homeassistant/components/xiaomi_aqara/config_flow.py @@ -76,10 +76,8 @@ class XiaomiAqaraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): if self.host is None: self.host = user_input.get(CONF_HOST) if self.sid is None: - mac_address = user_input.get(CONF_MAC) - # format sid from mac_address - if mac_address is not None: + if (mac_address := user_input.get(CONF_MAC)) is not None: self.sid = format_mac(mac_address).replace(":", "") # if host is already known by zeroconf discovery or manual optional settings diff --git a/homeassistant/components/xiaomi_aqara/lock.py b/homeassistant/components/xiaomi_aqara/lock.py index 5afb1701e33..b7167452b65 100644 --- a/homeassistant/components/xiaomi_aqara/lock.py +++ b/homeassistant/components/xiaomi_aqara/lock.py @@ -22,8 +22,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities = [] gateway = hass.data[DOMAIN][GATEWAYS_KEY][config_entry.entry_id] for device in gateway.devices["lock"]: - model = device["model"] - if model == "lock.aq1": + if device["model"] == "lock.aq1": entities.append(XiaomiAqaraLock(device, "Lock", gateway, config_entry)) async_add_entities(entities) @@ -63,14 +62,12 @@ class XiaomiAqaraLock(LockEntity, XiaomiDevice): def parse_data(self, data, raw_data): """Parse data sent by gateway.""" - value = data.get(VERIFIED_WRONG_KEY) - if value is not None: + if (value := data.get(VERIFIED_WRONG_KEY)) is not None: self._verified_wrong_times = int(value) return True for key in (FINGER_KEY, PASSWORD_KEY, CARD_KEY): - value = data.get(key) - if value is not None: + if (value := data.get(key)) is not None: self._changed_by = int(value) self._verified_wrong_times = 0 self._state = STATE_UNLOCKED diff --git a/homeassistant/components/xiaomi_aqara/sensor.py b/homeassistant/components/xiaomi_aqara/sensor.py index 3935f4fdc57..c3f5cf4dacc 100644 --- a/homeassistant/components/xiaomi_aqara/sensor.py +++ b/homeassistant/components/xiaomi_aqara/sensor.py @@ -158,8 +158,7 @@ class XiaomiSensor(XiaomiDevice, SensorEntity): def parse_data(self, data, raw_data): """Parse data sent by gateway.""" - value = data.get(self._data_key) - if value is None: + if (value := data.get(self._data_key)) is None: return False if self._data_key in ("coordination", "status"): self._attr_native_value = value