From c260413e2a344256e8328e498ab45fc179c29cd6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:08:50 +0200 Subject: [PATCH] Remove lovelace from mypy ignore list (#75167) * Remove lovelace from mypy ignore list * Raise error on failed config --- homeassistant/components/lovelace/__init__.py | 8 ++++++-- homeassistant/components/lovelace/resources.py | 4 ++-- homeassistant/components/lovelace/websocket.py | 8 ++++---- mypy.ini | 12 ------------ script/hassfest/mypy_config.py | 4 ---- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/lovelace/__init__.py b/homeassistant/components/lovelace/__init__.py index 9b268dfdfcd..cf74a3a588c 100644 --- a/homeassistant/components/lovelace/__init__.py +++ b/homeassistant/components/lovelace/__init__.py @@ -86,11 +86,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: config = await async_process_component_config(hass, conf, integration) + if config is None: + raise HomeAssistantError("Config validation failed") + resource_collection = await create_yaml_resource_col( hass, config[DOMAIN].get(CONF_RESOURCES) ) hass.data[DOMAIN]["resources"] = resource_collection + default_config: dashboard.LovelaceConfig if mode == MODE_YAML: default_config = dashboard.LovelaceYAML(hass, None, None) resource_collection = await create_yaml_resource_col(hass, yaml_resources) @@ -179,8 +183,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # Process YAML dashboards for url_path, dashboard_conf in hass.data[DOMAIN]["yaml_dashboards"].items(): # For now always mode=yaml - config = dashboard.LovelaceYAML(hass, url_path, dashboard_conf) - hass.data[DOMAIN]["dashboards"][url_path] = config + lovelace_config = dashboard.LovelaceYAML(hass, url_path, dashboard_conf) + hass.data[DOMAIN]["dashboards"][url_path] = lovelace_config try: _register_panel(hass, url_path, MODE_YAML, dashboard_conf, False) diff --git a/homeassistant/components/lovelace/resources.py b/homeassistant/components/lovelace/resources.py index 22297c54d6c..7e7c670baf5 100644 --- a/homeassistant/components/lovelace/resources.py +++ b/homeassistant/components/lovelace/resources.py @@ -7,7 +7,7 @@ import uuid import voluptuous as vol -from homeassistant.const import CONF_RESOURCES, CONF_TYPE +from homeassistant.const import CONF_ID, CONF_RESOURCES, CONF_TYPE from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import collection, storage @@ -94,7 +94,7 @@ class ResourceStorageCollection(collection.StorageCollection): conf.pop(CONF_RESOURCES) for item in data: - item[collection.CONF_ID] = uuid.uuid4().hex + item[CONF_ID] = uuid.uuid4().hex data = {"items": data} diff --git a/homeassistant/components/lovelace/websocket.py b/homeassistant/components/lovelace/websocket.py index 45a042c1f2e..cb45d9cfbc6 100644 --- a/homeassistant/components/lovelace/websocket.py +++ b/homeassistant/components/lovelace/websocket.py @@ -45,8 +45,8 @@ def _handle_errors(func): return send_with_error_handling -@websocket_api.async_response @websocket_api.websocket_command({"type": "lovelace/resources"}) +@websocket_api.async_response async def websocket_lovelace_resources(hass, connection, msg): """Send Lovelace UI resources over WebSocket configuration.""" resources = hass.data[DOMAIN]["resources"] @@ -58,7 +58,6 @@ async def websocket_lovelace_resources(hass, connection, msg): connection.send_result(msg["id"], resources.async_items()) -@websocket_api.async_response @websocket_api.websocket_command( { "type": "lovelace/config", @@ -66,6 +65,7 @@ async def websocket_lovelace_resources(hass, connection, msg): vol.Optional(CONF_URL_PATH): vol.Any(None, cv.string), } ) +@websocket_api.async_response @_handle_errors async def websocket_lovelace_config(hass, connection, msg, config): """Send Lovelace UI config over WebSocket configuration.""" @@ -73,7 +73,6 @@ async def websocket_lovelace_config(hass, connection, msg, config): @websocket_api.require_admin -@websocket_api.async_response @websocket_api.websocket_command( { "type": "lovelace/config/save", @@ -81,6 +80,7 @@ async def websocket_lovelace_config(hass, connection, msg, config): vol.Optional(CONF_URL_PATH): vol.Any(None, cv.string), } ) +@websocket_api.async_response @_handle_errors async def websocket_lovelace_save_config(hass, connection, msg, config): """Save Lovelace UI configuration.""" @@ -88,13 +88,13 @@ async def websocket_lovelace_save_config(hass, connection, msg, config): @websocket_api.require_admin -@websocket_api.async_response @websocket_api.websocket_command( { "type": "lovelace/config/delete", vol.Optional(CONF_URL_PATH): vol.Any(None, cv.string), } ) +@websocket_api.async_response @_handle_errors async def websocket_lovelace_delete_config(hass, connection, msg, config): """Delete Lovelace UI configuration.""" diff --git a/mypy.ini b/mypy.ini index 8588209b87a..93ae6c2f78c 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2668,18 +2668,6 @@ ignore_errors = true [mypy-homeassistant.components.evohome.climate] ignore_errors = true -[mypy-homeassistant.components.lovelace] -ignore_errors = true - -[mypy-homeassistant.components.lovelace.dashboard] -ignore_errors = true - -[mypy-homeassistant.components.lovelace.resources] -ignore_errors = true - -[mypy-homeassistant.components.lovelace.websocket] -ignore_errors = true - [mypy-homeassistant.components.minecraft_server] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 992d8836916..3b8e80490b6 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -20,10 +20,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.cloud.http_api", "homeassistant.components.evohome", "homeassistant.components.evohome.climate", - "homeassistant.components.lovelace", - "homeassistant.components.lovelace.dashboard", - "homeassistant.components.lovelace.resources", - "homeassistant.components.lovelace.websocket", "homeassistant.components.minecraft_server", "homeassistant.components.minecraft_server.helpers", "homeassistant.components.minecraft_server.sensor",