mirror of
https://github.com/home-assistant/core.git
synced 2025-08-06 14:15:12 +02:00
Add setup type hints to binary_sensor
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
"""Support for raspihats board binary sensors."""
|
"""Support for raspihats board binary sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@@ -10,7 +12,10 @@ from homeassistant.const import (
|
|||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
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
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
CONF_BOARD,
|
CONF_BOARD,
|
||||||
@@ -18,9 +23,11 @@ from . import (
|
|||||||
CONF_I2C_HATS,
|
CONF_I2C_HATS,
|
||||||
CONF_INDEX,
|
CONF_INDEX,
|
||||||
CONF_INVERT_LOGIC,
|
CONF_INVERT_LOGIC,
|
||||||
|
DOMAIN,
|
||||||
I2C_HAT_NAMES,
|
I2C_HAT_NAMES,
|
||||||
I2C_HATS_MANAGER,
|
I2C_HATS_MANAGER,
|
||||||
I2CHatsException,
|
I2CHatsException,
|
||||||
|
I2CHatsManager,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -54,15 +61,21 @@ 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 raspihats binary_sensor devices."""
|
"""Set up the raspihats binary_sensor devices."""
|
||||||
I2CHatBinarySensor.I2C_HATS_MANAGER = hass.data[I2C_HATS_MANAGER]
|
I2CHatBinarySensor.I2C_HATS_MANAGER = hass.data[DOMAIN][I2C_HATS_MANAGER]
|
||||||
binary_sensors = []
|
binary_sensors = []
|
||||||
i2c_hat_configs = config.get(CONF_I2C_HATS)
|
i2c_hat_configs = config.get(CONF_I2C_HATS, [])
|
||||||
for i2c_hat_config in i2c_hat_configs:
|
for i2c_hat_config in i2c_hat_configs:
|
||||||
address = i2c_hat_config[CONF_ADDRESS]
|
address = i2c_hat_config[CONF_ADDRESS]
|
||||||
board = i2c_hat_config[CONF_BOARD]
|
board = i2c_hat_config[CONF_BOARD]
|
||||||
try:
|
try:
|
||||||
|
assert I2CHatBinarySensor.I2C_HATS_MANAGER
|
||||||
I2CHatBinarySensor.I2C_HATS_MANAGER.register_board(board, address)
|
I2CHatBinarySensor.I2C_HATS_MANAGER.register_board(board, address)
|
||||||
for channel_config in i2c_hat_config[CONF_CHANNELS]:
|
for channel_config in i2c_hat_config[CONF_CHANNELS]:
|
||||||
binary_sensors.append(
|
binary_sensors.append(
|
||||||
@@ -84,7 +97,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class I2CHatBinarySensor(BinarySensorEntity):
|
class I2CHatBinarySensor(BinarySensorEntity):
|
||||||
"""Representation of a binary sensor that uses a I2C-HAT digital input."""
|
"""Representation of a binary sensor that uses a I2C-HAT digital input."""
|
||||||
|
|
||||||
I2C_HATS_MANAGER = None
|
I2C_HATS_MANAGER: I2CHatsManager | None = None
|
||||||
|
|
||||||
def __init__(self, address, channel, name, invert_logic, device_class):
|
def __init__(self, address, channel, name, invert_logic, device_class):
|
||||||
"""Initialize the raspihats sensor."""
|
"""Initialize the raspihats sensor."""
|
||||||
|
Reference in New Issue
Block a user