Use assignment expressions [other] (#66882)
This commit is contained in:
parent
4f20a8023b
commit
45d8d04c40
10 changed files with 15 additions and 35 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue