diff --git a/homeassistant/components/androidtv/media_player.py b/homeassistant/components/androidtv/media_player.py index 533470181c1..89deeec25b8 100644 --- a/homeassistant/components/androidtv/media_player.py +++ b/homeassistant/components/androidtv/media_player.py @@ -533,8 +533,7 @@ class ADBDevice(MediaPlayerEntity): @adb_decorator() async def adb_command(self, cmd): """Send an ADB command to an Android TV / Fire TV device.""" - key = KEYS.get(cmd) - if key: + if key := KEYS.get(cmd): await self.aftv.adb_shell(f"input keyevent {key}") return diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 321be5035cd..2571d35f98e 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -95,8 +95,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= if not sensors: return - store = hass.data.get(DATA_ARWN) - if store is None: + if (store := hass.data.get(DATA_ARWN)) is None: store = hass.data[DATA_ARWN] = {} if isinstance(sensors, ArwnSensor): diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index 4c720d5b9de..63270ee1f1b 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -68,9 +68,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: def _reset_device_favorites_handler(event): """Handle clearing favorites on device.""" - token = event.data.get("token") - - if token is None: + if (token := event.data.get("token")) is None: return doorstation = get_doorstation_by_token(hass, token) diff --git a/homeassistant/components/energy/validate.py b/homeassistant/components/energy/validate.py index c7f6c46aa1c..b2a939bffce 100644 --- a/homeassistant/components/energy/validate.py +++ b/homeassistant/components/energy/validate.py @@ -103,9 +103,7 @@ async def _async_validate_usage_stat( ) return - state = hass.states.get(entity_id) - - if state is None: + if (state := hass.states.get(entity_id)) is None: result.append( ValidationIssue( "entity_not_defined", @@ -180,9 +178,7 @@ def _async_validate_price_entity( unit_error: str, ) -> None: """Validate that the price entity is correct.""" - state = hass.states.get(entity_id) - - if state is None: + if (state := hass.states.get(entity_id)) is None: result.append( ValidationIssue( "entity_not_defined", @@ -228,9 +224,7 @@ async def _async_validate_cost_stat( if not recorder.is_entity_recorded(hass, stat_id): result.append(ValidationIssue("recorder_untracked", stat_id)) - state = hass.states.get(stat_id) - - if state is None: + if (state := hass.states.get(stat_id)) is None: result.append(ValidationIssue("entity_not_defined", stat_id)) return diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index 92122f1b2be..9ee5927695d 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -314,8 +314,7 @@ async def async_setup_entry( # noqa: C901 # Override settings from YAML config, but only if they're changed in it # Old values are stored as *_from_yaml in the config entry - yaml_config = hass.data[DOMAIN].config.get(url) - if yaml_config: + if yaml_config := hass.data[DOMAIN].config.get(url): # Config values new_data = {} for key in CONF_USERNAME, CONF_PASSWORD: diff --git a/homeassistant/components/hyperion/config_flow.py b/homeassistant/components/hyperion/config_flow.py index 81fef6429f6..6c76f03e3de 100644 --- a/homeassistant/components/hyperion/config_flow.py +++ b/homeassistant/components/hyperion/config_flow.py @@ -203,8 +203,7 @@ class HyperionConfigFlow(ConfigFlow, domain=DOMAIN): except ValueError: self._data[CONF_PORT] = const.DEFAULT_PORT_JSON - hyperion_id = discovery_info.get(ATTR_UPNP_SERIAL) - if not hyperion_id: + if not (hyperion_id := discovery_info.get(ATTR_UPNP_SERIAL)): return self.async_abort(reason="no_id") # For discovery mechanisms, we set the unique_id as early as possible to diff --git a/homeassistant/components/konnected/__init__.py b/homeassistant/components/konnected/__init__.py index 8fd439a0355..43537154e41 100644 --- a/homeassistant/components/konnected/__init__.py +++ b/homeassistant/components/konnected/__init__.py @@ -221,8 +221,7 @@ PLATFORMS = ["binary_sensor", "sensor", "switch"] async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Konnected platform.""" - cfg = config.get(DOMAIN) - if cfg is None: + if (cfg := config.get(DOMAIN)) is None: cfg = {} if DOMAIN not in hass.data: @@ -336,14 +335,12 @@ class KonnectedView(HomeAssistantView): "updating instructions" ) - device = data[CONF_DEVICES].get(device_id) - if device is None: + if (device := data[CONF_DEVICES].get(device_id)) is None: return self.json_message( "unregistered device", status_code=HTTPStatus.BAD_REQUEST ) - panel = device.get("panel") - if panel is not None: + if (panel := device.get("panel")) is not None: # connect if we haven't already hass.async_create_task(panel.async_connect()) @@ -382,14 +379,12 @@ class KonnectedView(HomeAssistantView): hass = request.app["hass"] data = hass.data[DOMAIN] - device = data[CONF_DEVICES].get(device_id) - if not device: + if not (device := data[CONF_DEVICES].get(device_id)): return self.json_message( f"Device {device_id} not configured", status_code=HTTPStatus.NOT_FOUND ) - panel = device.get("panel") - if panel is not None: + if (panel := device.get("panel")) is not None: # connect if we haven't already hass.async_create_task(panel.async_connect()) @@ -427,8 +422,7 @@ class KonnectedView(HomeAssistantView): resp[CONF_PIN] = ZONE_TO_PIN[zone_num] # Make sure entity is setup - zone_entity_id = zone.get(ATTR_ENTITY_ID) - if zone_entity_id: + if zone_entity_id := zone.get(ATTR_ENTITY_ID): resp["state"] = self.binary_value( hass.states.get(zone_entity_id).state, zone[CONF_ACTIVATION] ) diff --git a/homeassistant/components/konnected/handlers.py b/homeassistant/components/konnected/handlers.py index 879d0d4cf8f..b3c3f440e6f 100644 --- a/homeassistant/components/konnected/handlers.py +++ b/homeassistant/components/konnected/handlers.py @@ -51,8 +51,7 @@ async def async_handle_addr_update(hass, context, msg): """Handle an addressable sensor update.""" _LOGGER.debug("[addr handler] context: %s msg: %s", context, msg) addr, temp = msg.get("addr"), msg.get("temp") - entity_id = context.get(addr) - if entity_id: + if entity_id := context.get(addr): async_dispatcher_send(hass, f"konnected.{entity_id}.update", temp) else: msg["device_id"] = context.get("device_id") diff --git a/homeassistant/components/konnected/panel.py b/homeassistant/components/konnected/panel.py index cf2f33de332..137fdada8c5 100644 --- a/homeassistant/components/konnected/panel.py +++ b/homeassistant/components/konnected/panel.py @@ -347,9 +347,7 @@ class AlarmPanel: @callback def async_current_settings_payload(self): """Return a dict of configuration currently stored on the device.""" - settings = self.status["settings"] - if not settings: - settings = {} + settings = self.status["settings"] or {} return { "sensors": [ diff --git a/homeassistant/components/mazda/__init__.py b/homeassistant/components/mazda/__init__.py index 74a92b3e371..a9775b6d6df 100644 --- a/homeassistant/components/mazda/__init__.py +++ b/homeassistant/components/mazda/__init__.py @@ -110,9 +110,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: def validate_mazda_device_id(device_id): """Check that a device ID exists in the registry and has at least one 'mazda' identifier.""" dev_reg = device_registry.async_get(hass) - device_entry = dev_reg.async_get(device_id) - if device_entry is None: + if (device_entry := dev_reg.async_get(device_id)) is None: raise vol.Invalid("Invalid device ID") mazda_identifiers = [ diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 3ab9c64942c..3890a08de2b 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -98,8 +98,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity): async def async_set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return await self.coordinator.mill_data_connection.set_heater_temp( self._id, int(temperature) diff --git a/homeassistant/components/netatmo/climate.py b/homeassistant/components/netatmo/climate.py index 6b0f9cf5124..1e2dc3f0195 100644 --- a/homeassistant/components/netatmo/climate.py +++ b/homeassistant/components/netatmo/climate.py @@ -444,8 +444,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity): async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature for 2 hours.""" - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: return await self._home_status.async_set_room_thermpoint( self._id, STATE_NETATMO_MANUAL, temp diff --git a/homeassistant/components/oasa_telematics/sensor.py b/homeassistant/components/oasa_telematics/sensor.py index 4c9b583a36b..1a51738cb77 100644 --- a/homeassistant/components/oasa_telematics/sensor.py +++ b/homeassistant/components/oasa_telematics/sensor.py @@ -176,8 +176,7 @@ class OASATelematicsData: current_time = dt_util.utcnow() for result in results: - btime2 = result.get("btime2") - if btime2 is not None: + if (btime2 := result.get("btime2")) is not None: arrival_min = int(btime2) timestamp = current_time + timedelta(minutes=arrival_min) arrival_data = { diff --git a/homeassistant/components/scsgate/switch.py b/homeassistant/components/scsgate/switch.py index f5719aa24dc..175f40c3eba 100644 --- a/homeassistant/components/scsgate/switch.py +++ b/homeassistant/components/scsgate/switch.py @@ -62,9 +62,7 @@ def _setup_traditional_switches(logger, config, scsgate, add_entities_callback): def _setup_scenario_switches(logger, config, scsgate, hass): """Add only SCSGate scenario switches.""" - scenario = config.get(CONF_SCENARIO) - - if scenario: + if scenario := config.get(CONF_SCENARIO): for entity_info in scenario.values(): if entity_info[CONF_SCS_ID] in scsgate.devices: continue diff --git a/homeassistant/components/smtp/notify.py b/homeassistant/components/smtp/notify.py index 0586a5838fc..ef743912bc9 100644 --- a/homeassistant/components/smtp/notify.py +++ b/homeassistant/components/smtp/notify.py @@ -170,9 +170,8 @@ class MailNotificationService(BaseNotificationService): build a multipart HTML if html config is defined. """ subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) - data = kwargs.get(ATTR_DATA) - if data: + if data := kwargs.get(ATTR_DATA): if ATTR_HTML in data: msg = _build_html_msg( message, data[ATTR_HTML], images=data.get(ATTR_IMAGES, []) @@ -184,8 +183,7 @@ class MailNotificationService(BaseNotificationService): msg["Subject"] = subject - recipients = kwargs.get(ATTR_TARGET) - if not recipients: + if not (recipients := kwargs.get(ATTR_TARGET)): recipients = self.recipients msg["To"] = recipients if isinstance(recipients, str) else ",".join(recipients) if self._sender_name: diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 78764ccf4e7..52146518ee3 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -113,8 +113,7 @@ class SpiderThermostat(ClimateEntity): def set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return self.thermostat.set_temperature(temperature) diff --git a/homeassistant/components/system_log/__init__.py b/homeassistant/components/system_log/__init__.py index 9c868724d9b..8a88eef7bfc 100644 --- a/homeassistant/components/system_log/__init__.py +++ b/homeassistant/components/system_log/__init__.py @@ -197,8 +197,7 @@ class LogErrorHandler(logging.Handler): async def async_setup(hass, config): """Set up the logger component.""" - conf = config.get(DOMAIN) - if conf is None: + if (conf := config.get(DOMAIN)) is None: conf = CONFIG_SCHEMA({DOMAIN: {}})[DOMAIN] simple_queue = queue.SimpleQueue() diff --git a/homeassistant/components/threshold/binary_sensor.py b/homeassistant/components/threshold/binary_sensor.py index 1a53a599394..2db9f8aba06 100644 --- a/homeassistant/components/threshold/binary_sensor.py +++ b/homeassistant/components/threshold/binary_sensor.py @@ -95,8 +95,7 @@ class ThresholdSensor(BinarySensorEntity): @callback def async_threshold_sensor_state_listener(event): """Handle sensor state changes.""" - new_state = event.data.get("new_state") - if new_state is None: + if (new_state := event.data.get("new_state")) is None: return try: diff --git a/homeassistant/components/twilio_call/notify.py b/homeassistant/components/twilio_call/notify.py index 83ca081b26e..ca007a8231e 100644 --- a/homeassistant/components/twilio_call/notify.py +++ b/homeassistant/components/twilio_call/notify.py @@ -43,10 +43,7 @@ class TwilioCallNotificationService(BaseNotificationService): def send_message(self, message="", **kwargs): """Call to specified target users.""" - - targets = kwargs.get(ATTR_TARGET) - - if not targets: + if not (targets := kwargs.get(ATTR_TARGET)): _LOGGER.info("At least 1 target is required") return diff --git a/homeassistant/components/unifi/config_flow.py b/homeassistant/components/unifi/config_flow.py index 5edc71f9f5d..ea737599b20 100644 --- a/homeassistant/components/unifi/config_flow.py +++ b/homeassistant/components/unifi/config_flow.py @@ -235,8 +235,7 @@ class UnifiFlowHandler(config_entries.ConfigFlow, domain=UNIFI_DOMAIN): CONF_SITE_ID: DEFAULT_SITE_ID, } - port = MODEL_PORTS.get(model_description) - if port is not None: + if (port := MODEL_PORTS.get(model_description)) is not None: self.config[CONF_PORT] = port return await self.async_step_user() diff --git a/homeassistant/components/yamaha_musiccast/config_flow.py b/homeassistant/components/yamaha_musiccast/config_flow.py index f4ad455fb04..6645af20d83 100644 --- a/homeassistant/components/yamaha_musiccast/config_flow.py +++ b/homeassistant/components/yamaha_musiccast/config_flow.py @@ -54,8 +54,7 @@ class MusicCastFlowHandler(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: - serial_number = info.get("system_id") - if serial_number is None: + if (serial_number := info.get("system_id")) is None: errors["base"] = "no_musiccast_device" if not errors: