diff --git a/homeassistant/auth/permissions/__init__.py b/homeassistant/auth/permissions/__init__.py index 5680b0aecb2..25253a1601c 100644 --- a/homeassistant/auth/permissions/__init__.py +++ b/homeassistant/auth/permissions/__init__.py @@ -7,6 +7,7 @@ from typing import ( # noqa: F401 Dict, List, Mapping, + Optional, Set, Tuple, Union, @@ -31,7 +32,7 @@ _LOGGER = logging.getLogger(__name__) class AbstractPermissions: """Default permissions class.""" - _cached_entity_func = None + _cached_entity_func: Optional[Callable[[str, str], bool]] = None def _entity_func(self) -> Callable[[str, str], bool]: """Return a function that can test entity access.""" diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index 8c14276ccc9..7bb572dcf6b 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -11,6 +11,9 @@ import logging from homeassistant.core import split_entity_id + +# mypy: allow-untyped-defs + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 935f6ea0d02..5de9336d1d9 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -30,6 +30,10 @@ from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.loader import bind_hass from homeassistant.util.dt import parse_datetime, utcnow + +# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs +# mypy: no-check-untyped-defs, no-warn-return-any + DOMAIN = "automation" ENTITY_ID_FORMAT = DOMAIN + ".{}" diff --git a/homeassistant/components/automation/device.py b/homeassistant/components/automation/device.py index 2bb70fa1c96..b090484ab67 100644 --- a/homeassistant/components/automation/device.py +++ b/homeassistant/components/automation/device.py @@ -5,6 +5,8 @@ from homeassistant.const import CONF_DOMAIN, CONF_PLATFORM from homeassistant.loader import async_get_integration +# mypy: allow-untyped-defs, no-check-untyped-defs + TRIGGER_SCHEMA = vol.Schema( {vol.Required(CONF_PLATFORM): "device", vol.Required(CONF_DOMAIN): str}, extra=vol.ALLOW_EXTRA, diff --git a/homeassistant/components/automation/event.py b/homeassistant/components/automation/event.py index b353eb56196..d372aedd1d7 100644 --- a/homeassistant/components/automation/event.py +++ b/homeassistant/components/automation/event.py @@ -7,6 +7,9 @@ from homeassistant.core import callback from homeassistant.const import CONF_PLATFORM from homeassistant.helpers import config_validation as cv + +# mypy: allow-untyped-defs + CONF_EVENT_TYPE = "event_type" CONF_EVENT_DATA = "event_data" diff --git a/homeassistant/components/automation/geo_location.py b/homeassistant/components/automation/geo_location.py index 7c0994c4b30..3f2aa1c00d7 100644 --- a/homeassistant/components/automation/geo_location.py +++ b/homeassistant/components/automation/geo_location.py @@ -13,6 +13,9 @@ from homeassistant.const import ( from homeassistant.helpers import condition, config_validation as cv from homeassistant.helpers.config_validation import entity_domain + +# mypy: allow-untyped-defs, no-check-untyped-defs + EVENT_ENTER = "enter" EVENT_LEAVE = "leave" DEFAULT_EVENT = EVENT_ENTER diff --git a/homeassistant/components/automation/homeassistant.py b/homeassistant/components/automation/homeassistant.py index 96931e62766..bd1da7e7e1f 100644 --- a/homeassistant/components/automation/homeassistant.py +++ b/homeassistant/components/automation/homeassistant.py @@ -6,6 +6,9 @@ import voluptuous as vol from homeassistant.core import callback, CoreState from homeassistant.const import CONF_PLATFORM, CONF_EVENT, EVENT_HOMEASSISTANT_STOP + +# mypy: allow-untyped-defs + EVENT_START = "start" EVENT_SHUTDOWN = "shutdown" _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/automation/litejet.py b/homeassistant/components/automation/litejet.py index c642781ca66..7bc4c937765 100644 --- a/homeassistant/components/automation/litejet.py +++ b/homeassistant/components/automation/litejet.py @@ -9,6 +9,9 @@ import homeassistant.helpers.config_validation as cv import homeassistant.util.dt as dt_util from homeassistant.helpers.event import track_point_in_utc_time + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) CONF_NUMBER = "number" diff --git a/homeassistant/components/automation/mqtt.py b/homeassistant/components/automation/mqtt.py index 26c1ea5683d..fd9a778dbfc 100644 --- a/homeassistant/components/automation/mqtt.py +++ b/homeassistant/components/automation/mqtt.py @@ -8,6 +8,9 @@ from homeassistant.components import mqtt from homeassistant.const import CONF_PLATFORM, CONF_PAYLOAD import homeassistant.helpers.config_validation as cv + +# mypy: allow-untyped-defs + CONF_ENCODING = "encoding" CONF_TOPIC = "topic" DEFAULT_ENCODING = "utf-8" diff --git a/homeassistant/components/automation/numeric_state.py b/homeassistant/components/automation/numeric_state.py index f990e599552..b33d724d770 100644 --- a/homeassistant/components/automation/numeric_state.py +++ b/homeassistant/components/automation/numeric_state.py @@ -16,6 +16,9 @@ from homeassistant.const import ( from homeassistant.helpers.event import async_track_state_change, async_track_same_state from homeassistant.helpers import condition, config_validation as cv, template + +# mypy: allow-untyped-defs, no-check-untyped-defs + TRIGGER_SCHEMA = vol.All( vol.Schema( { diff --git a/homeassistant/components/automation/state.py b/homeassistant/components/automation/state.py index ccea3d9ec5a..5fbe97185a7 100644 --- a/homeassistant/components/automation/state.py +++ b/homeassistant/components/automation/state.py @@ -9,6 +9,9 @@ from homeassistant.const import MATCH_ALL, CONF_PLATFORM, CONF_FOR from homeassistant.helpers import config_validation as cv, template from homeassistant.helpers.event import async_track_state_change, async_track_same_state + +# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) CONF_ENTITY_ID = "entity_id" diff --git a/homeassistant/components/automation/sun.py b/homeassistant/components/automation/sun.py index e4d41830e0f..7cbbe56f326 100644 --- a/homeassistant/components/automation/sun.py +++ b/homeassistant/components/automation/sun.py @@ -14,6 +14,9 @@ from homeassistant.const import ( from homeassistant.helpers.event import async_track_sunrise, async_track_sunset import homeassistant.helpers.config_validation as cv + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) TRIGGER_SCHEMA = vol.Schema( diff --git a/homeassistant/components/automation/template.py b/homeassistant/components/automation/template.py index a48f252312b..c83d660912c 100644 --- a/homeassistant/components/automation/template.py +++ b/homeassistant/components/automation/template.py @@ -10,6 +10,9 @@ from homeassistant.helpers import condition from homeassistant.helpers.event import async_track_same_state, async_track_template from homeassistant.helpers import config_validation as cv, template + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) TRIGGER_SCHEMA = IF_ACTION_SCHEMA = vol.Schema( diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 958c1f007bc..3942d0efadb 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -8,6 +8,9 @@ from homeassistant.const import CONF_AT, CONF_PLATFORM from homeassistant.helpers import config_validation as cv from homeassistant.helpers.event import async_track_time_change + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) TRIGGER_SCHEMA = vol.Schema( diff --git a/homeassistant/components/automation/time_pattern.py b/homeassistant/components/automation/time_pattern.py index 15180e07094..f749a308bf7 100644 --- a/homeassistant/components/automation/time_pattern.py +++ b/homeassistant/components/automation/time_pattern.py @@ -8,6 +8,9 @@ from homeassistant.const import CONF_PLATFORM from homeassistant.helpers import config_validation as cv from homeassistant.helpers.event import async_track_time_change + +# mypy: allow-untyped-defs, no-check-untyped-defs + CONF_HOURS = "hours" CONF_MINUTES = "minutes" CONF_SECONDS = "seconds" diff --git a/homeassistant/components/automation/webhook.py b/homeassistant/components/automation/webhook.py index ceb764cea96..706afbe9042 100644 --- a/homeassistant/components/automation/webhook.py +++ b/homeassistant/components/automation/webhook.py @@ -11,6 +11,9 @@ import homeassistant.helpers.config_validation as cv from . import DOMAIN as AUTOMATION_DOMAIN + +# mypy: allow-untyped-defs + DEPENDENCIES = ("webhook",) _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/automation/zone.py b/homeassistant/components/automation/zone.py index 1f0f558f0de..35b11006024 100644 --- a/homeassistant/components/automation/zone.py +++ b/homeassistant/components/automation/zone.py @@ -12,6 +12,9 @@ from homeassistant.const import ( from homeassistant.helpers.event import async_track_state_change from homeassistant.helpers import condition, config_validation as cv, location + +# mypy: allow-untyped-defs, no-check-untyped-defs + EVENT_ENTER = "enter" EVENT_LEAVE = "leave" DEFAULT_EVENT = EVENT_ENTER diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 951f4a423e5..9af6a10c425 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -13,6 +13,9 @@ from homeassistant.helpers.config_validation import ( # noqa PLATFORM_SCHEMA_BASE, ) + +# mypy: allow-untyped-defs, no-check-untyped-defs + DOMAIN = "binary_sensor" SCAN_INTERVAL = timedelta(seconds=30) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index e538b6b802a..32817242642 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -17,6 +17,9 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.template import DATE_STR_FORMAT from homeassistant.util import dt + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "calendar" diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index efe7a37b310..1b2bfb5fdb1 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -7,6 +7,7 @@ from datetime import timedelta import logging import hashlib from random import SystemRandom +from typing import Deque import attr from aiohttp import web @@ -52,6 +53,9 @@ from homeassistant.setup import async_when_setup from .const import DOMAIN, DATA_CAMERA_PREFS from .prefs import CameraPreferences + +# mypy: allow-untyped-calls, allow-untyped-defs + _LOGGER = logging.getLogger(__name__) SERVICE_ENABLE_MOTION = "enable_motion_detection" @@ -311,7 +315,7 @@ class Camera(Entity): """Initialize a camera.""" self.is_streaming = False self.content_type = DEFAULT_CONTENT_TYPE - self.access_tokens = collections.deque([], 2) + self.access_tokens: Deque[str] = collections.deque([], 2) self.async_update_token() @property diff --git a/homeassistant/components/camera/prefs.py b/homeassistant/components/camera/prefs.py index 5e22b882d0a..d83e0b55c96 100644 --- a/homeassistant/components/camera/prefs.py +++ b/homeassistant/components/camera/prefs.py @@ -1,6 +1,9 @@ """Preference management for camera component.""" from .const import DOMAIN, PREF_PRELOAD_STREAM + +# mypy: allow-untyped-defs, no-check-untyped-defs + STORAGE_KEY = DOMAIN STORAGE_VERSION = 1 _UNDEF = object() diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 696524f5792..d491765bb00 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -32,6 +32,9 @@ from homeassistant.const import ( STATE_CLOSING, ) + +# mypy: allow-untyped-calls, allow-incomplete-defs, allow-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "cover" diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 235e8cf5fad..f5edfe5bb59 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -2,6 +2,7 @@ from datetime import timedelta import functools as ft import logging +from typing import Optional import voluptuous as vol @@ -74,7 +75,7 @@ FAN_SET_DIRECTION_SCHEMA = ENTITY_SERVICE_SCHEMA.extend( @bind_hass -def is_on(hass, entity_id: str = None) -> bool: +def is_on(hass, entity_id: Optional[str] = None) -> bool: """Return if the fans are on based on the statemachine.""" entity_id = entity_id or ENTITY_ID_ALL_FANS state = hass.states.get(entity_id) @@ -149,12 +150,12 @@ class FanEntity(ToggleEntity): return self.hass.async_add_job(self.set_direction, direction) # pylint: disable=arguments-differ - def turn_on(self, speed: str = None, **kwargs) -> None: + def turn_on(self, speed: Optional[str] = None, **kwargs) -> None: """Turn on the fan.""" raise NotImplementedError() # pylint: disable=arguments-differ - def async_turn_on(self, speed: str = None, **kwargs): + def async_turn_on(self, speed: Optional[str] = None, **kwargs): """Turn on the fan. This method must be run in the event loop and returns a coroutine. @@ -180,7 +181,7 @@ class FanEntity(ToggleEntity): return self.speed not in [SPEED_OFF, None] @property - def speed(self) -> str: + def speed(self) -> Optional[str]: """Return the current speed.""" return None @@ -190,7 +191,7 @@ class FanEntity(ToggleEntity): return [] @property - def current_direction(self) -> str: + def current_direction(self) -> Optional[str]: """Return the current direction of the fan.""" return None diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index b769d6b9aea..d8790b746be 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -22,6 +22,8 @@ from homeassistant.loader import bind_hass from .storage import async_setup_frontend_storage +# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs + # Fix mimetypes for borked Windows machines # https://github.com/home-assistant/home-assistant-polymer/issues/3336 mimetypes.add_type("text/css", ".css") @@ -45,7 +47,14 @@ MANIFEST_JSON = { "description": "Home automation platform that puts local control and privacy first.", "dir": "ltr", "display": "standalone", - "icons": [], + "icons": [ + { + "src": "/static/icons/favicon-{size}x{size}.png".format(size=size), + "sizes": "{size}x{size}".format(size=size), + "type": "image/png", + } + for size in (192, 384, 512, 1024) + ], "lang": "en-US", "name": "Home Assistant", "short_name": "Assistant", @@ -53,15 +62,6 @@ MANIFEST_JSON = { "theme_color": DEFAULT_THEME_COLOR, } -for size in (192, 384, 512, 1024): - MANIFEST_JSON["icons"].append( - { - "src": "/static/icons/favicon-{size}x{size}.png".format(size=size), - "sizes": "{size}x{size}".format(size=size), - "type": "image/png", - } - ) - DATA_PANELS = "frontend_panels" DATA_JS_VERSION = "frontend_js_version" DATA_EXTRA_HTML_URL = "frontend_extra_html_url" diff --git a/homeassistant/components/frontend/storage.py b/homeassistant/components/frontend/storage.py index 56f23da5253..75b7b356ef9 100644 --- a/homeassistant/components/frontend/storage.py +++ b/homeassistant/components/frontend/storage.py @@ -4,6 +4,9 @@ import voluptuous as vol from homeassistant.components import websocket_api + +# mypy: allow-untyped-calls, allow-untyped-defs + DATA_STORAGE = "frontend_storage" STORAGE_VERSION_USER_DATA = 1 STORAGE_KEY_USER_DATA = "frontend.user_data_{}" diff --git a/homeassistant/components/geo_location/__init__.py b/homeassistant/components/geo_location/__init__.py index 869f96901c1..3c270f2c521 100644 --- a/homeassistant/components/geo_location/__init__.py +++ b/homeassistant/components/geo_location/__init__.py @@ -11,6 +11,9 @@ from homeassistant.helpers.config_validation import ( # noqa from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_DISTANCE = "distance" diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index d402aceaa40..a2285da4e80 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -21,6 +21,9 @@ from homeassistant.const import ATTR_HIDDEN from homeassistant.components.recorder.util import session_scope, execute import homeassistant.helpers.config_validation as cv + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "history" diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 6d31c3fc700..5e474dafa07 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -27,6 +27,9 @@ from .real_ip import setup_real_ip from .static import CACHE_HEADERS, CachingStaticResource from .view import HomeAssistantView # noqa + +# mypy: allow-untyped-defs, no-check-untyped-defs + DOMAIN = "http" CONF_API_PASSWORD = "api_password" diff --git a/homeassistant/components/http/auth.py b/homeassistant/components/http/auth.py index c65cb6a2e94..4ff581aef02 100644 --- a/homeassistant/components/http/auth.py +++ b/homeassistant/components/http/auth.py @@ -14,6 +14,9 @@ from homeassistant.util import dt as dt_util from .const import KEY_AUTHENTICATED, KEY_HASS_USER, KEY_REAL_IP + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DATA_API_PASSWORD = "api_password" diff --git a/homeassistant/components/http/ban.py b/homeassistant/components/http/ban.py index db8d2ade959..71e7ff38924 100644 --- a/homeassistant/components/http/ban.py +++ b/homeassistant/components/http/ban.py @@ -3,6 +3,7 @@ from collections import defaultdict from datetime import datetime from ipaddress import ip_address import logging +from typing import List, Optional from aiohttp.web import middleware from aiohttp.web_exceptions import HTTPForbidden, HTTPUnauthorized @@ -16,6 +17,9 @@ from homeassistant.util.yaml import dump from .const import KEY_REAL_IP + +# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) KEY_BANNED_IPS = "ha_banned_ips" @@ -155,7 +159,7 @@ async def process_success_login(request): class IpBan: """Represents banned IP address.""" - def __init__(self, ip_ban: str, banned_at: datetime = None) -> None: + def __init__(self, ip_ban: str, banned_at: Optional[datetime] = None) -> None: """Initialize IP Ban object.""" self.ip_address = ip_address(ip_ban) self.banned_at = banned_at or datetime.utcnow() @@ -163,7 +167,7 @@ class IpBan: async def async_load_ip_bans_config(hass: HomeAssistant, path: str): """Load list of banned IPs from config file.""" - ip_list = [] + ip_list: List[IpBan] = [] try: list_ = await hass.async_add_executor_job(load_yaml_config_file, path) diff --git a/homeassistant/components/http/cors.py b/homeassistant/components/http/cors.py index 19fe88c5cde..39ff45fd4e4 100644 --- a/homeassistant/components/http/cors.py +++ b/homeassistant/components/http/cors.py @@ -5,6 +5,9 @@ from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION from homeassistant.const import HTTP_HEADER_HA_AUTH, HTTP_HEADER_X_REQUESTED_WITH from homeassistant.core import callback + +# mypy: allow-untyped-defs, no-check-untyped-defs + ALLOWED_CORS_HEADERS = [ ORIGIN, ACCEPT, diff --git a/homeassistant/components/http/data_validator.py b/homeassistant/components/http/data_validator.py index 8d6ac0b1ceb..634a96aa312 100644 --- a/homeassistant/components/http/data_validator.py +++ b/homeassistant/components/http/data_validator.py @@ -4,6 +4,9 @@ import logging import voluptuous as vol + +# mypy: allow-untyped-defs + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/http/real_ip.py b/homeassistant/components/http/real_ip.py index c38e5d0b592..f327c86a4c1 100644 --- a/homeassistant/components/http/real_ip.py +++ b/homeassistant/components/http/real_ip.py @@ -9,6 +9,9 @@ from homeassistant.core import callback from .const import KEY_REAL_IP +# mypy: allow-untyped-defs + + @callback def setup_real_ip(app, use_x_forwarded_for, trusted_proxies): """Create IP Ban middleware for the app.""" diff --git a/homeassistant/components/http/static.py b/homeassistant/components/http/static.py index f78ce81d884..76844407f7d 100644 --- a/homeassistant/components/http/static.py +++ b/homeassistant/components/http/static.py @@ -6,6 +6,9 @@ from aiohttp.web import FileResponse from aiohttp.web_exceptions import HTTPNotFound, HTTPForbidden from aiohttp.web_urldispatcher import StaticResource + +# mypy: allow-untyped-defs + CACHE_TIME = 31 * 86400 # = 1 month CACHE_HEADERS = {hdrs.CACHE_CONTROL: "public, max-age={}".format(CACHE_TIME)} @@ -39,7 +42,8 @@ class CachingStaticResource(StaticResource): if filepath.is_dir(): return await super()._handle(request) if filepath.is_file(): - return FileResponse( + # type ignore: https://github.com/aio-libs/aiohttp/pull/3976 + return FileResponse( # type: ignore filepath, chunk_size=self._chunk_size, headers=CACHE_HEADERS ) raise HTTPNotFound diff --git a/homeassistant/components/http/view.py b/homeassistant/components/http/view.py index 35e74b7c2c0..66864eba55e 100644 --- a/homeassistant/components/http/view.py +++ b/homeassistant/components/http/view.py @@ -2,6 +2,7 @@ import asyncio import json import logging +from typing import List, Optional from aiohttp import web from aiohttp.web_exceptions import ( @@ -22,11 +23,14 @@ from .const import KEY_AUTHENTICATED, KEY_HASS, KEY_REAL_IP _LOGGER = logging.getLogger(__name__) +# mypy: allow-untyped-defs, no-check-untyped-defs + + class HomeAssistantView: """Base view for all views.""" - url = None - extra_urls = [] + url: Optional[str] = None + extra_urls: List[str] = [] # Views inheriting from this class can override this requires_auth = True cors_allowed = False diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 1f106e12dcd..b1c167a4175 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -14,6 +14,9 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent from homeassistant.util.async_ import run_callback_threadsafe + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "image_processing" diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index 006e0fe9a41..d24b70c4be0 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -16,6 +16,9 @@ from homeassistant.core import callback from homeassistant.helpers.event import async_track_state_change from homeassistant.helpers.restore_state import RestoreEntity + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_SOURCE_ID = "source" diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 7ac46d1237d..c70a209a35a 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -4,6 +4,7 @@ import csv from datetime import timedelta import logging import os +from typing import Dict, Optional, Tuple import voluptuous as vol @@ -29,6 +30,9 @@ from homeassistant.helpers import intent from homeassistant.loader import bind_hass import homeassistant.util.color as color_util + +# mypy: allow-untyped-defs, no-check-untyped-defs + DOMAIN = "light" SCAN_INTERVAL = timedelta(seconds=30) @@ -344,7 +348,7 @@ async def async_unload_entry(hass, entry): class Profiles: """Representation of available color profiles.""" - _all = None + _all: Optional[Dict[str, Tuple[float, float, int]]] = None @classmethod async def load_profiles(cls, hass): diff --git a/homeassistant/components/light/device_automation.py b/homeassistant/components/light/device_automation.py index 26ddef16aae..ed75b5f906f 100644 --- a/homeassistant/components/light/device_automation.py +++ b/homeassistant/components/light/device_automation.py @@ -14,6 +14,9 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_registry import async_entries_for_device from . import DOMAIN + +# mypy: allow-untyped-defs, no-check-untyped-defs + CONF_TURN_OFF = "turn_off" CONF_TURN_ON = "turn_on" diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index a2205ccbf46..503bd3a8c78 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -25,6 +25,9 @@ from homeassistant.const import ( ) from homeassistant.components import group + +# mypy: allow-untyped-defs, no-check-untyped-defs + ATTR_CHANGED_BY = "changed_by" DOMAIN = "lock" diff --git a/homeassistant/components/mailbox/__init__.py b/homeassistant/components/mailbox/__init__.py index 08853a4edce..1252036e1b2 100644 --- a/homeassistant/components/mailbox/__init__.py +++ b/homeassistant/components/mailbox/__init__.py @@ -16,6 +16,9 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent from homeassistant.setup import async_prepare_setup_platform + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "mailbox" diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 8334577ac30..791dacb7024 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -97,6 +97,9 @@ from .const import ( SUPPORT_VOLUME_STEP, ) + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) _RND = SystemRandom() diff --git a/homeassistant/components/media_player/reproduce_state.py b/homeassistant/components/media_player/reproduce_state.py index a926274e641..4eba4657d95 100644 --- a/homeassistant/components/media_player/reproduce_state.py +++ b/homeassistant/components/media_player/reproduce_state.py @@ -36,6 +36,9 @@ from .const import ( ) +# mypy: allow-incomplete-defs, allow-untyped-defs + + async def _async_reproduce_states( hass: HomeAssistantType, state: State, context: Optional[Context] = None ) -> None: diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index af2fbac9639..75552d1d14b 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -416,7 +416,7 @@ async def async_subscribe( topic: str, msg_callback: MessageCallbackType, qos: int = DEFAULT_QOS, - encoding: str = "utf-8", + encoding: Optional[str] = "utf-8", ): """Subscribe to an MQTT topic. @@ -829,7 +829,11 @@ class MQTT: return self.hass.async_add_job(stop) async def async_subscribe( - self, topic: str, msg_callback: MessageCallbackType, qos: int, encoding: str + self, + topic: str, + msg_callback: MessageCallbackType, + qos: int, + encoding: Optional[str] = None, ) -> Callable[[], None]: """Set up a subscription to a topic with the provided qos. diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index 8483b703a70..773c08808c3 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -2,6 +2,7 @@ import asyncio import logging from functools import partial +from typing import Optional import voluptuous as vol @@ -10,8 +11,12 @@ from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv from homeassistant.const import CONF_NAME, CONF_PLATFORM from homeassistant.helpers import config_per_platform, discovery +from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import slugify + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) # Platform specific data @@ -164,7 +169,7 @@ async def async_setup(hass, config): class BaseNotificationService: """An abstract class for notification services.""" - hass = None + hass: Optional[HomeAssistantType] = None def send_message(self, message, **kwargs): """Send a message. diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index d563314225a..e9b85f79084 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -10,6 +10,9 @@ from homeassistant.helpers.event import track_state_change from homeassistant.util.distance import convert from homeassistant.util.location import distance + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_DIR_OF_TRAVEL = "dir_of_travel" diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index e495874f339..450b1c123c3 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -22,6 +22,9 @@ from homeassistant.helpers.config_validation import ( # noqa PLATFORM_SCHEMA_BASE, ) + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_ACTIVITY = "activity" diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index 5ddb1116d8f..1f71a24c304 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -12,6 +12,9 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.state import HASS_DOMAIN + +# mypy: allow-untyped-defs, no-check-untyped-defs + DOMAIN = "scene" STATE = "scening" STATES = "states" diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index cc460cdd4a9..9ca11b5266a 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -21,6 +21,9 @@ from homeassistant.helpers.config_validation import ( # noqa ) from homeassistant.helpers.entity_component import EntityComponent + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "sensor" diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index a52380882db..348c2a8616b 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -20,6 +20,9 @@ from homeassistant.const import ( ) from homeassistant.components import group + +# mypy: allow-untyped-defs, no-check-untyped-defs + DOMAIN = "switch" SCAN_INTERVAL = timedelta(seconds=30) diff --git a/homeassistant/components/switch/light.py b/homeassistant/components/switch/light.py index 38c66854a0b..0b1094c0dd9 100644 --- a/homeassistant/components/switch/light.py +++ b/homeassistant/components/switch/light.py @@ -1,5 +1,6 @@ """Light support for switch entities.""" import logging +from typing import cast import voluptuous as vol @@ -18,6 +19,9 @@ from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.components.light import PLATFORM_SCHEMA, Light + +# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs + _LOGGER = logging.getLogger(__name__) DEFAULT_NAME = "Light Switch" @@ -35,7 +39,7 @@ async def async_setup_platform( ) -> None: """Initialize Light Switch platform.""" async_add_entities( - [LightSwitch(config.get(CONF_NAME), config[CONF_ENTITY_ID])], True + [LightSwitch(cast(str, config.get(CONF_NAME)), config[CONF_ENTITY_ID])], True ) diff --git a/homeassistant/components/systemmonitor/sensor.py b/homeassistant/components/systemmonitor/sensor.py index 207440a6646..446a36ec350 100644 --- a/homeassistant/components/systemmonitor/sensor.py +++ b/homeassistant/components/systemmonitor/sensor.py @@ -12,6 +12,9 @@ from homeassistant.helpers.entity import Entity import homeassistant.helpers.config_validation as cv import homeassistant.util.dt as dt_util + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) CONF_ARG = "arg" diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 862c5e9cf9a..77d24fd7aab 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -8,6 +8,7 @@ import logging import mimetypes import os import re +from typing import Optional from aiohttp import web import voluptuous as vol @@ -25,8 +26,12 @@ from homeassistant.core import callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_per_platform import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import HomeAssistantType from homeassistant.setup import async_prepare_setup_platform + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_CACHE = "cache" @@ -461,8 +466,8 @@ class SpeechManager: class Provider: """Represent a single TTS provider.""" - hass = None - name = None + hass: Optional[HomeAssistantType] = None + name: Optional[str] = None @property def default_language(self): diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index ea2f29ed225..598c068aad5 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -27,6 +27,9 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity import ToggleEntity, Entity from homeassistant.helpers.icon import icon_for_battery_level + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) DOMAIN = "vacuum" diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index d4402eec3b5..c41381fe5fa 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -27,6 +27,9 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) + +# mypy: allow-untyped-defs, no-check-untyped-defs + DEFAULT_MIN_TEMP = 110 DEFAULT_MAX_TEMP = 140 diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 0bd22304119..8f276279ee5 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -11,6 +11,9 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.temperature import display_temp as show_temp + +# mypy: allow-untyped-defs, no-check-untyped-defs + _LOGGER = logging.getLogger(__name__) ATTR_CONDITION_CLASS = "condition_class" diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 789093cc49c..7ce27d404cf 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -175,11 +175,11 @@ class FlowHandler: """Handle the configuration flow of a component.""" # Set by flow manager - flow_id = None - hass = None + flow_id: Optional[str] = None + hass: Optional[HomeAssistant] = None handler = None - cur_step = None - context = None # type: Optional[Dict] + cur_step: Optional[Dict[str, str]] = None + context: Optional[Dict] = None # Set by _async_create_flow callback init_step = "init" diff --git a/homeassistant/scripts/check_config.py b/homeassistant/scripts/check_config.py index e8493822771..28734b30fcc 100644 --- a/homeassistant/scripts/check_config.py +++ b/homeassistant/scripts/check_config.py @@ -28,7 +28,7 @@ MOCKS = { } # type: Dict[str, Tuple[str, Callable]] SILENCE = ("homeassistant.scripts.check_config.yaml_loader.clear_secret_cache",) -PATCHES = {} +PATCHES: Dict[str, Any] = {} C_HEAD = "bold" ERROR_STR = "General Errors" diff --git a/mypyrc b/mypyrc index ece4678abe6..f3866f40e57 100644 --- a/mypyrc +++ b/mypyrc @@ -1,5 +1,32 @@ homeassistant/*.py homeassistant/auth/ +homeassistant/components/*.py +homeassistant/components/automation/ +homeassistant/components/binary_sensor/ +homeassistant/components/calendar/ +homeassistant/components/camera/ +homeassistant/components/cover/ +homeassistant/components/frontend/ +homeassistant/components/geo_location/ +homeassistant/components/history/ +homeassistant/components/http/ +homeassistant/components/image_processing/ +homeassistant/components/integration/ +homeassistant/components/light/ +homeassistant/components/lock/ +homeassistant/components/mailbox/ +homeassistant/components/media_player/ +homeassistant/components/notify/ +homeassistant/components/proximity/ +homeassistant/components/remote/ +homeassistant/components/scene/ +homeassistant/components/sensor/ +homeassistant/components/switch/ +homeassistant/components/systemmonitor/ +homeassistant/components/tts/ +homeassistant/components/vacuum/ +homeassistant/components/water_heater/ +homeassistant/components/weather/ homeassistant/helpers/ homeassistant/scripts/ homeassistant/util/