Type hint improvements (#32905)
* Complete helpers.entity_component type hints * Add discovery info type
This commit is contained in:
1 parent
7c79adad8f
commit
05abf37046
13 files changed
+120
-76
No files matched your search
@@ -12,6 +12,7 @@ from homeassistant.config_entries import CONN_CLASS_LOCAL_POLL, ConfigFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from .const import DEFAULT_PORT
|
||||
from .const import DOMAIN # pylint: disable=unused-import
|
||||
@@ -83,7 +84,7 @@ class DirecTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_create_entry(title=info["title"], data=user_input)
|
||||
|
||||
async def async_step_ssdp(
|
||||
self, discovery_info: Optional[Dict] = None
|
||||
self, discovery_info: Optional[DiscoveryInfoType] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle a flow initialized by discovery."""
|
||||
host = urlparse(discovery_info[ATTR_SSDP_LOCATION]).hostname
|
||||
|
||||
@@ -19,7 +19,11 @@ from homeassistant.const import (
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
from homeassistant.helpers.typing import (
|
||||
ConfigType,
|
||||
DiscoveryInfoType,
|
||||
HomeAssistantType,
|
||||
)
|
||||
from homeassistant.util import slugify
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@@ -332,7 +336,7 @@ def setup_platform(
|
||||
hass: HomeAssistantType,
|
||||
config: ConfigType,
|
||||
add_entities: Callable[[list], None],
|
||||
discovery_info: Optional[dict] = None,
|
||||
discovery_info: Optional[DiscoveryInfoType] = None,
|
||||
) -> None:
|
||||
"""Set up the GTFS sensor."""
|
||||
gtfs_dir = hass.config.path(DEFAULT_PATH)
|
||||
|
||||
@@ -24,6 +24,7 @@ from homeassistant.core import HomeAssistant, State, callback
|
||||
from homeassistant.helpers import location
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
import homeassistant.util.dt as dt
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -144,7 +145,7 @@ async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: Dict[str, Union[str, bool]],
|
||||
async_add_entities: Callable,
|
||||
discovery_info: None = None,
|
||||
discovery_info: Optional[DiscoveryInfoType] = None,
|
||||
) -> None:
|
||||
"""Set up the HERE travel time platform."""
|
||||
|
||||
|
||||
@@ -114,9 +114,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
return cast(
|
||||
bool, await cast(EntityComponent, hass.data[DOMAIN]).async_setup_entry(entry)
|
||||
)
|
||||
return await cast(EntityComponent, hass.data[DOMAIN]).async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Light support for switch entities."""
|
||||
import logging
|
||||
from typing import Callable, Dict, Optional, Sequence, cast
|
||||
from typing import Callable, Optional, Sequence, cast
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -17,7 +17,11 @@ from homeassistant.core import CALLBACK_TYPE, State, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import async_track_state_change
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
from homeassistant.helpers.typing import (
|
||||
ConfigType,
|
||||
DiscoveryInfoType,
|
||||
HomeAssistantType,
|
||||
)
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs
|
||||
|
||||
@@ -37,7 +41,7 @@ async def async_setup_platform(
|
||||
hass: HomeAssistantType,
|
||||
config: ConfigType,
|
||||
async_add_entities: Callable[[Sequence[Entity], bool], None],
|
||||
discovery_info: Optional[Dict] = None,
|
||||
discovery_info: Optional[DiscoveryInfoType] = None,
|
||||
) -> None:
|
||||
"""Initialize Light Switch platform."""
|
||||
async_add_entities(
|
||||
|
||||
@@ -20,6 +20,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import (
|
||||
ContextType,
|
||||
DiscoveryInfoType,
|
||||
EventType,
|
||||
HomeAssistantType,
|
||||
ServiceCallType,
|
||||
@@ -115,7 +116,7 @@ async def async_setup(hass: HomeAssistantType, config: Dict) -> bool:
|
||||
hass.data[DOMAIN] = {DATA_DEVICE: device_data}
|
||||
|
||||
async def async_switch_platform_discovered(
|
||||
platform: str, discovery_info: Optional[Dict]
|
||||
platform: str, discovery_info: DiscoveryInfoType
|
||||
) -> None:
|
||||
"""Use for registering services after switch platform is discovered."""
|
||||
if platform != DOMAIN:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Config flow for Vizio."""
|
||||
import copy
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from pyvizio import VizioAsync, async_guess_device_type
|
||||
import voluptuous as vol
|
||||
@@ -23,6 +23,7 @@ from homeassistant.const import (
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from .const import (
|
||||
CONF_APPS,
|
||||
@@ -318,7 +319,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return await self.async_step_user(user_input=import_config)
|
||||
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: Dict[str, Any] = None
|
||||
self, discovery_info: Optional[DiscoveryInfoType] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle zeroconf discovery."""
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ async def async_setup(hass: HomeAssistant, config: Dict) -> bool:
|
||||
|
||||
home_zone = Zone(_home_conf(hass), True,)
|
||||
home_zone.entity_id = ENTITY_ID_HOME
|
||||
await component.async_add_entities([home_zone]) # type: ignore
|
||||
await component.async_add_entities([home_zone])
|
||||
|
||||
async def core_config_updated(_: Event) -> None:
|
||||
"""Handle core config updated."""
|
||||
|
||||
Reference in new issue
Block a user