diff --git a/homeassistant/components/camera/media_source.py b/homeassistant/components/camera/media_source.py index b0161a58251..c61cbef146a 100644 --- a/homeassistant/components/camera/media_source.py +++ b/homeassistant/components/camera/media_source.py @@ -47,14 +47,12 @@ class CameraMediaSource(MediaSource): if not camera: raise Unresolvable(f"Could not resolve media item: {item.identifier}") - stream_type = camera.frontend_stream_type - - if stream_type is None: + if (stream_type := camera.frontend_stream_type) is None: return PlayMedia( f"/api/camera_proxy_stream/{camera.entity_id}", camera.content_type ) - if camera.frontend_stream_type != STREAM_TYPE_HLS: + if stream_type != STREAM_TYPE_HLS: raise Unresolvable("Camera does not support MJPEG or HLS streaming.") if "stream" not in self.hass.config.components: diff --git a/homeassistant/components/config/config_entries.py b/homeassistant/components/config/config_entries.py index 2cf7005cb66..e5bf9e9b93d 100644 --- a/homeassistant/components/config/config_entries.py +++ b/homeassistant/components/config/config_entries.py @@ -317,8 +317,7 @@ async def config_entry_update(hass, connection, msg): @websocket_api.async_response async def config_entry_disable(hass, connection, msg): """Disable config entry.""" - disabled_by = msg["disabled_by"] - if disabled_by is not None: + if (disabled_by := msg["disabled_by"]) is not None: disabled_by = config_entries.ConfigEntryDisabler(disabled_by) result = False diff --git a/homeassistant/components/device_tracker/config_entry.py b/homeassistant/components/device_tracker/config_entry.py index c83ca669d6d..adabd297c55 100644 --- a/homeassistant/components/device_tracker/config_entry.py +++ b/homeassistant/components/device_tracker/config_entry.py @@ -141,14 +141,11 @@ def _async_register_mac( return ent_reg = er.async_get(hass) - entity_id = ent_reg.async_get_entity_id(DOMAIN, *unique_id) - if entity_id is None: + if (entity_id := ent_reg.async_get_entity_id(DOMAIN, *unique_id)) is None: return - entity_entry = ent_reg.async_get(entity_id) - - if entity_entry is None: + if (entity_entry := ent_reg.async_get(entity_id)) is None: return # Make sure entity has a config entry and was disabled by the diff --git a/homeassistant/components/diagnostics/__init__.py b/homeassistant/components/diagnostics/__init__.py index b08c521537d..a3f1e5fe272 100644 --- a/homeassistant/components/diagnostics/__init__.py +++ b/homeassistant/components/diagnostics/__init__.py @@ -106,9 +106,8 @@ def handle_get( ): """List all possible diagnostic handlers.""" domain = msg["domain"] - info = hass.data[DOMAIN].get(domain) - if info is None: + if (info := hass.data[DOMAIN].get(domain)) is None: connection.send_error( msg["id"], websocket_api.ERR_NOT_FOUND, "Domain not supported" ) @@ -197,14 +196,11 @@ class DownloadDiagnosticsView(http.HomeAssistantView): return web.Response(status=HTTPStatus.BAD_REQUEST) hass = request.app["hass"] - config_entry = hass.config_entries.async_get_entry(d_id) - if config_entry is None: + if (config_entry := hass.config_entries.async_get_entry(d_id)) is None: return web.Response(status=HTTPStatus.NOT_FOUND) - info = hass.data[DOMAIN].get(config_entry.domain) - - if info is None: + if (info := hass.data[DOMAIN].get(config_entry.domain)) is None: return web.Response(status=HTTPStatus.NOT_FOUND) filename = f"{config_entry.domain}-{config_entry.entry_id}" @@ -226,9 +222,8 @@ class DownloadDiagnosticsView(http.HomeAssistantView): dev_reg = async_get(hass) assert sub_id - device = dev_reg.async_get(sub_id) - if device is None: + if (device := dev_reg.async_get(sub_id)) is None: return web.Response(status=HTTPStatus.NOT_FOUND) filename += f"-{device.name}-{device.id}" diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 23a1fcc579e..197cf26b41f 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -610,10 +610,8 @@ def _merge_config(entry, conf): async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Load a config entry.""" - conf = hass.data.get(DATA_MQTT_CONFIG) - # If user didn't have configuration.yaml config, generate defaults - if conf is None: + if (conf := hass.data.get(DATA_MQTT_CONFIG)) is None: conf = CONFIG_SCHEMA({DOMAIN: dict(entry.data)})[DOMAIN] elif any(key in conf for key in entry.data): shared_keys = conf.keys() & entry.data.keys() diff --git a/homeassistant/components/mqtt/mixins.py b/homeassistant/components/mqtt/mixins.py index ba67339a5d4..9f3722a8f31 100644 --- a/homeassistant/components/mqtt/mixins.py +++ b/homeassistant/components/mqtt/mixins.py @@ -839,8 +839,7 @@ def async_removed_from_device( if "config_entries" not in event.data["changes"]: return False device_registry = dr.async_get(hass) - device_entry = device_registry.async_get(device_id) - if not device_entry: + if not (device_entry := device_registry.async_get(device_id)): # The device is already removed, do cleanup when we get "remove" event return False if config_entry_id in device_entry.config_entries: diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index abe3d29c607..5e6629ca2a2 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -344,9 +344,7 @@ class SpeechManager: This method is a coroutine. """ - provider = self.providers.get(engine) - - if provider is None: + if (provider := self.providers.get(engine)) is None: raise HomeAssistantError(f"Provider {engine} not found") msg_hash = hashlib.sha1(bytes(message, "utf-8")).hexdigest() diff --git a/homeassistant/components/tts/media_source.py b/homeassistant/components/tts/media_source.py index 5e595ca42b7..48bb43990ef 100644 --- a/homeassistant/components/tts/media_source.py +++ b/homeassistant/components/tts/media_source.py @@ -94,9 +94,7 @@ class TTSMediaSource(MediaSource): ) -> BrowseMediaSource: """Return provider item.""" manager: SpeechManager = self.hass.data[DOMAIN] - provider = manager.providers.get(provider_domain) - - if provider is None: + if (provider := manager.providers.get(provider_domain)) is None: raise BrowseError("Unknown provider") if params: diff --git a/homeassistant/components/zone/trigger.py b/homeassistant/components/zone/trigger.py index a008a30007a..5a11bf2068d 100644 --- a/homeassistant/components/zone/trigger.py +++ b/homeassistant/components/zone/trigger.py @@ -79,8 +79,7 @@ async def async_attach_trigger( ): return - zone_state = hass.states.get(zone_entity_id) - if not zone_state: + if not (zone_state := hass.states.get(zone_entity_id)): _LOGGER.warning( "Automation '%s' is referencing non-existing zone '%s' in a zone trigger", automation_info["name"], diff --git a/homeassistant/components/zwave_js/helpers.py b/homeassistant/components/zwave_js/helpers.py index 2eb440cec90..05df480a487 100644 --- a/homeassistant/components/zwave_js/helpers.py +++ b/homeassistant/components/zwave_js/helpers.py @@ -302,8 +302,7 @@ def async_is_device_config_entry_not_loaded( ) -> bool: """Return whether device's config entries are not loaded.""" dev_reg = dr.async_get(hass) - device = dev_reg.async_get(device_id) - if device is None: + if (device := dev_reg.async_get(device_id)) is None: raise ValueError(f"Device {device_id} not found") return any( (entry := hass.config_entries.async_get_entry(entry_id))