Add basic type hints to xiaomi_miio (#62889)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
de64622f3b
commit
cb135bc889
12 changed files with 102 additions and 24 deletions
|
@ -4,7 +4,10 @@ import logging
|
|||
from miio import AirQualityMonitor, AirQualityMonitorCGDN1, DeviceException
|
||||
|
||||
from homeassistant.components.air_quality import AirQualityEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -236,7 +239,11 @@ DEVICE_MAP = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi Air Quality from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Support for Xiomi Gateway alarm control panels."""
|
||||
|
||||
from functools import partial
|
||||
import logging
|
||||
|
||||
|
@ -9,12 +8,15 @@ from homeassistant.components.alarm_control_panel import (
|
|||
SUPPORT_ALARM_ARM_AWAY,
|
||||
AlarmControlPanelEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
STATE_ALARM_ARMED_AWAY,
|
||||
STATE_ALARM_ARMING,
|
||||
STATE_ALARM_DISARMED,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_GATEWAY, DOMAIN
|
||||
|
||||
|
@ -25,7 +27,11 @@ XIAOMI_STATE_DISARMED_VALUE = "off"
|
|||
XIAOMI_STATE_ARMING_VALUE = "oning"
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi Gateway Alarm from a config entry."""
|
||||
entities = []
|
||||
gateway = hass.data[DOMAIN][config_entry.entry_id][CONF_GATEWAY]
|
||||
|
|
|
@ -10,8 +10,10 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import VacuumCoordinatorDataAttributes
|
||||
from .const import (
|
||||
|
@ -158,7 +160,11 @@ def _setup_vacuum_sensors(hass, config_entry, async_add_entities):
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi sensor from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
|
|
@ -24,9 +24,11 @@ from homeassistant.components.fan import (
|
|||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
ranged_value_to_percentage,
|
||||
|
@ -172,7 +174,11 @@ FAN_DIRECTIONS_MAP = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Fan from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
@ -222,7 +228,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
entities.append(entity)
|
||||
|
||||
async def async_service_handler(service):
|
||||
async def async_service_handler(service: ServiceCall) -> None:
|
||||
"""Map services to methods on XiaomiAirPurifier."""
|
||||
method = SERVICE_TO_METHOD[service.service]
|
||||
params = {
|
||||
|
|
|
@ -8,8 +8,10 @@ from miio.airhumidifier_mjjsq import OperationMode as AirhumidifierMjjsqOperatio
|
|||
|
||||
from homeassistant.components.humidifier import HumidifierDeviceClass, HumidifierEntity
|
||||
from homeassistant.components.humidifier.const import SUPPORT_MODES
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_MODE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.percentage import percentage_to_ranged_value
|
||||
|
||||
from .const import (
|
||||
|
@ -55,7 +57,11 @@ AVAILABLE_MODES_OTHER = [
|
|||
]
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Humidifier from a config entry."""
|
||||
if not config_entry.data[CONF_FLOW_TYPE] == CONF_DEVICE:
|
||||
return
|
||||
|
|
|
@ -24,9 +24,12 @@ from homeassistant.components.light import (
|
|||
SUPPORT_COLOR_TEMP,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import color, dt
|
||||
|
||||
from .const import (
|
||||
|
@ -109,7 +112,11 @@ SERVICE_TO_METHOD = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi light from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
@ -187,7 +194,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
)
|
||||
return
|
||||
|
||||
async def async_service_handler(service):
|
||||
async def async_service_handler(service: ServiceCall) -> None:
|
||||
"""Map services to methods on Xiaomi Philips Lights."""
|
||||
method = SERVICE_TO_METHOD.get(service.service)
|
||||
params = {
|
||||
|
|
|
@ -4,9 +4,11 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEGREE, TIME_MINUTES
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -228,7 +230,11 @@ OSCILLATION_ANGLE_VALUES = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Selectors from a config entry."""
|
||||
entities = []
|
||||
if not config_entry.data[CONF_FLOW_TYPE] == CONF_DEVICE:
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Support for the Xiaomi IR Remote (Chuangmi IR)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
@ -21,8 +23,11 @@ from homeassistant.const import (
|
|||
CONF_TIMEOUT,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from .const import SERVICE_LEARN, SERVICE_SET_REMOTE_LED_OFF, SERVICE_SET_REMOTE_LED_ON
|
||||
|
@ -58,7 +63,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
)
|
||||
|
||||
|
||||
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 Xiaomi IR Remote (Chuangmi IR) platform."""
|
||||
host = config[CONF_HOST]
|
||||
token = config[CONF_TOKEN]
|
||||
|
|
|
@ -11,8 +11,10 @@ from miio.airpurifier_miot import LedBrightness as AirpurifierMiotLedBrightness
|
|||
from miio.fan import LedBrightness as FanLedBrightness
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -68,7 +70,11 @@ SELECTOR_TYPES = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Selectors from a config entry."""
|
||||
if not config_entry.data[CONF_FLOW_TYPE] == CONF_DEVICE:
|
||||
return
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
AREA_SQUARE_METERS,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
|
@ -37,8 +38,9 @@ from homeassistant.const import (
|
|||
TIME_SECONDS,
|
||||
VOLUME_CUBIC_METERS,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import VacuumCoordinatorDataAttributes
|
||||
|
@ -550,7 +552,11 @@ def _setup_vacuum_sensors(hass, config_entry, async_add_entities):
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi sensor from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.switch import (
|
|||
SwitchEntity,
|
||||
SwitchEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_MODE,
|
||||
|
@ -22,9 +23,10 @@ from homeassistant.const import (
|
|||
CONF_HOST,
|
||||
CONF_TOKEN,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
CONF_DEVICE,
|
||||
|
@ -274,7 +276,11 @@ SWITCH_TYPES = (
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the switch from a config entry."""
|
||||
model = config_entry.data[CONF_MODEL]
|
||||
if model in (*MODELS_HUMIDIFIER, *MODELS_FAN):
|
||||
|
@ -405,7 +411,7 @@ async def async_setup_other_entry(hass, config_entry, async_add_entities):
|
|||
model,
|
||||
)
|
||||
|
||||
async def async_service_handler(service):
|
||||
async def async_service_handler(service: ServiceCall) -> None:
|
||||
"""Map services to methods on XiaomiPlugGenericSwitch."""
|
||||
method = SERVICE_TO_METHOD.get(service.service)
|
||||
params = {
|
||||
|
|
|
@ -26,8 +26,10 @@ from homeassistant.components.vacuum import (
|
|||
SUPPORT_STOP,
|
||||
StateVacuumEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.dt import as_utc
|
||||
|
||||
from . import VacuumCoordinatorData
|
||||
|
@ -98,7 +100,11 @@ STATE_CODE_TO_STATE = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Xiaomi vacuum cleaner robot from a config entry."""
|
||||
entities = []
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue