diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 1f0ac9eb103..c62fe9e7d6b 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -12,8 +12,6 @@ from typing import Any, Optional, Dict import voluptuous as vol -from homeassistant.helpers.typing import HomeAssistantType - import homeassistant.components as core_components from homeassistant.components import group, persistent_notification import homeassistant.config as conf_util @@ -218,7 +216,7 @@ def prepare_setup_platform(hass: core.HomeAssistant, config, domain: str, # pylint: disable=too-many-branches, too-many-statements, too-many-arguments def from_config_dict(config: Dict[str, Any], - hass: Optional[HomeAssistantType]=None, + hass: Optional[core.HomeAssistant]=None, config_dir: Optional[str]=None, enable_log: bool=True, verbose: bool=False, diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index 84073572ec6..5e4415d81a0 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -16,13 +16,13 @@ from typing import Any, Union, Optional, List import voluptuous as vol -from homeassistant.helpers.typing import (ConfigType, QueryType, - HomeAssistantType) -import homeassistant.util.dt as dt_util +from homeassistant.core import HomeAssistant from homeassistant.const import (EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, MATCH_ALL) from homeassistant.helpers.event import track_point_in_utc_time +from homeassistant.helpers.typing import ConfigType, QueryType +import homeassistant.util.dt as dt_util DOMAIN = "recorder" @@ -95,7 +95,7 @@ def run_information(point_in_time: Optional[datetime]=None): (recorder_runs.end > point_in_time)).first() -def setup(hass: HomeAssistantType, config: ConfigType) -> bool: +def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Setup the recorder.""" # pylint: disable=global-statement global _INSTANCE @@ -155,7 +155,7 @@ class Recorder(threading.Thread): """A threaded recorder class.""" # pylint: disable=too-many-instance-attributes - def __init__(self, hass: HomeAssistantType, purge_days: int, uri: str) \ + def __init__(self, hass: HomeAssistant, purge_days: int, uri: str) \ -> None: """Initialize the recorder.""" threading.Thread.__init__(self) diff --git a/homeassistant/config.py b/homeassistant/config.py index 1d280b40b1a..65ed44bef83 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -18,9 +18,9 @@ from homeassistant.core import valid_entity_id from homeassistant.exceptions import HomeAssistantError from homeassistant.util.yaml import load_yaml import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.unit_system import (IMPERIAL_SYSTEM, METRIC_SYSTEM) from homeassistant.helpers.entity import set_customize from homeassistant.util import dt as date_util, location as loc_util +from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/core.py b/homeassistant/core.py index bd33cae792a..81660d65a9b 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -29,11 +29,10 @@ from homeassistant.const import ( SERVICE_HOMEASSISTANT_RESTART, SERVICE_HOMEASSISTANT_STOP, __version__) from homeassistant.exceptions import ( HomeAssistantError, InvalidEntityFormatError) -from homeassistant.helpers.typing import UnitSystemType # NOQA -from homeassistant.helpers.unit_system import METRIC_SYSTEM import homeassistant.util as util import homeassistant.util.dt as dt_util import homeassistant.util.location as location +from homeassistant.util.unit_system import UnitSystem, METRIC_SYSTEM # NOQA DOMAIN = "homeassistant" @@ -731,7 +730,7 @@ class Config(object): self.elevation = None # type: Optional[int] self.location_name = None # type: Optional[str] self.time_zone = None # type: Optional[str] - self.units = METRIC_SYSTEM # type: UnitSystemType + self.units = METRIC_SYSTEM # type: UnitSystem # If True, pip install is skipped for requirements on startup self.skip_pip = False # type: bool diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 791405f6da1..f2c3585ec8b 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -3,8 +3,9 @@ from datetime import timedelta import logging import sys -from homeassistant.helpers.typing import ConfigType, HomeAssistantType +from homeassistant.helpers.typing import ConfigType +from homeassistant.core import HomeAssistant from homeassistant.components import ( zone as zone_cmp, sun as sun_cmp) from homeassistant.const import ( @@ -42,7 +43,7 @@ def and_from_config(config: ConfigType, config_validation: bool=True): config = cv.AND_CONDITION_SCHEMA(config) checks = [from_config(entry) for entry in config['conditions']] - def if_and_condition(hass: HomeAssistantType, + def if_and_condition(hass: HomeAssistant, variables=None) -> bool: """Test and condition.""" for check in checks: @@ -64,7 +65,7 @@ def or_from_config(config: ConfigType, config_validation: bool=True): config = cv.OR_CONDITION_SCHEMA(config) checks = [from_config(entry) for entry in config['conditions']] - def if_or_condition(hass: HomeAssistantType, + def if_or_condition(hass: HomeAssistant, variables=None) -> bool: """Test and condition.""" for check in checks: @@ -80,7 +81,7 @@ def or_from_config(config: ConfigType, config_validation: bool=True): # pylint: disable=too-many-arguments -def numeric_state(hass: HomeAssistantType, entity, below=None, above=None, +def numeric_state(hass: HomeAssistant, entity, below=None, above=None, value_template=None, variables=None): """Test a numeric state condition.""" if isinstance(entity, str): diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 2ec64b3ea09..61cda43d431 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -8,11 +8,10 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, DEVICE_DEFAULT_NAME, STATE_OFF, STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_ENTITY_PICTURE) +from homeassistant.core import HomeAssistant from homeassistant.exceptions import NoEntitySpecifiedError from homeassistant.util import ensure_unique_string, slugify -from homeassistant.helpers.typing import HomeAssistantType - # Entity attributes that we will overwrite _OVERWRITE = {} # type: Dict[str, Any] @@ -21,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) def generate_entity_id(entity_id_format: str, name: Optional[str], current_ids: Optional[List[str]]=None, - hass: Optional[HomeAssistantType]=None) -> str: + hass: Optional[HomeAssistant]=None) -> str: """Generate a unique entity ID based on given entity IDs or used IDs.""" name = (name or DEVICE_DEFAULT_NAME).lower() if current_ids is None: @@ -137,7 +136,7 @@ class Entity(object): # are used to perform a very specific function. Overwriting these may # produce undesirable effects in the entity's operation. - hass = None # type: Optional[HomeAssistantType] + hass = None # type: Optional[HomeAssistant] def update_ha_state(self, force_refresh=False): """Update Home Assistant with current state of entity. diff --git a/homeassistant/helpers/event_decorators.py b/homeassistant/helpers/event_decorators.py index 29430f7055c..aed90599a75 100644 --- a/homeassistant/helpers/event_decorators.py +++ b/homeassistant/helpers/event_decorators.py @@ -3,11 +3,11 @@ import functools # pylint: disable=unused-import from typing import Optional # NOQA -from homeassistant.helpers.typing import HomeAssistantType # NOQA +from homeassistant.core import HomeAssistant # NOQA from homeassistant.helpers import event -HASS = None # type: Optional[HomeAssistantType] +HASS = None # type: Optional[HomeAssistant] def track_state_change(entity_ids, from_state=None, to_state=None): diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index 132ffb30a82..008fdb9374d 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -2,18 +2,17 @@ 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.core import HomeAssistant from homeassistant.const import EVENT_TIME_CHANGED, CONF_CONDITION +from homeassistant.helpers import ( + service, condition, template, config_validation as cv) from homeassistant.helpers.event import track_point_in_utc_time -from homeassistant.helpers import service, condition, template -import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import ConfigType +import homeassistant.util.dt as date_util _LOGGER = logging.getLogger(__name__) @@ -26,7 +25,7 @@ CONF_EVENT_DATA = "event_data" CONF_DELAY = "delay" -def call_from_config(hass: HomeAssistantType, config: ConfigType, +def call_from_config(hass: HomeAssistant, config: ConfigType, variables: Optional[Sequence]=None) -> None: """Call a script based on a config entry.""" Script(hass, config).run(variables) @@ -36,7 +35,7 @@ class Script(): """Representation of a script.""" # pylint: disable=too-many-instance-attributes - def __init__(self, hass: HomeAssistantType, sequence, name: str=None, + def __init__(self, hass: HomeAssistant, sequence, name: str=None, change_listener=None) -> None: """Initialize the script.""" self.hass = hass diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index ffad2997a43..b594889fd77 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -1,21 +1,19 @@ """Service calling related helpers.""" import functools import logging - # pylint: disable=unused-import from typing import Optional # NOQA import voluptuous as vol -from homeassistant.helpers.typing import HomeAssistantType # NOQA - from homeassistant.const import ATTR_ENTITY_ID +from homeassistant.core import HomeAssistant # NOQA from homeassistant.exceptions import TemplateError from homeassistant.helpers import template from homeassistant.loader import get_component import homeassistant.helpers.config_validation as cv -HASS = None # type: Optional[HomeAssistantType] +HASS = None # type: Optional[HomeAssistant] CONF_SERVICE = 'service' CONF_SERVICE_TEMPLATE = 'service_template' diff --git a/homeassistant/helpers/typing.py b/homeassistant/helpers/typing.py index 473e28995b2..6eb53f14493 100644 --- a/homeassistant/helpers/typing.py +++ b/homeassistant/helpers/typing.py @@ -8,22 +8,9 @@ try: except ImportError: NewType = None -# HACK: mypy/pytype will import, other interpreters will not; this is to avoid -# circular dependencies where the type is needed. -# All homeassistant types should be imported this way. -# Documentation -# http://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles -# pylint: disable=using-constant-test,unused-import -if False: - from homeassistant.core import HomeAssistant # NOQA - from homeassistant.helpers.unit_system import UnitSystem # NOQA -# ENDHACK - # pylint: disable=invalid-name if NewType: ConfigType = NewType('ConfigType', Dict[str, Any]) - HomeAssistantType = NewType('HomeAssistantType', 'HomeAssistant') - UnitSystemType = NewType('UnitSystemType', 'UnitSystem') # Custom type for recorder Queries QueryType = NewType('QueryType', Any) @@ -32,8 +19,6 @@ if NewType: # pylint: disable=invalid-name else: ConfigType = Dict[str, Any] # type: ignore - HomeAssistantType = 'HomeAssistant' # type: ignore - UnitSystemType = 'UnitSystemType' # type: ignore # Custom type for recorder Queries QueryType = Any # type: ignore diff --git a/homeassistant/helpers/unit_system.py b/homeassistant/util/unit_system.py similarity index 100% rename from homeassistant/helpers/unit_system.py rename to homeassistant/util/unit_system.py diff --git a/tests/common.py b/tests/common.py index e3ca00c8cbb..b0e3ef17653 100644 --- a/tests/common.py +++ b/tests/common.py @@ -6,7 +6,7 @@ from unittest import mock from homeassistant import core as ha, loader from homeassistant.bootstrap import _setup_component from homeassistant.helpers.entity import ToggleEntity -from homeassistant.helpers.unit_system import METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM import homeassistant.util.dt as date_util from homeassistant.const import ( STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED, diff --git a/tests/components/hvac/test_demo.py b/tests/components/hvac/test_demo.py index fb1abd90c65..536a1ac36f7 100644 --- a/tests/components/hvac/test_demo.py +++ b/tests/components/hvac/test_demo.py @@ -1,7 +1,7 @@ """The tests for the demo hvac.""" import unittest -from homeassistant.helpers.unit_system import ( +from homeassistant.util.unit_system import ( METRIC_SYSTEM, ) from homeassistant.components import hvac diff --git a/tests/components/thermostat/test_demo.py b/tests/components/thermostat/test_demo.py index ba85c393f63..673626136ab 100644 --- a/tests/components/thermostat/test_demo.py +++ b/tests/components/thermostat/test_demo.py @@ -1,7 +1,7 @@ """The tests for the demo thermostat.""" import unittest -from homeassistant.helpers.unit_system import ( +from homeassistant.util.unit_system import ( METRIC_SYSTEM, ) from homeassistant.components import thermostat diff --git a/tests/components/thermostat/test_heat_control.py b/tests/components/thermostat/test_heat_control.py index 1ccc3fb2903..a01c1595393 100644 --- a/tests/components/thermostat/test_heat_control.py +++ b/tests/components/thermostat/test_heat_control.py @@ -13,7 +13,7 @@ from homeassistant.const import ( STATE_OFF, TEMP_CELSIUS, ) -from homeassistant.helpers.unit_system import METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM from homeassistant.components import thermostat from tests.common import get_test_home_assistant diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 4d62d328825..266138d1fd5 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -6,7 +6,7 @@ from unittest.mock import patch from homeassistant.components import group from homeassistant.exceptions import TemplateError from homeassistant.helpers import template -from homeassistant.helpers.unit_system import UnitSystem +from homeassistant.util.unit_system import UnitSystem from homeassistant.const import ( LENGTH_METERS, TEMP_CELSIUS, diff --git a/tests/test_core.py b/tests/test_core.py index ea9f96ab808..78a676708df 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -15,7 +15,7 @@ import homeassistant.core as ha from homeassistant.exceptions import ( HomeAssistantError, InvalidEntityFormatError) import homeassistant.util.dt as dt_util -from homeassistant.helpers.unit_system import (METRIC_SYSTEM) +from homeassistant.util.unit_system import (METRIC_SYSTEM) from homeassistant.const import ( __version__, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM) diff --git a/tests/helpers/test_unit_system.py b/tests/util/test_unit_system.py similarity index 98% rename from tests/helpers/test_unit_system.py rename to tests/util/test_unit_system.py index a31b3bfc53a..c99c2cf87bf 100644 --- a/tests/helpers/test_unit_system.py +++ b/tests/util/test_unit_system.py @@ -1,7 +1,7 @@ """Test the unit system helper.""" import unittest -from homeassistant.helpers.unit_system import ( +from homeassistant.util.unit_system import ( UnitSystem, METRIC_SYSTEM, IMPERIAL_SYSTEM,