mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Move unit system to util (#2763)
This commit is contained in:
parent
640a8b5a7f
commit
0b7b0e54ba
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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__)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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.
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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,
|
Loading…
x
Reference in New Issue
Block a user