Improve device condition type hinting (#54906)
This commit is contained in:
parent
9633b9fe6e
commit
debc6d632c
8 changed files with 40 additions and 14 deletions
|
@ -43,6 +43,8 @@ from . import (
|
|||
DOMAIN,
|
||||
)
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
DEVICE_CLASS_NONE = "none"
|
||||
|
||||
CONF_IS_BAT_LOW = "is_bat_low"
|
||||
|
@ -266,7 +268,9 @@ def async_condition_from_config(
|
|||
return condition.state_from_config(state_config)
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
return {
|
||||
"extra_fields": vol.Schema(
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Provides device automations for Cover."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -38,6 +36,8 @@ from . import (
|
|||
SUPPORT_SET_TILT_POSITION,
|
||||
)
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
POSITION_CONDITION_TYPES = {"is_position", "is_tilt_position"}
|
||||
STATE_CONDITION_TYPES = {"is_open", "is_closed", "is_opening", "is_closing"}
|
||||
|
||||
|
@ -67,10 +67,12 @@ STATE_CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
|
|||
CONDITION_SCHEMA = vol.Any(POSITION_CONDITION_SCHEMA, STATE_CONDITION_SCHEMA)
|
||||
|
||||
|
||||
async def async_get_conditions(hass: HomeAssistant, device_id: str) -> list[dict]:
|
||||
async def async_get_conditions(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> list[dict[str, str]]:
|
||||
"""List device conditions for Cover devices."""
|
||||
registry = await entity_registry.async_get_registry(hass)
|
||||
conditions: list[dict[str, Any]] = []
|
||||
conditions: list[dict[str, str]] = []
|
||||
|
||||
# Get all the integrations entities for this device
|
||||
for entry in entity_registry.async_entries_for_device(registry, device_id):
|
||||
|
@ -100,7 +102,9 @@ async def async_get_conditions(hass: HomeAssistant, device_id: str) -> list[dict
|
|||
return conditions
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
if config[CONF_TYPE] not in ["is_position", "is_tilt_position"]:
|
||||
return {}
|
||||
|
|
|
@ -217,7 +217,9 @@ async def async_get_triggers(
|
|||
return await _async_get_automations(hass, device_id, ENTITY_TRIGGERS, domain)
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
return {
|
||||
"extra_fields": vol.Schema(
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.helpers.typing import ConfigType
|
|||
|
||||
from . import DOMAIN
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
|
||||
{vol.Required(CONF_DOMAIN): DOMAIN}
|
||||
)
|
||||
|
@ -33,6 +35,8 @@ async def async_get_conditions(
|
|||
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
return await toggle_entity.async_get_condition_capabilities(hass, config)
|
||||
|
|
|
@ -23,6 +23,8 @@ from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
|||
|
||||
from . import DOMAIN
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
CONDITION_TYPES = {
|
||||
"is_locked",
|
||||
"is_unlocked",
|
||||
|
@ -39,7 +41,9 @@ CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
|
|||
)
|
||||
|
||||
|
||||
async def async_get_conditions(hass: HomeAssistant, device_id: str) -> list[dict]:
|
||||
async def async_get_conditions(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> list[dict[str, str]]:
|
||||
"""List device conditions for Lock devices."""
|
||||
registry = await entity_registry.async_get_registry(hass)
|
||||
conditions = []
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.helpers.typing import ConfigType
|
|||
|
||||
from . import DOMAIN
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
|
||||
{vol.Required(CONF_DOMAIN): DOMAIN}
|
||||
)
|
||||
|
@ -33,6 +35,8 @@ async def async_get_conditions(
|
|||
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
return await toggle_entity.async_get_condition_capabilities(hass, config)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Provide the device conditions for Select."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
|
@ -21,6 +19,8 @@ from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
|||
|
||||
from .const import ATTR_OPTIONS, CONF_OPTION, DOMAIN
|
||||
|
||||
# nypy: disallow-any-generics
|
||||
|
||||
CONDITION_TYPES = {"selected_option"}
|
||||
|
||||
CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
|
||||
|
@ -71,7 +71,7 @@ def async_condition_from_config(
|
|||
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, Any]:
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
try:
|
||||
options = get_capability(hass, config[CONF_ENTITY_ID], ATTR_OPTIONS) or []
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.helpers.typing import ConfigType
|
|||
|
||||
from . import DOMAIN
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
|
||||
{vol.Required(CONF_DOMAIN): DOMAIN}
|
||||
)
|
||||
|
@ -33,6 +35,8 @@ async def async_get_conditions(
|
|||
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
|
||||
|
||||
|
||||
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
||||
async def async_get_condition_capabilities(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> dict[str, vol.Schema]:
|
||||
"""List condition capabilities."""
|
||||
return await toggle_entity.async_get_condition_capabilities(hass, config)
|
||||
|
|
Loading…
Add table
Reference in a new issue