Type hint additions (#26765)

This commit is contained in:
Ville Skyttä authored and Paulus Schoutsen committed 2019-09-20 08:23:34 -07:00
1 parent 6a3132344c
commit 54242cd65c
10 files changed
+60 -52

No files matched your search

@@ -3,6 +3,7 @@ import asyncio
from functools import partial
import importlib
import logging
from typing import Any
import voluptuous as vol
@@ -34,7 +35,7 @@ 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: allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs, no-warn-return-any
DOMAIN = "automation"
@@ -281,11 +282,11 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
if enable_automation:
await self.async_enable()
async def async_turn_on(self, **kwargs) -> None:
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on and update the state."""
await self.async_enable()
async def async_turn_off(self, **kwargs) -> None:
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
await self.async_disable()
+8 -7
View File
@@ -2,6 +2,7 @@
from datetime import timedelta
import functools as ft
import logging
from typing import Any
import voluptuous as vol
@@ -33,7 +34,7 @@ from homeassistant.const import (
)
# mypy: allow-untyped-calls, allow-incomplete-defs, allow-untyped-defs
# mypy: allow-untyped-calls, allow-untyped-defs
_LOGGER = logging.getLogger(__name__)
@@ -263,7 +264,7 @@ class CoverDevice(Entity):
"""Return if the cover is closed or not."""
raise NotImplementedError()
def open_cover(self, **kwargs):
def open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
raise NotImplementedError()
@@ -274,7 +275,7 @@ class CoverDevice(Entity):
"""
return self.hass.async_add_job(ft.partial(self.open_cover, **kwargs))
def close_cover(self, **kwargs):
def close_cover(self, **kwargs: Any) -> None:
"""Close cover."""
raise NotImplementedError()
@@ -285,7 +286,7 @@ class CoverDevice(Entity):
"""
return self.hass.async_add_job(ft.partial(self.close_cover, **kwargs))
def toggle(self, **kwargs) -> None:
def toggle(self, **kwargs: Any) -> None:
"""Toggle the entity."""
if self.is_closed:
self.open_cover(**kwargs)
@@ -323,7 +324,7 @@ class CoverDevice(Entity):
"""
return self.hass.async_add_job(ft.partial(self.stop_cover, **kwargs))
def open_cover_tilt(self, **kwargs):
def open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the cover tilt."""
pass
@@ -334,7 +335,7 @@ class CoverDevice(Entity):
"""
return self.hass.async_add_job(ft.partial(self.open_cover_tilt, **kwargs))
def close_cover_tilt(self, **kwargs):
def close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the cover tilt."""
pass
@@ -369,7 +370,7 @@ class CoverDevice(Entity):
"""
return self.hass.async_add_job(ft.partial(self.stop_cover_tilt, **kwargs))
def toggle_tilt(self, **kwargs) -> None:
def toggle_tilt(self, **kwargs: Any) -> None:
"""Toggle the entity."""
if self.current_cover_tilt_position == 0:
self.open_cover_tilt(**kwargs)
@@ -4,6 +4,7 @@ import logging
import mimetypes
import os
import pathlib
from typing import Optional, Set, Tuple
from aiohttp import web, web_urldispatcher, hdrs
import voluptuous as vol
@@ -22,7 +23,7 @@ from homeassistant.loader import bind_hass
from .storage import async_setup_frontend_storage
# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs
# mypy: allow-untyped-defs, no-check-untyped-defs
# Fix mimetypes for borked Windows machines
# https://github.com/home-assistant/home-assistant-polymer/issues/3336
@@ -400,7 +401,9 @@ class IndexView(web_urldispatcher.AbstractResource):
"""Construct url for resource with additional params."""
return URL("/")
async def resolve(self, request: web.Request):
async def resolve(
self, request: web.Request
) -> Tuple[Optional[web_urldispatcher.UrlMappingMatchInfo], Set[str]]:
"""Resolve resource.
Return (UrlMappingMatchInfo, allowed_methods) pair.
@@ -447,7 +450,7 @@ class IndexView(web_urldispatcher.AbstractResource):
return tpl
async def get(self, request: web.Request):
async def get(self, request: web.Request) -> web.Response:
"""Serve the index page for panel pages."""
hass = request.app["hass"]
+3 -3
View File
@@ -18,7 +18,7 @@ from homeassistant.util.yaml import dump
from .const import KEY_REAL_IP
# mypy: allow-incomplete-defs, allow-untyped-defs, no-check-untyped-defs
# mypy: allow-untyped-defs, no-check-untyped-defs
_LOGGER = logging.getLogger(__name__)
@@ -165,7 +165,7 @@ class IpBan:
self.banned_at = banned_at or datetime.utcnow()
async def async_load_ip_bans_config(hass: HomeAssistant, path: str):
async def async_load_ip_bans_config(hass: HomeAssistant, path: str) -> List[IpBan]:
"""Load list of banned IPs from config file."""
ip_list: List[IpBan] = []
@@ -188,7 +188,7 @@ async def async_load_ip_bans_config(hass: HomeAssistant, path: str):
return ip_list
def update_ip_bans_config(path: str, ip_ban: IpBan):
def update_ip_bans_config(path: str, ip_ban: IpBan) -> None:
"""Update config file with new banned IP address."""
with open(path, "a") as out:
ip_ = {
@@ -36,7 +36,7 @@ from .const import (
)
# mypy: allow-incomplete-defs, allow-untyped-defs
# mypy: allow-untyped-defs
async def _async_reproduce_states(
@@ -44,7 +44,7 @@ async def _async_reproduce_states(
) -> None:
"""Reproduce component states."""
async def call_service(service: str, keys: Iterable):
async def call_service(service: str, keys: Iterable) -> None:
"""Call service with set of attributes given."""
data = {}
data["entity_id"] = state.entity_id
+8 -4
View File
@@ -1,6 +1,6 @@
"""Light support for switch entities."""
import logging
from typing import cast
from typing import cast, Callable, Dict, Optional, Sequence
import voluptuous as vol
@@ -14,13 +14,14 @@ from homeassistant.const import (
)
from homeassistant.core import State, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import async_track_state_change
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
# mypy: allow-untyped-calls, allow-untyped-defs
_LOGGER = logging.getLogger(__name__)
@@ -35,7 +36,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
hass: HomeAssistantType,
config: ConfigType,
async_add_entities: Callable[[Sequence[Entity], bool], None],
discovery_info: Optional[Dict] = None,
) -> None:
"""Initialize Light Switch platform."""
async_add_entities(
@@ -105,7 +109,7 @@ class LightSwitch(Light):
@callback
def async_state_changed_listener(
entity_id: str, old_state: State, new_state: State
):
) -> None:
"""Handle child updates."""
self.async_schedule_update_ha_state(True)