Add setup type hints [x-z] (#63485)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
a4fdaffb14
commit
d20851812e
4 changed files with 56 additions and 19 deletions
|
@ -1,4 +1,6 @@
|
|||
"""Support for XBee Zigbee sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from binascii import hexlify
|
||||
import logging
|
||||
|
||||
|
@ -7,6 +9,9 @@ from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure
|
|||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.const import CONF_TYPE, TEMP_CELSIUS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, PLATFORM_SCHEMA, XBeeAnalogIn, XBeeAnalogInConfig, XBeeConfig
|
||||
|
||||
|
@ -25,14 +30,19 @@ 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 XBee Zigbee platform.
|
||||
|
||||
Uses the 'type' config value to work out which type of Zigbee sensor we're
|
||||
dealing with and instantiates the relevant classes to handle it.
|
||||
"""
|
||||
zigbee_device = hass.data[DOMAIN]
|
||||
typ = config.get(CONF_TYPE)
|
||||
typ = config[CONF_TYPE]
|
||||
|
||||
try:
|
||||
sensor_class, config_class = TYPE_CLASSES[typ]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Support for Zabbix sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -6,7 +8,10 @@ import voluptuous as vol
|
|||
from homeassistant.components import zabbix
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
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__)
|
||||
|
||||
|
@ -30,13 +35,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 Zabbix sensor platform."""
|
||||
sensors = []
|
||||
sensors: list[ZabbixTriggerCountSensor] = []
|
||||
|
||||
if not (zapi := hass.data[zabbix.DOMAIN]):
|
||||
_LOGGER.error("Zabbix integration hasn't been loaded? zapi is None")
|
||||
return False
|
||||
return
|
||||
|
||||
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
|
||||
|
||||
|
@ -51,27 +61,27 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
if not hostids:
|
||||
# We need hostids
|
||||
_LOGGER.error("If using 'individual', must specify hostids")
|
||||
return False
|
||||
return
|
||||
|
||||
for hostid in hostids:
|
||||
_LOGGER.debug("Creating Zabbix Sensor: %s", str(hostid))
|
||||
sensor = ZabbixSingleHostTriggerCountSensor(zapi, [hostid], name)
|
||||
sensors.append(sensor)
|
||||
sensors.append(ZabbixSingleHostTriggerCountSensor(zapi, [hostid], name))
|
||||
else:
|
||||
if not hostids:
|
||||
# Single sensor that provides the total count of triggers.
|
||||
_LOGGER.debug("Creating Zabbix Sensor")
|
||||
sensor = ZabbixTriggerCountSensor(zapi, name)
|
||||
sensors.append(ZabbixTriggerCountSensor(zapi, name))
|
||||
else:
|
||||
# Single sensor that sums total issues for all hosts
|
||||
_LOGGER.debug("Creating Zabbix Sensor group: %s", str(hostids))
|
||||
sensor = ZabbixMultipleHostTriggerCountSensor(zapi, hostids, name)
|
||||
sensors.append(sensor)
|
||||
sensors.append(
|
||||
ZabbixMultipleHostTriggerCountSensor(zapi, hostids, name)
|
||||
)
|
||||
|
||||
else:
|
||||
# Single sensor that provides the total count of triggers.
|
||||
_LOGGER.debug("Creating Zabbix Sensor")
|
||||
sensor = ZabbixTriggerCountSensor(zapi)
|
||||
sensors.append(sensor)
|
||||
sensors.append(ZabbixTriggerCountSensor(zapi))
|
||||
|
||||
add_entities(sensors)
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Support for interface with a Ziggo Mediabox XL."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
|
@ -22,7 +24,10 @@ from homeassistant.const import (
|
|||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
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__)
|
||||
|
||||
|
@ -43,18 +48,22 @@ 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 Ziggo Mediabox XL platform."""
|
||||
|
||||
hass.data[DATA_KNOWN_DEVICES] = known_devices = set()
|
||||
|
||||
# Is this a manual configuration?
|
||||
if config.get(CONF_HOST) is not None:
|
||||
host = config.get(CONF_HOST)
|
||||
if (host := config.get(CONF_HOST)) is not None:
|
||||
name = config.get(CONF_NAME)
|
||||
manual_config = True
|
||||
elif discovery_info is not None:
|
||||
host = discovery_info.get("host")
|
||||
host = discovery_info["host"]
|
||||
name = discovery_info.get("name")
|
||||
manual_config = False
|
||||
else:
|
||||
|
|
|
@ -12,7 +12,10 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN as ZONEMINDER_DOMAIN
|
||||
|
||||
|
@ -59,12 +62,17 @@ 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 ZoneMinder sensor platform."""
|
||||
include_archived = config[CONF_INCLUDE_ARCHIVED]
|
||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
sensors = []
|
||||
sensors: list[SensorEntity] = []
|
||||
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
|
||||
if not (monitors := zm_client.get_monitors()):
|
||||
_LOGGER.warning("Could not fetch any monitors from ZoneMinder")
|
||||
|
|
Loading…
Add table
Reference in a new issue