Enable basic type checking for config (#66197)

This commit is contained in:
Erik Montnemery 2022-02-09 19:09:55 +01:00 committed by GitHub
parent d4995624ee
commit 83a10cca53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 49 deletions

View file

@ -60,7 +60,6 @@ async def websocket_delete(hass, connection, msg):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "config/auth/create",
@ -69,6 +68,7 @@ async def websocket_delete(hass, connection, msg):
vol.Optional("local_only"): bool,
}
)
@websocket_api.async_response
async def websocket_create(hass, connection, msg):
"""Create a user."""
user = await hass.auth.async_create_user(
@ -81,7 +81,6 @@ async def websocket_create(hass, connection, msg):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "config/auth/update",
@ -92,6 +91,7 @@ async def websocket_create(hass, connection, msg):
vol.Optional("local_only"): bool,
}
)
@websocket_api.async_response
async def websocket_update(hass, connection, msg):
"""Update a user."""
if not (user := await hass.auth.async_get_user(msg.pop("user_id"))):

View file

@ -262,7 +262,6 @@ def get_entry(
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{
"type": "config_entries/update",
@ -272,6 +271,7 @@ def get_entry(
vol.Optional("pref_disable_polling"): bool,
}
)
@websocket_api.async_response
async def config_entry_update(hass, connection, msg):
"""Update config entry."""
changes = dict(msg)
@ -305,7 +305,6 @@ async def config_entry_update(hass, connection, msg):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{
"type": "config_entries/disable",
@ -315,6 +314,7 @@ async def config_entry_update(hass, connection, msg):
"disabled_by": vol.Any(config_entries.ConfigEntryDisabler.USER.value, None),
}
)
@websocket_api.async_response
async def config_entry_disable(hass, connection, msg):
"""Disable config entry."""
disabled_by = msg["disabled_by"]
@ -339,10 +339,10 @@ async def config_entry_disable(hass, connection, msg):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{"type": "config_entries/ignore_flow", "flow_id": str, "title": str}
)
@websocket_api.async_response
async def ignore_config_flow(hass, connection, msg):
"""Ignore a config flow."""
flow = next(

View file

@ -35,7 +35,6 @@ class CheckConfigView(HomeAssistantView):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command(
{
"type": "config/core/update",
@ -50,6 +49,7 @@ class CheckConfigView(HomeAssistantView):
vol.Optional("currency"): cv.currency,
}
)
@websocket_api.async_response
async def websocket_update_config(hass, connection, msg):
"""Handle update core config command."""
data = dict(msg)
@ -64,8 +64,8 @@ async def websocket_update_config(hass, connection, msg):
@websocket_api.require_admin
@websocket_api.async_response
@websocket_api.websocket_command({"type": "config/core/detect"})
@websocket_api.async_response
async def websocket_detect_config(hass, connection, msg):
"""Detect core config."""
session = async_get_clientsession(hass)

View file

@ -4,15 +4,12 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import websocket_api
from homeassistant.components.websocket_api.const import ERR_NOT_FOUND
from homeassistant.components.websocket_api.decorators import (
async_response,
require_admin,
)
from homeassistant.components.websocket_api.decorators import require_admin
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_registry import (
RegistryEntryDisabler,
async_get_registry,
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
entity_registry as er,
)
@ -25,14 +22,11 @@ async def async_setup(hass):
return True
@async_response
@websocket_api.websocket_command({vol.Required("type"): "config/entity_registry/list"})
async def websocket_list_entities(hass, connection, msg):
"""Handle list registry entries command.
Async friendly.
"""
registry = await async_get_registry(hass)
@callback
def websocket_list_entities(hass, connection, msg):
"""Handle list registry entries command."""
registry = er.async_get(hass)
connection.send_message(
websocket_api.result_message(
msg["id"], [_entry_dict(entry) for entry in registry.entities.values()]
@ -40,19 +34,19 @@ async def websocket_list_entities(hass, connection, msg):
)
@async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "config/entity_registry/get",
vol.Required("entity_id"): cv.entity_id,
}
)
async def websocket_get_entity(hass, connection, msg):
@callback
def websocket_get_entity(hass, connection, msg):
"""Handle get entity registry entry command.
Async friendly.
"""
registry = await async_get_registry(hass)
registry = er.async_get(hass)
if (entry := registry.entities.get(msg["entity_id"])) is None:
connection.send_message(
@ -66,7 +60,6 @@ async def websocket_get_entity(hass, connection, msg):
@require_admin
@async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "config/entity_registry/update",
@ -81,17 +74,19 @@ async def websocket_get_entity(hass, connection, msg):
vol.Optional("disabled_by"): vol.Any(
None,
vol.All(
vol.Coerce(RegistryEntryDisabler), RegistryEntryDisabler.USER.value
vol.Coerce(er.RegistryEntryDisabler),
er.RegistryEntryDisabler.USER.value,
),
),
}
)
async def websocket_update_entity(hass, connection, msg):
@callback
def websocket_update_entity(hass, connection, msg):
"""Handle update entity websocket command.
Async friendly.
"""
registry = await async_get_registry(hass)
registry = er.async_get(hass)
if msg["entity_id"] not in registry.entities:
connection.send_message(
@ -120,7 +115,7 @@ async def websocket_update_entity(hass, connection, msg):
if "disabled_by" in msg and msg["disabled_by"] is None:
entity = registry.entities[msg["entity_id"]]
if entity.device_id:
device_registry = await hass.helpers.device_registry.async_get_registry()
device_registry = dr.async_get(hass)
device = device_registry.async_get(entity.device_id)
if device.disabled:
connection.send_message(
@ -149,19 +144,19 @@ async def websocket_update_entity(hass, connection, msg):
@require_admin
@async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "config/entity_registry/remove",
vol.Required("entity_id"): cv.entity_id,
}
)
async def websocket_remove_entity(hass, connection, msg):
@callback
def websocket_remove_entity(hass, connection, msg):
"""Handle remove entity websocket command.
Async friendly.
"""
registry = await async_get_registry(hass)
registry = er.async_get(hass)
if msg["entity_id"] not in registry.entities:
connection.send_message(

View file

@ -2145,18 +2145,6 @@ ignore_errors = true
[mypy-homeassistant.components.cloud.http_api]
ignore_errors = true
[mypy-homeassistant.components.config.auth]
ignore_errors = true
[mypy-homeassistant.components.config.config_entries]
ignore_errors = true
[mypy-homeassistant.components.config.core]
ignore_errors = true
[mypy-homeassistant.components.config.entity_registry]
ignore_errors = true
[mypy-homeassistant.components.conversation]
ignore_errors = true

View file

@ -21,10 +21,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.blueprint.websocket_api",
"homeassistant.components.cloud.client",
"homeassistant.components.cloud.http_api",
"homeassistant.components.config.auth",
"homeassistant.components.config.config_entries",
"homeassistant.components.config.core",
"homeassistant.components.config.entity_registry",
"homeassistant.components.conversation",
"homeassistant.components.conversation.default_agent",
"homeassistant.components.deconz",