Type hint improvements (#31876)
* Complete components.remote type hints * Define ConfigType only in helpers.typing
This commit is contained in:
parent
e5e7c9fa25
commit
03f7fe483b
7 changed files with 22 additions and 18 deletions
|
@ -7,8 +7,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.config_entries import CONN_CLASS_LOCAL_POLL, ConfigFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.helpers import ConfigType
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_SERIAL_NUMBER, DOMAIN # pylint: disable=unused-import
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from aioesphomeapi import APIClient, APIConnectionError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
from homeassistant.helpers import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .entry_data import DATA_KEY, RuntimeEntryData
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.helpers import ConfigType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@ from homeassistant.const import (
|
|||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import ConfigType, aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
from typing import Any, Iterable
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -19,9 +20,10 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
|||
)
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||
# mypy: allow-untyped-calls
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -57,12 +59,12 @@ REMOTE_SERVICE_ACTIVITY_SCHEMA = make_entity_service_schema(
|
|||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id):
|
||||
def is_on(hass: HomeAssistantType, entity_id: str) -> bool:
|
||||
"""Return if the remote is on based on the statemachine."""
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for remotes."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
||||
await component.async_setup(config)
|
||||
|
@ -111,24 +113,26 @@ class RemoteDevice(ToggleEntity):
|
|||
"""Representation of a remote."""
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
return 0
|
||||
|
||||
def send_command(self, command, **kwargs):
|
||||
"""Send a command to a device."""
|
||||
def send_command(self, command: Iterable[str], **kwargs: Any) -> None:
|
||||
"""Send commands to a device."""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def async_send_command(self, command, **kwargs):
|
||||
"""Send a command to a device."""
|
||||
async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
|
||||
"""Send commands to a device."""
|
||||
assert self.hass is not None
|
||||
await self.hass.async_add_executor_job(
|
||||
ft.partial(self.send_command, command, **kwargs)
|
||||
)
|
||||
|
||||
def learn_command(self, **kwargs):
|
||||
def learn_command(self, **kwargs: Any) -> None:
|
||||
"""Learn a command from a device."""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def async_learn_command(self, **kwargs):
|
||||
async def async_learn_command(self, **kwargs: Any) -> None:
|
||||
"""Learn a command from a device."""
|
||||
assert self.hass is not None
|
||||
await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs))
|
||||
|
|
|
@ -11,8 +11,8 @@ from homeassistant.config_entries import (
|
|||
ConfigFlow,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME
|
||||
from homeassistant.helpers import ConfigType
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN # pylint: disable=unused-import
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"""Helper methods for components within Home Assistant."""
|
||||
import re
|
||||
from typing import Any, Dict, Iterable, Sequence, Tuple
|
||||
from typing import Any, Iterable, Sequence, Tuple
|
||||
|
||||
from homeassistant.const import CONF_PLATFORM
|
||||
|
||||
ConfigType = Dict[str, Any]
|
||||
from .typing import ConfigType
|
||||
|
||||
|
||||
def config_per_platform(config: ConfigType, domain: str) -> Iterable[Tuple[Any, Any]]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue