Improvement typing (#2735)

* Fix: Circular dependencies of internal files

* Change: dt.date for Date and dt.datetime for DateTime

* Use NewType if available

* FIX: Wrong version test

* Remove: Date and DateTime types due to error

* Change to HomeAssistantType

* General Improvement of Typing

* Improve typing config_validation

* Improve typing script

* General Typing Improvements

* Improve NewType check

* Improve typing db_migrator

* Improve util/__init__ typing

* Improve helpers/location typing

* Regroup imports and remove pylint: disable=ungrouped-imports

* General typing improvements
This commit is contained in:
Fabian Heredia Montiel 2016-08-07 18:26:35 -05:00 committed by Paulus Schoutsen
parent a3ca3e878b
commit 0377338a81
16 changed files with 139 additions and 66 deletions

View file

@ -3,8 +3,12 @@ import logging
import threading
from itertools import islice
from typing import Optional, Sequence
import voluptuous as vol
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
import homeassistant.util.dt as date_util
from homeassistant.const import EVENT_TIME_CHANGED, CONF_CONDITION
from homeassistant.helpers.event import track_point_in_utc_time
@ -22,7 +26,8 @@ CONF_EVENT_DATA = "event_data"
CONF_DELAY = "delay"
def call_from_config(hass, config, variables=None):
def call_from_config(hass: HomeAssistantType, config: ConfigType,
variables: Optional[Sequence]=None) -> None:
"""Call a script based on a config entry."""
Script(hass, config).run(variables)
@ -31,7 +36,8 @@ class Script():
"""Representation of a script."""
# pylint: disable=too-many-instance-attributes
def __init__(self, hass, sequence, name=None, change_listener=None):
def __init__(self, hass: HomeAssistantType, sequence, name: str=None,
change_listener=None) -> None:
"""Initialize the script."""
self.hass = hass
self.sequence = cv.SCRIPT_SCHEMA(sequence)
@ -45,11 +51,11 @@ class Script():
self._delay_listener = None
@property
def is_running(self):
def is_running(self) -> bool:
"""Return true if script is on."""
return self._cur != -1
def run(self, variables=None):
def run(self, variables: Optional[Sequence]=None) -> None:
"""Run script."""
with self._lock:
if self._cur == -1:
@ -101,7 +107,7 @@ class Script():
if self._change_listener:
self._change_listener()
def stop(self):
def stop(self) -> None:
"""Stop running script."""
with self._lock:
if self._cur == -1: