mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 19:09:32 +00:00
Migrate legacy typehints in core to PEP-526 (#26403)
* Migrate legacy typehints in core to PEP-526 * Fix one type
This commit is contained in:
committed by
Paulus Schoutsen
parent
2dc90be94f
commit
2f0eb07624
@@ -17,7 +17,7 @@ from time import monotonic
|
||||
import uuid
|
||||
|
||||
from types import MappingProxyType
|
||||
from typing import ( # noqa: F401 pylint: disable=unused-import
|
||||
from typing import (
|
||||
Optional,
|
||||
Any,
|
||||
Callable,
|
||||
@@ -28,7 +28,6 @@ from typing import ( # noqa: F401 pylint: disable=unused-import
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
Awaitable,
|
||||
Iterator,
|
||||
)
|
||||
|
||||
from async_timeout import timeout
|
||||
@@ -170,10 +169,10 @@ class HomeAssistant:
|
||||
"""Initialize new Home Assistant object."""
|
||||
self.loop: asyncio.events.AbstractEventLoop = (loop or asyncio.get_event_loop())
|
||||
|
||||
executor_opts = {
|
||||
executor_opts: Dict[str, Any] = {
|
||||
"max_workers": None,
|
||||
"thread_name_prefix": "SyncWorker",
|
||||
} # type: Dict[str, Any]
|
||||
}
|
||||
|
||||
self.executor = ThreadPoolExecutor(**executor_opts)
|
||||
self.loop.set_default_executor(self.executor)
|
||||
@@ -733,7 +732,7 @@ class State:
|
||||
)
|
||||
|
||||
self.entity_id = entity_id.lower()
|
||||
self.state = state # type: str
|
||||
self.state: str = state
|
||||
self.attributes = MappingProxyType(attributes or {})
|
||||
self.last_updated = last_updated or dt_util.utcnow()
|
||||
self.last_changed = last_changed or self.last_updated
|
||||
@@ -836,7 +835,7 @@ class StateMachine:
|
||||
|
||||
def __init__(self, bus: EventBus, loop: asyncio.events.AbstractEventLoop) -> None:
|
||||
"""Initialize state machine."""
|
||||
self._states = {} # type: Dict[str, State]
|
||||
self._states: Dict[str, State] = {}
|
||||
self._bus = bus
|
||||
self._loop = loop
|
||||
|
||||
@@ -1050,7 +1049,7 @@ class ServiceRegistry:
|
||||
|
||||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
"""Initialize a service registry."""
|
||||
self._services = {} # type: Dict[str, Dict[str, Service]]
|
||||
self._services: Dict[str, Dict[str, Service]] = {}
|
||||
self._hass = hass
|
||||
|
||||
@property
|
||||
@@ -1269,29 +1268,29 @@ class Config:
|
||||
"""Initialize a new config object."""
|
||||
self.hass = hass
|
||||
|
||||
self.latitude = 0 # type: float
|
||||
self.longitude = 0 # type: float
|
||||
self.elevation = 0 # type: int
|
||||
self.location_name = "Home" # type: str
|
||||
self.time_zone = dt_util.UTC # type: datetime.tzinfo
|
||||
self.units = METRIC_SYSTEM # type: UnitSystem
|
||||
self.latitude: float = 0
|
||||
self.longitude: float = 0
|
||||
self.elevation: int = 0
|
||||
self.location_name: str = "Home"
|
||||
self.time_zone: datetime.tzinfo = dt_util.UTC
|
||||
self.units: UnitSystem = METRIC_SYSTEM
|
||||
|
||||
self.config_source = "default" # type: str
|
||||
self.config_source: str = "default"
|
||||
|
||||
# If True, pip install is skipped for requirements on startup
|
||||
self.skip_pip = False # type: bool
|
||||
self.skip_pip: bool = False
|
||||
|
||||
# List of loaded components
|
||||
self.components = set() # type: set
|
||||
self.components: set = set()
|
||||
|
||||
# API (HTTP) server configuration, see components.http.ApiConfig
|
||||
self.api = None # type: Optional[Any]
|
||||
self.api: Optional[Any] = None
|
||||
|
||||
# Directory that holds the configuration
|
||||
self.config_dir = None # type: Optional[str]
|
||||
self.config_dir: Optional[str] = None
|
||||
|
||||
# List of allowed external dirs to access
|
||||
self.whitelist_external_dirs = set() # type: Set[str]
|
||||
self.whitelist_external_dirs: Set[str] = set()
|
||||
|
||||
def distance(self, lat: float, lon: float) -> Optional[float]:
|
||||
"""Calculate distance from Home Assistant.
|
||||
|
||||
Reference in New Issue
Block a user