From ec1b45c922f710874c74cda257cefc47133c46c6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 12 Jan 2022 12:53:50 +0100 Subject: [PATCH] Add setup type hints (part 3) (#63961) * Drop return value from vesync * Add setup type hints to netgear_lte * Drop return value from hyperion * Add setup type hints to opentherm_gw Co-authored-by: epenet --- homeassistant/components/hyperion/light.py | 3 +-- homeassistant/components/hyperion/switch.py | 3 +-- homeassistant/components/netgear_lte/sensor.py | 14 ++++++++++++-- .../components/opentherm_gw/binary_sensor.py | 10 ++++++++-- homeassistant/components/opentherm_gw/const.py | 6 ++++-- homeassistant/components/opentherm_gw/sensor.py | 10 ++++++++-- homeassistant/components/vesync/sensor.py | 11 ++++++++--- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/hyperion/light.py b/homeassistant/components/hyperion/light.py index 0c0070d0c23..753e41018d9 100644 --- a/homeassistant/components/hyperion/light.py +++ b/homeassistant/components/hyperion/light.py @@ -85,7 +85,7 @@ async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, -) -> bool: +) -> None: """Set up a Hyperion platform from config entry.""" entry_data = hass.data[DOMAIN][config_entry.entry_id] @@ -122,7 +122,6 @@ async def async_setup_entry( ) listen_for_instance_updates(hass, config_entry, instance_add, instance_remove) - return True class HyperionBaseLight(LightEntity): diff --git a/homeassistant/components/hyperion/switch.py b/homeassistant/components/hyperion/switch.py index 6cc90af3c4d..ac853a32909 100644 --- a/homeassistant/components/hyperion/switch.py +++ b/homeassistant/components/hyperion/switch.py @@ -86,7 +86,7 @@ async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, -) -> bool: +) -> None: """Set up a Hyperion platform from config entry.""" entry_data = hass.data[DOMAIN][config_entry.entry_id] server_id = config_entry.unique_id @@ -121,7 +121,6 @@ async def async_setup_entry( ) listen_for_instance_updates(hass, config_entry, instance_add, instance_remove) - return True class HyperionComponentSwitch(SwitchEntity): diff --git a/homeassistant/components/netgear_lte/sensor.py b/homeassistant/components/netgear_lte/sensor.py index 8950a9b1663..de607f2a3c0 100644 --- a/homeassistant/components/netgear_lte/sensor.py +++ b/homeassistant/components/netgear_lte/sensor.py @@ -1,12 +1,22 @@ """Support for Netgear LTE sensors.""" +from __future__ import annotations + from homeassistant.components.sensor import SensorEntity +from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady +from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from . import CONF_MONITORED_CONDITIONS, CONF_SENSOR, DATA_KEY, LTEEntity from .sensor_types import SENSOR_SMS, SENSOR_SMS_TOTAL, SENSOR_UNITS, SENSOR_USAGE -async def async_setup_platform(hass, config, async_add_entities, discovery_info): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up Netgear LTE sensor devices.""" if discovery_info is None: return @@ -19,7 +29,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info) sensor_conf = discovery_info[CONF_SENSOR] monitored_conditions = sensor_conf[CONF_MONITORED_CONDITIONS] - sensors = [] + sensors: list[SensorEntity] = [] for sensor_type in monitored_conditions: if sensor_type == SENSOR_SMS: sensors.append(SMSUnreadSensor(modem_data, sensor_type)) diff --git a/homeassistant/components/opentherm_gw/binary_sensor.py b/homeassistant/components/opentherm_gw/binary_sensor.py index 81160729c4b..f630cdf273b 100644 --- a/homeassistant/components/opentherm_gw/binary_sensor.py +++ b/homeassistant/components/opentherm_gw/binary_sensor.py @@ -3,10 +3,12 @@ import logging from pprint import pformat from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, async_generate_entity_id +from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_registry import async_get_registry from . import DOMAIN @@ -21,7 +23,11 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -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 OpenTherm Gateway binary sensors.""" sensors = [] deprecated_sensors = [] diff --git a/homeassistant/components/opentherm_gw/const.py b/homeassistant/components/opentherm_gw/const.py index 7ad97e865e3..a5042628529 100644 --- a/homeassistant/components/opentherm_gw/const.py +++ b/homeassistant/components/opentherm_gw/const.py @@ -1,4 +1,6 @@ """Constants for the opentherm_gw integration.""" +from __future__ import annotations + import pyotgw.vars as gw_vars from homeassistant.components.binary_sensor import BinarySensorDeviceClass @@ -49,7 +51,7 @@ TRANSLATE_SOURCE = { UNIT_KW = "kW" UNIT_L_MIN = f"L/{TIME_MINUTES}" -BINARY_SENSOR_INFO = { +BINARY_SENSOR_INFO: dict[str, list] = { # [device_class, friendly_name format, [status source, ...]] gw_vars.DATA_MASTER_CH_ENABLED: [ None, @@ -211,7 +213,7 @@ BINARY_SENSOR_INFO = { gw_vars.OTGW_OVRD_HB: [None, "Gateway Override High Byte {}", [gw_vars.OTGW]], } -SENSOR_INFO = { +SENSOR_INFO: dict[str, list] = { # [device_class, unit, friendly_name, [status source, ...]] gw_vars.DATA_CONTROL_SETPOINT: [ SensorDeviceClass.TEMPERATURE, diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index a29dd319176..9b2e6c45899 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -3,10 +3,12 @@ import logging from pprint import pformat from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, async_generate_entity_id +from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_registry import async_get_registry from . import DOMAIN @@ -21,7 +23,11 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -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 OpenTherm Gateway sensors.""" sensors = [] deprecated_sensors = [] diff --git a/homeassistant/components/vesync/sensor.py b/homeassistant/components/vesync/sensor.py index 4dd03e11d07..1ed851b1dd3 100644 --- a/homeassistant/components/vesync/sensor.py +++ b/homeassistant/components/vesync/sensor.py @@ -6,10 +6,12 @@ from homeassistant.components.sensor import ( SensorEntity, SensorStateClass, ) +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import EntityCategory +from homeassistant.helpers.entity_platform import AddEntitiesCallback from .common import VeSyncBaseEntity from .const import DOMAIN, VS_DISCOVERY, VS_DISPATCHERS, VS_SENSORS @@ -18,7 +20,11 @@ from .switch import DEV_TYPE_TO_HA _LOGGER = logging.getLogger(__name__) -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 switches.""" async def async_discover(devices): @@ -31,7 +37,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): hass.data[DOMAIN][VS_DISPATCHERS].append(disp) _async_setup_entities(hass.data[DOMAIN][VS_SENSORS], async_add_entities) - return True @callback