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."""
|
"""Support for XBee Zigbee sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -7,6 +9,9 @@ from xbee_helper.exceptions import ZigBeeException, ZigBeeTxFailure
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.const import CONF_TYPE, TEMP_CELSIUS
|
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
|
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.
|
"""Set up the XBee Zigbee platform.
|
||||||
|
|
||||||
Uses the 'type' config value to work out which type of Zigbee sensor we're
|
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.
|
dealing with and instantiates the relevant classes to handle it.
|
||||||
"""
|
"""
|
||||||
zigbee_device = hass.data[DOMAIN]
|
zigbee_device = hass.data[DOMAIN]
|
||||||
typ = config.get(CONF_TYPE)
|
typ = config[CONF_TYPE]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sensor_class, config_class = TYPE_CLASSES[typ]
|
sensor_class, config_class = TYPE_CLASSES[typ]
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for Zabbix sensors."""
|
"""Support for Zabbix sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -6,7 +8,10 @@ import voluptuous as vol
|
||||||
from homeassistant.components import zabbix
|
from homeassistant.components import zabbix
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_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__)
|
||||||
|
|
||||||
|
@ -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."""
|
"""Set up the Zabbix sensor platform."""
|
||||||
sensors = []
|
sensors: list[ZabbixTriggerCountSensor] = []
|
||||||
|
|
||||||
if not (zapi := hass.data[zabbix.DOMAIN]):
|
if not (zapi := hass.data[zabbix.DOMAIN]):
|
||||||
_LOGGER.error("Zabbix integration hasn't been loaded? zapi is None")
|
_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())
|
_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:
|
if not hostids:
|
||||||
# We need hostids
|
# We need hostids
|
||||||
_LOGGER.error("If using 'individual', must specify hostids")
|
_LOGGER.error("If using 'individual', must specify hostids")
|
||||||
return False
|
return
|
||||||
|
|
||||||
for hostid in hostids:
|
for hostid in hostids:
|
||||||
_LOGGER.debug("Creating Zabbix Sensor: %s", str(hostid))
|
_LOGGER.debug("Creating Zabbix Sensor: %s", str(hostid))
|
||||||
sensor = ZabbixSingleHostTriggerCountSensor(zapi, [hostid], name)
|
sensors.append(ZabbixSingleHostTriggerCountSensor(zapi, [hostid], name))
|
||||||
sensors.append(sensor)
|
|
||||||
else:
|
else:
|
||||||
if not hostids:
|
if not hostids:
|
||||||
# Single sensor that provides the total count of triggers.
|
# Single sensor that provides the total count of triggers.
|
||||||
_LOGGER.debug("Creating Zabbix Sensor")
|
_LOGGER.debug("Creating Zabbix Sensor")
|
||||||
sensor = ZabbixTriggerCountSensor(zapi, name)
|
sensors.append(ZabbixTriggerCountSensor(zapi, name))
|
||||||
else:
|
else:
|
||||||
# Single sensor that sums total issues for all hosts
|
# Single sensor that sums total issues for all hosts
|
||||||
_LOGGER.debug("Creating Zabbix Sensor group: %s", str(hostids))
|
_LOGGER.debug("Creating Zabbix Sensor group: %s", str(hostids))
|
||||||
sensor = ZabbixMultipleHostTriggerCountSensor(zapi, hostids, name)
|
sensors.append(
|
||||||
sensors.append(sensor)
|
ZabbixMultipleHostTriggerCountSensor(zapi, hostids, name)
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Single sensor that provides the total count of triggers.
|
# Single sensor that provides the total count of triggers.
|
||||||
_LOGGER.debug("Creating Zabbix Sensor")
|
_LOGGER.debug("Creating Zabbix Sensor")
|
||||||
sensor = ZabbixTriggerCountSensor(zapi)
|
sensors.append(ZabbixTriggerCountSensor(zapi))
|
||||||
sensors.append(sensor)
|
|
||||||
|
|
||||||
add_entities(sensors)
|
add_entities(sensors)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for interface with a Ziggo Mediabox XL."""
|
"""Support for interface with a Ziggo Mediabox XL."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
@ -22,7 +24,10 @@ from homeassistant.const import (
|
||||||
STATE_PAUSED,
|
STATE_PAUSED,
|
||||||
STATE_PLAYING,
|
STATE_PLAYING,
|
||||||
)
|
)
|
||||||
|
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__)
|
||||||
|
|
||||||
|
@ -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."""
|
"""Set up the Ziggo Mediabox XL platform."""
|
||||||
|
|
||||||
hass.data[DATA_KNOWN_DEVICES] = known_devices = set()
|
hass.data[DATA_KNOWN_DEVICES] = known_devices = set()
|
||||||
|
|
||||||
# Is this a manual configuration?
|
# Is this a manual configuration?
|
||||||
if config.get(CONF_HOST) is not None:
|
if (host := config.get(CONF_HOST)) is not None:
|
||||||
host = config.get(CONF_HOST)
|
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
manual_config = True
|
manual_config = True
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
host = discovery_info.get("host")
|
host = discovery_info["host"]
|
||||||
name = discovery_info.get("name")
|
name = discovery_info.get("name")
|
||||||
manual_config = False
|
manual_config = False
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -12,7 +12,10 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||||
|
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 DOMAIN as ZONEMINDER_DOMAIN
|
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."""
|
"""Set up the ZoneMinder sensor platform."""
|
||||||
include_archived = config[CONF_INCLUDE_ARCHIVED]
|
include_archived = config[CONF_INCLUDE_ARCHIVED]
|
||||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||||
|
|
||||||
sensors = []
|
sensors: list[SensorEntity] = []
|
||||||
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
|
for zm_client in hass.data[ZONEMINDER_DOMAIN].values():
|
||||||
if not (monitors := zm_client.get_monitors()):
|
if not (monitors := zm_client.get_monitors()):
|
||||||
_LOGGER.warning("Could not fetch any monitors from ZoneMinder")
|
_LOGGER.warning("Could not fetch any monitors from ZoneMinder")
|
||||||
|
|
Loading…
Add table
Reference in a new issue