diff --git a/homeassistant/components/blueprint/models.py b/homeassistant/components/blueprint/models.py index 7547a701220..ee81a583391 100644 --- a/homeassistant/components/blueprint/models.py +++ b/homeassistant/components/blueprint/models.py @@ -51,7 +51,7 @@ class Blueprint: def __init__( self, - data: dict, + data: dict[str, Any], *, path: str | None = None, expected_domain: str | None = None, diff --git a/homeassistant/components/blueprint/websocket_api.py b/homeassistant/components/blueprint/websocket_api.py index 0b84d1d08c2..a9bcf5ded1c 100644 --- a/homeassistant/components/blueprint/websocket_api.py +++ b/homeassistant/components/blueprint/websocket_api.py @@ -1,6 +1,8 @@ """Websocket API for blueprint.""" from __future__ import annotations +from typing import Any, cast + import async_timeout import voluptuous as vol @@ -31,12 +33,14 @@ def async_setup(hass: HomeAssistant): } ) @websocket_api.async_response -async def ws_list_blueprints(hass, connection, msg): +async def ws_list_blueprints( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """List available blueprints.""" - domain_blueprints: dict[str, models.DomainBlueprints] | None = hass.data.get( - DOMAIN, {} - ) - results = {} + domain_blueprints: dict[str, models.DomainBlueprints] = hass.data.get(DOMAIN, {}) + results: dict[str, Any] = {} if msg["domain"] not in domain_blueprints: connection.send_result(msg["id"], results) @@ -62,7 +66,11 @@ async def ws_list_blueprints(hass, connection, msg): } ) @websocket_api.async_response -async def ws_import_blueprint(hass, connection, msg): +async def ws_import_blueprint( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Import a blueprint.""" async with async_timeout.timeout(10): imported_blueprint = await importer.fetch_blueprint_from_url(hass, msg["url"]) @@ -96,15 +104,17 @@ async def ws_import_blueprint(hass, connection, msg): } ) @websocket_api.async_response -async def ws_save_blueprint(hass, connection, msg): +async def ws_save_blueprint( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Save a blueprint.""" path = msg["path"] domain = msg["domain"] - domain_blueprints: dict[str, models.DomainBlueprints] | None = hass.data.get( - DOMAIN, {} - ) + domain_blueprints: dict[str, models.DomainBlueprints] = hass.data.get(DOMAIN, {}) if domain not in domain_blueprints: connection.send_error( @@ -112,9 +122,8 @@ async def ws_save_blueprint(hass, connection, msg): ) try: - blueprint = models.Blueprint( - yaml.parse_yaml(msg["yaml"]), expected_domain=domain - ) + yaml_data = cast(dict[str, Any], yaml.parse_yaml(msg["yaml"])) + blueprint = models.Blueprint(yaml_data, expected_domain=domain) if "source_url" in msg: blueprint.update_metadata(source_url=msg["source_url"]) except HomeAssistantError as err: @@ -143,15 +152,17 @@ async def ws_save_blueprint(hass, connection, msg): } ) @websocket_api.async_response -async def ws_delete_blueprint(hass, connection, msg): +async def ws_delete_blueprint( + hass: HomeAssistant, + connection: websocket_api.ActiveConnection, + msg: dict[str, Any], +) -> None: """Delete a blueprint.""" path = msg["path"] domain = msg["domain"] - domain_blueprints: dict[str, models.DomainBlueprints] | None = hass.data.get( - DOMAIN, {} - ) + domain_blueprints: dict[str, models.DomainBlueprints] = hass.data.get(DOMAIN, {}) if domain not in domain_blueprints: connection.send_error(