Complete some incomplete type hints in helpers (#25953)

This commit is contained in:
Ville Skyttä 2019-08-15 18:53:25 +03:00 committed by Paulus Schoutsen
parent 3525728abc
commit aa508b5106
7 changed files with 28 additions and 22 deletions

View file

@ -27,8 +27,7 @@ import homeassistant.util.yaml.loader as yaml_loader
from homeassistant.exceptions import HomeAssistantError
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-warn-return-any
# mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any
CheckConfigError = namedtuple("CheckConfigError", "message domain config")

View file

@ -2,9 +2,10 @@
from functools import partial
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):
@ -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."""
if not entry.data.get("cloudhook") or "cloud" not in hass.config.components:
return

View file

@ -13,7 +13,7 @@ from homeassistant.loader import bind_hass
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
_LOGGER = logging.getLogger(__name__)
@ -84,7 +84,9 @@ class DeviceRegistry:
return self.devices.get(device_id)
@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."""
for device in self.devices.values():
if any(iden in device.identifiers for iden in identifiers) or any(

View file

@ -3,7 +3,7 @@ from datetime import timedelta
import logging
import functools as ft
from timeit import default_timer as timer
from typing import Optional, List, Iterable
from typing import Any, Optional, List, Iterable
from homeassistant.const import (
ATTR_ASSUMED_STATE,
@ -34,8 +34,7 @@ from homeassistant.util.async_ import run_callback_threadsafe
from homeassistant.util import dt as dt_util
# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs
# mypy: no-warn-return-any
# mypy: allow-untyped-defs, no-check-untyped-defs, no-warn-return-any
_LOGGER = logging.getLogger(__name__)
SLOW_UPDATE_WARNING = 10
@ -532,7 +531,7 @@ class ToggleEntity(Entity):
"""Return True if entity is on."""
raise NotImplementedError()
def turn_on(self, **kwargs) -> None:
def turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
raise NotImplementedError()
@ -543,7 +542,7 @@ class ToggleEntity(Entity):
"""
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."""
raise NotImplementedError()
@ -554,7 +553,7 @@ class ToggleEntity(Entity):
"""
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."""
if self.is_on:
self.turn_off(**kwargs)

View file

@ -24,7 +24,7 @@ from homeassistant.util.yaml import load_yaml
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
PATH_REGISTRY = "entity_registry.yaml"
@ -91,7 +91,9 @@ class EntityRegistry:
return self.entities.get(entity_id)
@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."""
for entity in self.entities.values():
if (

View file

@ -18,12 +18,13 @@ from homeassistant.exceptions import (
from homeassistant.helpers import template, typing
from homeassistant.loader import async_get_integration, bind_hass
from homeassistant.util.yaml import load_yaml
from homeassistant.util.yaml.loader import JSON_TYPE
import homeassistant.helpers.config_validation as cv
from homeassistant.util.async_ import run_coroutine_threadsafe
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_TEMPLATE = "service_template"
@ -161,7 +162,7 @@ async def async_extract_entity_ids(hass, service_call, expand_group=True):
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."""
integration = await async_get_integration(hass, domain)
try:

View file

@ -6,14 +6,13 @@ import os
from typing import Dict, List, Optional, Callable, Union, Any, Type
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.util import json as json_util
from homeassistant.helpers.event import async_call_later
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-warn-return-any
# mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any
STORAGE_DIR = ".storage"
_LOGGER = logging.getLogger(__name__)
@ -59,7 +58,7 @@ class Store:
def __init__(
self,
hass,
hass: HomeAssistant,
version: int,
key: str,
private: bool = False,
@ -94,6 +93,7 @@ class Store:
"""
if self._load_task is None:
self._load_task = self.hass.async_add_job(self._async_load())
assert self._load_task is not None
return await self._load_task
@ -138,7 +138,7 @@ class Store:
@callback
def async_delay_save(
self, data_func: Callable[[], Dict], delay: Optional[int] = None
):
) -> None:
"""Save data with an optional delay."""
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:
_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."""
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))