Complete some incomplete type hints in helpers (#25953)
This commit is contained in:
parent
3525728abc
commit
aa508b5106
7 changed files with 28 additions and 22 deletions
|
@ -27,8 +27,7 @@ import homeassistant.util.yaml.loader as yaml_loader
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
|
# mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any
|
||||||
# mypy: no-warn-return-any
|
|
||||||
|
|
||||||
CheckConfigError = namedtuple("CheckConfigError", "message domain config")
|
CheckConfigError = namedtuple("CheckConfigError", "message domain config")
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from .typing import HomeAssistantType
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-defs
|
# mypy: allow-untyped-defs
|
||||||
|
|
||||||
|
|
||||||
def register_discovery_flow(domain, title, discovery_function, connection_class):
|
def register_discovery_flow(domain, title, discovery_function, connection_class):
|
||||||
|
@ -130,7 +131,9 @@ class WebhookFlowHandler(config_entries.ConfigFlow):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def webhook_async_remove_entry(hass, entry) -> None:
|
async def webhook_async_remove_entry(
|
||||||
|
hass: HomeAssistantType, entry: config_entries.ConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Remove a webhook config entry."""
|
"""Remove a webhook config entry."""
|
||||||
if not entry.data.get("cloudhook") or "cloud" not in hass.config.components:
|
if not entry.data.get("cloudhook") or "cloud" not in hass.config.components:
|
||||||
return
|
return
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.loader import bind_hass
|
||||||
from .typing import HomeAssistantType
|
from .typing import HomeAssistantType
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
|
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||||
# mypy: no-check-untyped-defs, no-warn-return-any
|
# mypy: no-check-untyped-defs, no-warn-return-any
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -84,7 +84,9 @@ class DeviceRegistry:
|
||||||
return self.devices.get(device_id)
|
return self.devices.get(device_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_device(self, identifiers: set, connections: set):
|
def async_get_device(
|
||||||
|
self, identifiers: set, connections: set
|
||||||
|
) -> Optional[DeviceEntry]:
|
||||||
"""Check if device is registered."""
|
"""Check if device is registered."""
|
||||||
for device in self.devices.values():
|
for device in self.devices.values():
|
||||||
if any(iden in device.identifiers for iden in identifiers) or any(
|
if any(iden in device.identifiers for iden in identifiers) or any(
|
||||||
|
|
|
@ -3,7 +3,7 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
import functools as ft
|
import functools as ft
|
||||||
from timeit import default_timer as timer
|
from timeit import default_timer as timer
|
||||||
from typing import Optional, List, Iterable
|
from typing import Any, Optional, List, Iterable
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
|
@ -34,8 +34,7 @@ from homeassistant.util.async_ import run_callback_threadsafe
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs, no-warn-return-any
|
||||||
# mypy: no-warn-return-any
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
SLOW_UPDATE_WARNING = 10
|
SLOW_UPDATE_WARNING = 10
|
||||||
|
@ -532,7 +531,7 @@ class ToggleEntity(Entity):
|
||||||
"""Return True if entity is on."""
|
"""Return True if entity is on."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def turn_on(self, **kwargs) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -543,7 +542,7 @@ class ToggleEntity(Entity):
|
||||||
"""
|
"""
|
||||||
return self.hass.async_add_job(ft.partial(self.turn_on, **kwargs))
|
return self.hass.async_add_job(ft.partial(self.turn_on, **kwargs))
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -554,7 +553,7 @@ class ToggleEntity(Entity):
|
||||||
"""
|
"""
|
||||||
return self.hass.async_add_job(ft.partial(self.turn_off, **kwargs))
|
return self.hass.async_add_job(ft.partial(self.turn_off, **kwargs))
|
||||||
|
|
||||||
def toggle(self, **kwargs) -> None:
|
def toggle(self, **kwargs: Any) -> None:
|
||||||
"""Toggle the entity."""
|
"""Toggle the entity."""
|
||||||
if self.is_on:
|
if self.is_on:
|
||||||
self.turn_off(**kwargs)
|
self.turn_off(**kwargs)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.util.yaml import load_yaml
|
||||||
from .typing import HomeAssistantType
|
from .typing import HomeAssistantType
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
|
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||||
# mypy: no-check-untyped-defs, no-warn-return-any
|
# mypy: no-check-untyped-defs, no-warn-return-any
|
||||||
|
|
||||||
PATH_REGISTRY = "entity_registry.yaml"
|
PATH_REGISTRY = "entity_registry.yaml"
|
||||||
|
@ -91,7 +91,9 @@ class EntityRegistry:
|
||||||
return self.entities.get(entity_id)
|
return self.entities.get(entity_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_entity_id(self, domain: str, platform: str, unique_id: str):
|
def async_get_entity_id(
|
||||||
|
self, domain: str, platform: str, unique_id: str
|
||||||
|
) -> Optional[str]:
|
||||||
"""Check if an entity_id is currently registered."""
|
"""Check if an entity_id is currently registered."""
|
||||||
for entity in self.entities.values():
|
for entity in self.entities.values():
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -18,12 +18,13 @@ from homeassistant.exceptions import (
|
||||||
from homeassistant.helpers import template, typing
|
from homeassistant.helpers import template, typing
|
||||||
from homeassistant.loader import async_get_integration, bind_hass
|
from homeassistant.loader import async_get_integration, bind_hass
|
||||||
from homeassistant.util.yaml import load_yaml
|
from homeassistant.util.yaml import load_yaml
|
||||||
|
from homeassistant.util.yaml.loader import JSON_TYPE
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util.async_ import run_coroutine_threadsafe
|
from homeassistant.util.async_ import run_coroutine_threadsafe
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
|
|
||||||
CONF_SERVICE = "service"
|
CONF_SERVICE = "service"
|
||||||
CONF_SERVICE_TEMPLATE = "service_template"
|
CONF_SERVICE_TEMPLATE = "service_template"
|
||||||
|
@ -161,7 +162,7 @@ async def async_extract_entity_ids(hass, service_call, expand_group=True):
|
||||||
return extracted
|
return extracted
|
||||||
|
|
||||||
|
|
||||||
async def _load_services_file(hass: HomeAssistantType, domain: str):
|
async def _load_services_file(hass: HomeAssistantType, domain: str) -> JSON_TYPE:
|
||||||
"""Load services file for an integration."""
|
"""Load services file for an integration."""
|
||||||
integration = await async_get_integration(hass, domain)
|
integration = await async_get_integration(hass, domain)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -6,14 +6,13 @@ import os
|
||||||
from typing import Dict, List, Optional, Callable, Union, Any, Type
|
from typing import Dict, List, Optional, Callable, Union, Any, Type
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.util import json as json_util
|
from homeassistant.util import json as json_util
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
|
|
||||||
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
|
# mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any
|
||||||
# mypy: no-warn-return-any
|
|
||||||
|
|
||||||
STORAGE_DIR = ".storage"
|
STORAGE_DIR = ".storage"
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -59,7 +58,7 @@ class Store:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
version: int,
|
version: int,
|
||||||
key: str,
|
key: str,
|
||||||
private: bool = False,
|
private: bool = False,
|
||||||
|
@ -94,6 +93,7 @@ class Store:
|
||||||
"""
|
"""
|
||||||
if self._load_task is None:
|
if self._load_task is None:
|
||||||
self._load_task = self.hass.async_add_job(self._async_load())
|
self._load_task = self.hass.async_add_job(self._async_load())
|
||||||
|
assert self._load_task is not None
|
||||||
|
|
||||||
return await self._load_task
|
return await self._load_task
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class Store:
|
||||||
@callback
|
@callback
|
||||||
def async_delay_save(
|
def async_delay_save(
|
||||||
self, data_func: Callable[[], Dict], delay: Optional[int] = None
|
self, data_func: Callable[[], Dict], delay: Optional[int] = None
|
||||||
):
|
) -> None:
|
||||||
"""Save data with an optional delay."""
|
"""Save data with an optional delay."""
|
||||||
self._data = {"version": self.version, "key": self.key, "data_func": data_func}
|
self._data = {"version": self.version, "key": self.key, "data_func": data_func}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ class Store:
|
||||||
except (json_util.SerializationError, json_util.WriteError) as err:
|
except (json_util.SerializationError, json_util.WriteError) as err:
|
||||||
_LOGGER.error("Error writing config for %s: %s", self.key, err)
|
_LOGGER.error("Error writing config for %s: %s", self.key, err)
|
||||||
|
|
||||||
def _write_data(self, path: str, data: Dict):
|
def _write_data(self, path: str, data: Dict) -> None:
|
||||||
"""Write the data."""
|
"""Write the data."""
|
||||||
if not os.path.isdir(os.path.dirname(path)):
|
if not os.path.isdir(os.path.dirname(path)):
|
||||||
os.makedirs(os.path.dirname(path))
|
os.makedirs(os.path.dirname(path))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue