Remove HomeAssistantType alias from entity components - Part 1 (#48467)

This commit is contained in:
Franck Nijhof 2021-03-30 01:24:36 +02:00 committed by GitHub
parent bb9da22a84
commit 855b68faa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 60 additions and 76 deletions

View File

@ -2,13 +2,12 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.exclude_domain() registry.exclude_domain()

View File

@ -10,13 +10,12 @@ from homeassistant.const import (
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
STATE_OFF, STATE_OFF,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.on_off_states( registry.on_off_states(

View File

@ -20,8 +20,7 @@ from homeassistant.const import (
STATE_ALARM_DISARMED, STATE_ALARM_DISARMED,
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
) )
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN from . import DOMAIN
@ -38,7 +37,7 @@ VALID_STATES = {
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -82,7 +81,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -12,8 +12,7 @@ from homeassistant.const import (
STATE_OFF, STATE_OFF,
STATE_ON, STATE_ON,
) )
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN from . import DOMAIN
@ -23,7 +22,7 @@ VALID_STATES = {STATE_ON, STATE_OFF}
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -60,7 +59,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -12,8 +12,7 @@ from homeassistant.const import (
STATE_OFF, STATE_OFF,
STATE_ON, STATE_ON,
) )
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN from . import DOMAIN
@ -23,7 +22,7 @@ VALID_STATES = {STATE_ON, STATE_OFF}
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -59,7 +58,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -3,13 +3,12 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.on_off_states({STATE_ON}, STATE_OFF) registry.on_off_states({STATE_ON}, STATE_OFF)

View File

@ -19,6 +19,7 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import ( # noqa: F401 from homeassistant.helpers.config_validation import ( # noqa: F401
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
@ -28,7 +29,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.temperature import display_temp as show_temp
from homeassistant.helpers.typing import ConfigType, HomeAssistantType, ServiceDataType from homeassistant.helpers.typing import ConfigType, ServiceDataType
from homeassistant.util.temperature import convert as convert_temperature from homeassistant.util.temperature import convert as convert_temperature
from .const import ( from .const import (
@ -102,7 +103,7 @@ SET_TEMPERATURE_SCHEMA = vol.All(
) )
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up climate entities.""" """Set up climate entities."""
component = hass.data[DOMAIN] = EntityComponent( component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL _LOGGER, DOMAIN, hass, SCAN_INTERVAL
@ -156,12 +157,12 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
return True return True
async def async_setup_entry(hass: HomeAssistantType, entry): async def async_setup_entry(hass: HomeAssistant, entry):
"""Set up a config entry.""" """Set up a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry) return await hass.data[DOMAIN].async_setup_entry(entry)
async def async_unload_entry(hass: HomeAssistantType, entry): async def async_unload_entry(hass: HomeAssistant, entry):
"""Unload a config entry.""" """Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry) return await hass.data[DOMAIN].async_unload_entry(entry)

View File

@ -3,15 +3,14 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.const import STATE_OFF from homeassistant.const import STATE_OFF
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
from .const import HVAC_MODE_OFF, HVAC_MODES from .const import HVAC_MODE_OFF, HVAC_MODES
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.on_off_states( registry.on_off_states(

View File

@ -5,8 +5,7 @@ import asyncio
from typing import Any, Iterable from typing import Any, Iterable
from homeassistant.const import ATTR_TEMPERATURE from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from .const import ( from .const import (
ATTR_AUX_HEAT, ATTR_AUX_HEAT,
@ -28,7 +27,7 @@ from .const import (
async def _async_reproduce_states( async def _async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -75,7 +74,7 @@ async def _async_reproduce_states(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -15,10 +15,9 @@ from homeassistant.components.alexa import (
) )
from homeassistant.components.google_assistant import const as gc, smart_home as ga from homeassistant.components.google_assistant import const as gc, smart_home as ga
from homeassistant.const import HTTP_OK from homeassistant.const import HTTP_OK
from homeassistant.core import Context, callback from homeassistant.core import Context, HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_call_later from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.aiohttp import MockRequest from homeassistant.util.aiohttp import MockRequest
from . import alexa_config, google_config, utils from . import alexa_config, google_config, utils
@ -31,7 +30,7 @@ class CloudClient(Interface):
def __init__( def __init__(
self, self,
hass: HomeAssistantType, hass: HomeAssistant,
prefs: CloudPreferences, prefs: CloudPreferences,
websession: aiohttp.ClientSession, websession: aiohttp.ClientSession,
alexa_user_config: dict[str, Any], alexa_user_config: dict[str, Any],

View File

@ -6,9 +6,8 @@ from homeassistant.components.group import (
) )
from homeassistant.config import GROUP_CONFIG_PATH from homeassistant.config import GROUP_CONFIG_PATH
from homeassistant.const import SERVICE_RELOAD from homeassistant.const import SERVICE_RELOAD
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import HomeAssistantType
from . import EditKeyBasedConfigView from . import EditKeyBasedConfigView
@ -35,7 +34,7 @@ async def async_setup(hass):
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
return return

View File

@ -13,13 +13,13 @@ from homeassistant.const import (
CONF_MINIMUM, CONF_MINIMUM,
CONF_NAME, CONF_NAME,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import collection from homeassistant.helpers import collection
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.storage import Store from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -101,7 +101,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the counters.""" """Set up the counters."""
component = EntityComponent(_LOGGER, DOMAIN, hass) component = EntityComponent(_LOGGER, DOMAIN, hass)
id_manager = collection.IDManager() id_manager = collection.IDManager()

View File

@ -6,8 +6,7 @@ import logging
from typing import Any, Iterable from typing import Any, Iterable
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import ( from . import (
ATTR_INITIAL, ATTR_INITIAL,
@ -23,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -69,7 +68,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -3,13 +3,12 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.const import STATE_CLOSED, STATE_OPEN from homeassistant.const import STATE_CLOSED, STATE_OPEN
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
# On means open, Off means closed # On means open, Off means closed

View File

@ -24,8 +24,7 @@ from homeassistant.const import (
STATE_OPEN, STATE_OPEN,
STATE_OPENING, STATE_OPENING,
) )
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN from . import DOMAIN
@ -35,7 +34,7 @@ VALID_STATES = {STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING}
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -116,7 +115,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,

View File

@ -1,6 +1,7 @@
"""Provide functionality to keep track of devices.""" """Provide functionality to keep track of devices."""
from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME # noqa: F401 from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME # noqa: F401
from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from .config_entry import async_setup_entry, async_unload_entry # noqa: F401 from .config_entry import async_setup_entry, async_unload_entry # noqa: F401
@ -36,12 +37,12 @@ from .legacy import ( # noqa: F401
@bind_hass @bind_hass
def is_on(hass: HomeAssistantType, entity_id: str): def is_on(hass: HomeAssistant, entity_id: str):
"""Return the state if any or a specified device is home.""" """Return the state if any or a specified device is home."""
return hass.states.is_state(entity_id, STATE_HOME) return hass.states.is_state(entity_id, STATE_HOME)
async def async_setup(hass: HomeAssistantType, config: ConfigType): async def async_setup(hass: HomeAssistant, config: ConfigType):
"""Set up the device tracker.""" """Set up the device tracker."""
await async_setup_legacy_integration(hass, config) await async_setup_legacy_integration(hass, config)

View File

@ -3,13 +3,12 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.const import STATE_HOME, STATE_NOT_HOME from homeassistant.const import STATE_HOME, STATE_NOT_HOME
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.on_off_states({STATE_HOME}, STATE_NOT_HOME) registry.on_off_states({STATE_HOME}, STATE_NOT_HOME)

View File

@ -27,7 +27,7 @@ from homeassistant.const import (
STATE_HOME, STATE_HOME,
STATE_NOT_HOME, STATE_NOT_HOME,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_per_platform, discovery from homeassistant.helpers import config_per_platform, discovery
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -37,7 +37,7 @@ from homeassistant.helpers.event import (
async_track_utc_time_change, async_track_utc_time_change,
) )
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, GPSType, HomeAssistantType from homeassistant.helpers.typing import ConfigType, GPSType
from homeassistant.setup import async_prepare_setup_platform from homeassistant.setup import async_prepare_setup_platform
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from homeassistant.util.yaml import dump from homeassistant.util.yaml import dump
@ -119,7 +119,7 @@ EVENT_NEW_DEVICE = "device_tracker_new_device"
def see( def see(
hass: HomeAssistantType, hass: HomeAssistant,
mac: str = None, mac: str = None,
dev_id: str = None, dev_id: str = None,
host_name: str = None, host_name: str = None,
@ -148,7 +148,7 @@ def see(
hass.services.call(DOMAIN, SERVICE_SEE, data) hass.services.call(DOMAIN, SERVICE_SEE, data)
async def async_setup_integration(hass: HomeAssistantType, config: ConfigType) -> None: async def async_setup_integration(hass: HomeAssistant, config: ConfigType) -> None:
"""Set up the legacy integration.""" """Set up the legacy integration."""
tracker = await get_tracker(hass, config) tracker = await get_tracker(hass, config)
@ -302,7 +302,7 @@ async def async_create_platform_type(
@callback @callback
def async_setup_scanner_platform( def async_setup_scanner_platform(
hass: HomeAssistantType, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
scanner: Any, scanner: Any,
async_see_device: Callable, async_see_device: Callable,
@ -392,7 +392,7 @@ class DeviceTracker:
def __init__( def __init__(
self, self,
hass: HomeAssistantType, hass: HomeAssistant,
consider_home: timedelta, consider_home: timedelta,
track_new: bool, track_new: bool,
defaults: dict, defaults: dict,
@ -609,7 +609,7 @@ class Device(RestoreEntity):
def __init__( def __init__(
self, self,
hass: HomeAssistantType, hass: HomeAssistant,
consider_home: timedelta, consider_home: timedelta,
track: bool, track: bool,
dev_id: str, dev_id: str,
@ -790,7 +790,7 @@ class Device(RestoreEntity):
class DeviceScanner: class DeviceScanner:
"""Device scanner object.""" """Device scanner object."""
hass: HomeAssistantType = None hass: HomeAssistant = None
def scan_devices(self) -> list[str]: def scan_devices(self) -> list[str]:
"""Scan for devices.""" """Scan for devices."""
@ -817,9 +817,7 @@ class DeviceScanner:
return await self.hass.async_add_executor_job(self.get_extra_attributes, device) return await self.hass.async_add_executor_job(self.get_extra_attributes, device)
async def async_load_config( async def async_load_config(path: str, hass: HomeAssistant, consider_home: timedelta):
path: str, hass: HomeAssistantType, consider_home: timedelta
):
"""Load devices from YAML configuration file. """Load devices from YAML configuration file.
This method is a coroutine. This method is a coroutine.

View File

@ -3,13 +3,12 @@
from homeassistant.components.group import GroupIntegrationRegistry from homeassistant.components.group import GroupIntegrationRegistry
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import HomeAssistantType
@callback @callback
def async_describe_on_off_states( def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry hass: HomeAssistant, registry: GroupIntegrationRegistry
) -> None: ) -> None:
"""Describe group on off states.""" """Describe group on off states."""
registry.on_off_states({STATE_ON}, STATE_OFF) registry.on_off_states({STATE_ON}, STATE_OFF)

View File

@ -13,8 +13,7 @@ from homeassistant.const import (
STATE_OFF, STATE_OFF,
STATE_ON, STATE_ON,
) )
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from homeassistant.helpers.typing import HomeAssistantType
from . import ( from . import (
ATTR_DIRECTION, ATTR_DIRECTION,
@ -43,7 +42,7 @@ ATTRIBUTES = { # attribute: service
async def _async_reproduce_state( async def _async_reproduce_state(
hass: HomeAssistantType, hass: HomeAssistant,
state: State, state: State,
*, *,
context: Context | None = None, context: Context | None = None,
@ -97,7 +96,7 @@ async def _async_reproduce_state(
async def async_reproduce_states( async def async_reproduce_states(
hass: HomeAssistantType, hass: HomeAssistant,
states: Iterable[State], states: Iterable[State],
*, *,
context: Context | None = None, context: Context | None = None,