mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add setup type hints [h] (#63438)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
ed791aa854
commit
fee95e129a
@ -11,6 +11,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import dispatcher, intent
|
from homeassistant.helpers import dispatcher, intent
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
# We need an import from .config_flow, without it .config_flow is never loaded.
|
# We need an import from .config_flow, without it .config_flow is never loaded.
|
||||||
from .config_flow import HangoutsFlowHandler # noqa: F401
|
from .config_flow import HangoutsFlowHandler # noqa: F401
|
||||||
@ -57,9 +58,9 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Hangouts bot component."""
|
"""Set up the Hangouts bot component."""
|
||||||
if (config := config.get(DOMAIN)) is None:
|
if (conf := config.get(DOMAIN)) is None:
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
CONF_INTENTS: {},
|
CONF_INTENTS: {},
|
||||||
CONF_DEFAULT_CONVERSATIONS: [],
|
CONF_DEFAULT_CONVERSATIONS: [],
|
||||||
@ -68,11 +69,9 @@ async def async_setup(hass, config):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
CONF_INTENTS: config[CONF_INTENTS],
|
CONF_INTENTS: conf[CONF_INTENTS],
|
||||||
CONF_DEFAULT_CONVERSATIONS: config[CONF_DEFAULT_CONVERSATIONS],
|
CONF_DEFAULT_CONVERSATIONS: conf[CONF_DEFAULT_CONVERSATIONS],
|
||||||
CONF_ERROR_SUPPRESSED_CONVERSATIONS: config[
|
CONF_ERROR_SUPPRESSED_CONVERSATIONS: conf[CONF_ERROR_SUPPRESSED_CONVERSATIONS],
|
||||||
CONF_ERROR_SUPPRESSED_CONVERSATIONS
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for haveibeenpwned (email breaches) sensor."""
|
"""Support for haveibeenpwned (email breaches) sensor."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
@ -9,8 +11,11 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_EMAIL
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_EMAIL
|
||||||
|
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.event import track_point_in_time
|
from homeassistant.helpers.event import track_point_in_time
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
@ -35,9 +40,14 @@ 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 HaveIBeenPwned sensor."""
|
"""Set up the HaveIBeenPwned sensor."""
|
||||||
emails = config.get(CONF_EMAIL)
|
emails = config[CONF_EMAIL]
|
||||||
api_key = config[CONF_API_KEY]
|
api_key = config[CONF_API_KEY]
|
||||||
data = HaveIBeenPwnedData(emails, api_key)
|
data = HaveIBeenPwnedData(emails, api_key)
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for Hikvision event stream events represented as binary sensors."""
|
"""Support for Hikvision event stream events represented as binary sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -23,8 +25,11 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import track_point_in_utc_time
|
from homeassistant.helpers.event import track_point_in_utc_time
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -84,15 +89,20 @@ 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 Hikvision binary sensor devices."""
|
"""Set up the Hikvision binary sensor devices."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
port = config.get(CONF_PORT)
|
port = config[CONF_PORT]
|
||||||
username = config.get(CONF_USERNAME)
|
username = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
|
|
||||||
customize = config.get(CONF_CUSTOMIZE)
|
customize = config[CONF_CUSTOMIZE]
|
||||||
|
|
||||||
protocol = "https" if config[CONF_SSL] else "http"
|
protocol = "https" if config[CONF_SSL] else "http"
|
||||||
|
|
||||||
@ -102,7 +112,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
if data.sensors is None:
|
if data.sensors is None:
|
||||||
_LOGGER.error("Hikvision event stream has no data, unable to set up")
|
_LOGGER.error("Hikvision event stream has no data, unable to set up")
|
||||||
return False
|
return
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
"""Support for HomeMatic binary sensors."""
|
"""Support for HomeMatic binary sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import ATTR_DISCOVER_DEVICES, ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY
|
from .const import ATTR_DISCOVER_DEVICES, ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY
|
||||||
from .entity import HMDevice
|
from .entity import HMDevice
|
||||||
@ -29,12 +34,17 @@ SENSOR_TYPES_CLASS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 HomeMatic binary sensor platform."""
|
"""Set up the HomeMatic binary sensor platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
devices = []
|
devices: list[BinarySensorEntity] = []
|
||||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
if discovery_info[ATTR_DISCOVERY_TYPE] == DISCOVER_BATTERY:
|
if discovery_info[ATTR_DISCOVERY_TYPE] == DISCOVER_BATTERY:
|
||||||
devices.append(HMBatterySensor(conf))
|
devices.append(HMBatterySensor(conf))
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
"""Support for HomeMatic covers."""
|
"""Support for HomeMatic covers."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TILT_POSITION,
|
ATTR_TILT_POSITION,
|
||||||
CoverDeviceClass,
|
CoverDeviceClass,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import ATTR_DEVICE_TYPE, ATTR_DISCOVER_DEVICES
|
from .const import ATTR_DEVICE_TYPE, ATTR_DISCOVER_DEVICES
|
||||||
from .entity import HMDevice
|
from .entity import HMDevice
|
||||||
@ -12,18 +17,22 @@ from .entity import HMDevice
|
|||||||
HM_GARAGE = ("IPGarage",)
|
HM_GARAGE = ("IPGarage",)
|
||||||
|
|
||||||
|
|
||||||
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 platform."""
|
"""Set up the platform."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
devices = []
|
devices: list[HMCover] = []
|
||||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
if conf[ATTR_DEVICE_TYPE] in HM_GARAGE:
|
if conf[ATTR_DEVICE_TYPE] in HM_GARAGE:
|
||||||
new_device = HMGarage(conf)
|
devices.append(HMGarage(conf))
|
||||||
else:
|
else:
|
||||||
new_device = HMCover(conf)
|
devices.append(HMCover(conf))
|
||||||
devices.append(new_device)
|
|
||||||
|
|
||||||
add_entities(devices, True)
|
add_entities(devices, True)
|
||||||
|
|
||||||
|
@ -11,10 +11,11 @@ from homeassistant.const import (
|
|||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
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.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -63,7 +64,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, base_config):
|
def setup(hass: HomeAssistant, base_config: ConfigType) -> bool:
|
||||||
"""Start Homeworks controller."""
|
"""Start Homeworks controller."""
|
||||||
|
|
||||||
def hw_callback(msg_type, values):
|
def hw_callback(msg_type, values):
|
||||||
@ -73,7 +74,7 @@ def setup(hass, base_config):
|
|||||||
signal = f"homeworks_entity_{addr}"
|
signal = f"homeworks_entity_{addr}"
|
||||||
dispatcher_send(hass, signal, msg_type, values)
|
dispatcher_send(hass, signal, msg_type, values)
|
||||||
|
|
||||||
config = base_config.get(DOMAIN)
|
config = base_config[DOMAIN]
|
||||||
controller = Homeworks(config[CONF_HOST], config[CONF_PORT], hw_callback)
|
controller = Homeworks(config[CONF_HOST], config[CONF_PORT], hw_callback)
|
||||||
hass.data[HOMEWORKS_CONTROLLER] = controller
|
hass.data[HOMEWORKS_CONTROLLER] = controller
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Support for information from HP iLO sensors."""
|
"""Support for information from HP iLO sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -17,7 +19,10 @@ from homeassistant.const import (
|
|||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
CONF_VALUE_TEMPLATE,
|
CONF_VALUE_TEMPLATE,
|
||||||
)
|
)
|
||||||
|
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
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -67,13 +72,18 @@ 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 HP iLO sensors."""
|
"""Set up the HP iLO sensors."""
|
||||||
hostname = config.get(CONF_HOST)
|
hostname = config[CONF_HOST]
|
||||||
port = config.get(CONF_PORT)
|
port = config[CONF_PORT]
|
||||||
login = config.get(CONF_USERNAME)
|
login = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
monitored_variables = config.get(CONF_MONITORED_VARIABLES)
|
monitored_variables = config[CONF_MONITORED_VARIABLES]
|
||||||
|
|
||||||
# Create a data fetcher to support all of the configured sensors. Then make
|
# Create a data fetcher to support all of the configured sensors. Then make
|
||||||
# the first call to init the data and confirm we can connect.
|
# the first call to init the data and confirm we can connect.
|
||||||
@ -89,7 +99,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
new_device = HpIloSensor(
|
new_device = HpIloSensor(
|
||||||
hass=hass,
|
hass=hass,
|
||||||
hp_ilo_data=hp_ilo_data,
|
hp_ilo_data=hp_ilo_data,
|
||||||
sensor_name=f"{config.get(CONF_NAME)} {monitored_variable[CONF_NAME]}",
|
sensor_name=f"{config[CONF_NAME]} {monitored_variable[CONF_NAME]}",
|
||||||
sensor_type=monitored_variable[CONF_SENSOR_TYPE],
|
sensor_type=monitored_variable[CONF_SENSOR_TYPE],
|
||||||
sensor_value_template=monitored_variable.get(CONF_VALUE_TEMPLATE),
|
sensor_value_template=monitored_variable.get(CONF_VALUE_TEMPLATE),
|
||||||
unit_of_measurement=monitored_variable.get(CONF_UNIT_OF_MEASUREMENT),
|
unit_of_measurement=monitored_variable.get(CONF_UNIT_OF_MEASUREMENT),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user