mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add setup type hints [i-k] (#63444)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
fee95e129a
commit
178d2848f3
@ -1,4 +1,6 @@
|
|||||||
"""Component for interfacing RFK101 proximity card readers."""
|
"""Component for interfacing RFK101 proximity card readers."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from rfk101py.rfk101py import rfk101py
|
from rfk101py.rfk101py import rfk101py
|
||||||
@ -10,7 +12,9 @@ from homeassistant.const import (
|
|||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import Event, HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -37,7 +41,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the IDTECK proximity card component."""
|
"""Set up the IDTECK proximity card component."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
for unit in conf:
|
for unit in conf:
|
||||||
@ -78,7 +82,7 @@ class IdteckReader:
|
|||||||
EVENT_IDTECK_PROX_KEYCARD, {"card": card, "name": self._name}
|
EVENT_IDTECK_PROX_KEYCARD, {"card": card, "name": self._name}
|
||||||
)
|
)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self, _: Event) -> None:
|
||||||
"""Close resources."""
|
"""Close resources."""
|
||||||
if self._connection:
|
if self._connection:
|
||||||
self._connection.close()
|
self._connection.close()
|
||||||
|
@ -22,6 +22,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_CONTROLLER_ID,
|
ATTR_CONTROLLER_ID,
|
||||||
@ -224,9 +225,9 @@ PULSE_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the IHC integration."""
|
"""Set up the IHC integration."""
|
||||||
conf = config.get(DOMAIN)
|
conf = config[DOMAIN]
|
||||||
for index, controller_conf in enumerate(conf):
|
for index, controller_conf in enumerate(conf):
|
||||||
if not ihc_setup(hass, config, controller_conf, index):
|
if not ihc_setup(hass, config, controller_conf, index):
|
||||||
return False
|
return False
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Numeric integration of data coming from a source sensor over time."""
|
"""Numeric integration of data coming from a source sensor over time."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from decimal import Decimal, DecimalException
|
from decimal import Decimal, DecimalException
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -22,10 +24,12 @@ from homeassistant.const import (
|
|||||||
TIME_MINUTES,
|
TIME_MINUTES,
|
||||||
TIME_SECONDS,
|
TIME_SECONDS,
|
||||||
)
|
)
|
||||||
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_state_change_event
|
from homeassistant.helpers.event import async_track_state_change_event
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
|
|
||||||
@ -77,7 +81,12 @@ PLATFORM_SCHEMA = vol.All(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Set up the integration sensor."""
|
"""Set up the integration sensor."""
|
||||||
integral = IntegrationSensor(
|
integral = IntegrationSensor(
|
||||||
config[CONF_SOURCE_SENSOR],
|
config[CONF_SOURCE_SENSOR],
|
||||||
@ -97,14 +106,14 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
source_entity,
|
source_entity: str,
|
||||||
name,
|
name: str | None,
|
||||||
round_digits,
|
round_digits: int,
|
||||||
unit_prefix,
|
unit_prefix: str | None,
|
||||||
unit_time,
|
unit_time: str,
|
||||||
unit_of_measurement,
|
unit_of_measurement: str | None,
|
||||||
integration_method,
|
integration_method: str,
|
||||||
):
|
) -> None:
|
||||||
"""Initialize the integration sensor."""
|
"""Initialize the integration sensor."""
|
||||||
self._sensor_source_id = source_entity
|
self._sensor_source_id = source_entity
|
||||||
self._round_digits = round_digits
|
self._round_digits = round_digits
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Native Home Assistant iOS app component."""
|
"""Native Home Assistant iOS app component."""
|
||||||
import datetime
|
import datetime
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_validation as cv, discovery
|
from homeassistant.helpers import config_validation as cv, discovery
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.json import load_json, save_json
|
from homeassistant.util.json import load_json, save_json
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -247,7 +249,7 @@ def device_name_for_push_id(hass, push_id):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the iOS component."""
|
"""Set up the iOS component."""
|
||||||
conf = config.get(DOMAIN)
|
conf = config.get(DOMAIN)
|
||||||
|
|
||||||
@ -255,6 +257,9 @@ async def async_setup(hass, config):
|
|||||||
load_json, hass.config.path(CONFIGURATION_FILE)
|
load_json, hass.config.path(CONFIGURATION_FILE)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert isinstance(ios_config, dict)
|
||||||
|
|
||||||
if ios_config == {}:
|
if ios_config == {}:
|
||||||
ios_config[ATTR_DEVICES] = {}
|
ios_config[ATTR_DEVICES] = {}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for iTach IR devices."""
|
"""Support for iTach IR devices."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pyitachip2ir
|
import pyitachip2ir
|
||||||
@ -18,7 +20,10 @@ from homeassistant.const import (
|
|||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
DEVICE_DEFAULT_NAME,
|
DEVICE_DEFAULT_NAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -63,18 +68,23 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
add_entities: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Set up the ITach connection and devices."""
|
"""Set up the ITach connection and devices."""
|
||||||
itachip2ir = pyitachip2ir.ITachIP2IR(
|
itachip2ir = pyitachip2ir.ITachIP2IR(
|
||||||
config.get(CONF_MAC), config.get(CONF_HOST), int(config.get(CONF_PORT))
|
config.get(CONF_MAC), config[CONF_HOST], int(config[CONF_PORT])
|
||||||
)
|
)
|
||||||
|
|
||||||
if not itachip2ir.ready(CONNECT_TIMEOUT):
|
if not itachip2ir.ready(CONNECT_TIMEOUT):
|
||||||
_LOGGER.error("Unable to find iTach")
|
_LOGGER.error("Unable to find iTach")
|
||||||
return False
|
return
|
||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
for data in config.get(CONF_DEVICES):
|
for data in config[CONF_DEVICES]:
|
||||||
name = data.get(CONF_NAME)
|
name = data.get(CONF_NAME)
|
||||||
modaddr = int(data.get(CONF_MODADDR, DEFAULT_MODADDR))
|
modaddr = int(data.get(CONF_MODADDR, DEFAULT_MODADDR))
|
||||||
connaddr = int(data.get(CONF_CONNADDR, DEFAULT_CONNADDR))
|
connaddr = int(data.get(CONF_CONNADDR, DEFAULT_CONNADDR))
|
||||||
@ -91,7 +101,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
itachip2ir.addDevice(name, modaddr, connaddr, cmddatas)
|
itachip2ir.addDevice(name, modaddr, connaddr, cmddatas)
|
||||||
devices.append(ITachIP2IRRemote(itachip2ir, name, ir_count))
|
devices.append(ITachIP2IRRemote(itachip2ir, name, ir_count))
|
||||||
add_entities(devices, True)
|
add_entities(devices, True)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ITachIP2IRRemote(remote.RemoteEntity):
|
class ITachIP2IRRemote(remote.RemoteEntity):
|
||||||
|
@ -10,7 +10,9 @@ from evdev import InputDevice, categorize, ecodes, list_devices
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -60,9 +62,9 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the keyboard_remote."""
|
"""Set up the keyboard_remote."""
|
||||||
config = config.get(DOMAIN)
|
config = config[DOMAIN]
|
||||||
|
|
||||||
remote = KeyboardRemote(hass, config)
|
remote = KeyboardRemote(hass, config)
|
||||||
remote.setup()
|
remote.setup()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user