diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 62c416a98830..35804cd8483c 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -2,9 +2,10 @@ import asyncio import logging from collections import OrderedDict +from typing import List, Awaitable from homeassistant import data_entry_flow -from homeassistant.core import callback +from homeassistant.core import callback, HomeAssistant from . import models from . import auth_store @@ -13,7 +14,9 @@ from .providers import auth_provider_from_config _LOGGER = logging.getLogger(__name__) -async def auth_manager_from_config(hass, provider_configs): +async def auth_manager_from_config( + hass: HomeAssistant, + provider_configs: List[dict]) -> Awaitable['AuthManager']: """Initialize an auth manager from config.""" store = auth_store.AuthStore(hass) if provider_configs: diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index 06e28c42b13c..bf1577cbf01f 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -10,6 +10,7 @@ Component design guidelines: import asyncio import itertools as it import logging +from typing import Awaitable import homeassistant.core as ha import homeassistant.config as conf_util @@ -109,7 +110,7 @@ def async_reload_core_config(hass): @asyncio.coroutine -def async_setup(hass, config): +def async_setup(hass: ha.HomeAssistant, config: dict) -> Awaitable[bool]: """Set up general services related to Home Assistant.""" @asyncio.coroutine def async_handle_turn_service(service): diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index cce3550d35c8..2850a5f96cd9 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -6,10 +6,11 @@ https://home-assistant.io/components/persistent_notification/ """ import asyncio import logging +from typing import Awaitable import voluptuous as vol -from homeassistant.core import callback +from homeassistant.core import callback, HomeAssistant from homeassistant.exceptions import TemplateError from homeassistant.loader import bind_hass from homeassistant.helpers import config_validation as cv @@ -58,7 +59,8 @@ def dismiss(hass, notification_id): @callback @bind_hass -def async_create(hass, message, title=None, notification_id=None): +def async_create(hass: HomeAssistant, message: str, title: str = None, + notification_id: str = None) -> None: """Generate a notification.""" data = { key: value for key, value in [ @@ -68,7 +70,8 @@ def async_create(hass, message, title=None, notification_id=None): ] if value is not None } - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_CREATE, data)) + hass.async_create_task( + hass.services.async_call(DOMAIN, SERVICE_CREATE, data)) @callback @@ -81,7 +84,7 @@ def async_dismiss(hass, notification_id): @asyncio.coroutine -def async_setup(hass, config): +def async_setup(hass: HomeAssistant, config: dict) -> Awaitable[bool]: """Set up the persistent notification component.""" @callback def create_service(call): diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 8e2bb3fa5df9..12420e989eea 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -113,7 +113,7 @@ the flow from the config panel. import logging import uuid -from typing import Set, Optional # noqa pylint: disable=unused-import +from typing import Set, Optional, List # noqa pylint: disable=unused-import from homeassistant import data_entry_flow from homeassistant.core import callback, HomeAssistant @@ -270,19 +270,19 @@ class ConfigEntries: An instance of this object is available via `hass.config_entries`. """ - def __init__(self, hass, hass_config): + def __init__(self, hass: HomeAssistant, hass_config: dict) -> None: """Initialize the entry manager.""" self.hass = hass self.flow = data_entry_flow.FlowManager( hass, self._async_create_flow, self._async_finish_flow) self._hass_config = hass_config - self._entries = None + self._entries = [] # type: List[ConfigEntry] self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY) @callback - def async_domains(self): + def async_domains(self) -> List[str]: """Return domains for which we have entries.""" - seen = set() # type: Set[ConfigEntry] + seen = set() # type: Set[str] result = [] for entry in self._entries: @@ -293,7 +293,7 @@ class ConfigEntries: return result @callback - def async_entries(self, domain=None): + def async_entries(self, domain: str = None) -> List[ConfigEntry]: """Return all entries or entries for a specific domain.""" if domain is None: return list(self._entries) @@ -319,7 +319,7 @@ class ConfigEntries: 'require_restart': not unloaded } - async def async_load(self): + async def async_load(self) -> None: """Handle loading the config.""" # Migrating for config entries stored before 0.73 config = await self.hass.helpers.storage.async_migrator( diff --git a/homeassistant/helpers/entity_values.py b/homeassistant/helpers/entity_values.py index 5caa6b93131f..77739f8adabb 100644 --- a/homeassistant/helpers/entity_values.py +++ b/homeassistant/helpers/entity_values.py @@ -2,6 +2,7 @@ from collections import OrderedDict import fnmatch import re +from typing import Dict from homeassistant.core import split_entity_id @@ -9,7 +10,8 @@ from homeassistant.core import split_entity_id class EntityValues: """Class to store entity id based values.""" - def __init__(self, exact=None, domain=None, glob=None): + def __init__(self, exact: Dict = None, domain: Dict = None, + glob: Dict = None) -> None: """Initialize an EntityConfigDict.""" self._cache = {} self._exact = exact diff --git a/homeassistant/helpers/signal.py b/homeassistant/helpers/signal.py index 3ea52388d338..824b32177cdb 100644 --- a/homeassistant/helpers/signal.py +++ b/homeassistant/helpers/signal.py @@ -3,7 +3,7 @@ import logging import signal import sys -from homeassistant.core import callback +from homeassistant.core import callback, HomeAssistant from homeassistant.const import RESTART_EXIT_CODE from homeassistant.loader import bind_hass @@ -12,13 +12,13 @@ _LOGGER = logging.getLogger(__name__) @callback @bind_hass -def async_register_signal_handling(hass): +def async_register_signal_handling(hass: HomeAssistant) -> None: """Register system signal handler for core.""" if sys.platform != 'win32': @callback def async_signal_handle(exit_code): """Wrap signal handling.""" - hass.async_add_job(hass.async_stop(exit_code)) + hass.async_create_task(hass.async_stop(exit_code)) try: hass.loop.add_signal_handler( diff --git a/mypy.ini b/mypy.ini index c92786e643fd..875aec5eda79 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,5 +1,6 @@ [mypy] check_untyped_defs = true +disallow_untyped_calls = true follow_imports = silent ignore_missing_imports = true warn_incomplete_stub = true @@ -16,4 +17,5 @@ disallow_untyped_defs = false [mypy-homeassistant.util.yaml] warn_return_any = false +disallow_untyped_calls = false