From 2709db008c5ead83b6a9c76ea5a3e9cd1eaf629e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 4 Jan 2022 11:08:28 +0100 Subject: [PATCH] Remove invalid return values in setup methods [a-h] (#63362) Co-authored-by: epenet --- homeassistant/components/arest/binary_sensor.py | 16 +++++++++++++--- homeassistant/components/arest/sensor.py | 16 +++++++++++++--- homeassistant/components/arwn/sensor.py | 14 +++++++++++--- homeassistant/components/bbox/sensor.py | 12 ++++++++++-- homeassistant/components/bh1750/sensor.py | 14 ++++++++++++-- homeassistant/components/blockchain/sensor.py | 14 ++++++++++++-- .../components/concord232/binary_sensor.py | 14 ++++++++++++-- .../components/currencylayer/sensor.py | 14 ++++++++++++-- homeassistant/components/decora_wifi/light.py | 13 +++++++++++-- homeassistant/components/dht/sensor.py | 12 ++++++++++-- .../components/digital_ocean/binary_sensor.py | 16 +++++++++++++--- .../components/digital_ocean/switch.py | 16 +++++++++++++--- homeassistant/components/eliqonline/sensor.py | 14 ++++++++++++-- homeassistant/components/emoncms/sensor.py | 14 ++++++++++++-- homeassistant/components/envirophat/sensor.py | 12 ++++++++++-- .../components/frontier_silicon/media_player.py | 17 ++++++++++++----- .../components/geofency/device_tracker.py | 12 ++++++++---- homeassistant/components/gpsd/sensor.py | 14 ++++++++++++-- homeassistant/components/hikvisioncam/switch.py | 16 +++++++++++++--- .../components/history_stats/sensor.py | 15 +++++++++++---- homeassistant/components/htu21d/sensor.py | 12 ++++++++++-- 21 files changed, 242 insertions(+), 55 deletions(-) diff --git a/homeassistant/components/arest/binary_sensor.py b/homeassistant/components/arest/binary_sensor.py index 1280e013f8d..92309f5620f 100644 --- a/homeassistant/components/arest/binary_sensor.py +++ b/homeassistant/components/arest/binary_sensor.py @@ -1,4 +1,6 @@ """Support for an exposed aREST RESTful API of a device.""" +from __future__ import annotations + from datetime import timedelta from http import HTTPStatus import logging @@ -12,7 +14,10 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME, CONF_PIN, CONF_RESOURCE +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 homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -29,7 +34,12 @@ 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 aREST binary sensor.""" resource = config[CONF_RESOURCE] pin = config[CONF_PIN] @@ -41,10 +51,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.error( "Missing resource or schema in configuration. Add http:// to your URL" ) - return False + return except requests.exceptions.ConnectionError: _LOGGER.error("No route to device at %s", resource) - return False + return arest = ArestData(resource, pin) diff --git a/homeassistant/components/arest/sensor.py b/homeassistant/components/arest/sensor.py index 7ca6d230a08..e4d3fff8c74 100644 --- a/homeassistant/components/arest/sensor.py +++ b/homeassistant/components/arest/sensor.py @@ -1,4 +1,6 @@ """Support for an exposed aREST RESTful API of a device.""" +from __future__ import annotations + from datetime import timedelta from http import HTTPStatus import logging @@ -14,8 +16,11 @@ from homeassistant.const import ( CONF_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, ) +from homeassistant.core import HomeAssistant from homeassistant.exceptions import TemplateError 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 _LOGGER = logging.getLogger(__name__) @@ -49,7 +54,12 @@ 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 aREST sensor.""" resource = config[CONF_RESOURCE] var_conf = config[CONF_MONITORED_VARIABLES] @@ -61,10 +71,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.error( "Missing resource or schema in configuration. Add http:// to your URL" ) - return False + return except requests.exceptions.ConnectionError: _LOGGER.error("No route to device at %s", resource) - return False + return arest = ArestData(resource) diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 4f06ac169ad..45db805d1de 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -1,4 +1,6 @@ """Support for collecting data from the ARWN project.""" +from __future__ import annotations + import json import logging @@ -10,7 +12,9 @@ from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT, ) -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import slugify _LOGGER = logging.getLogger(__name__) @@ -72,7 +76,12 @@ def _slug(name): return f"sensor.arwn_{slugify(name)}" -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the ARWN platform.""" @callback @@ -121,7 +130,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= store[sensor.name].set_event(event) await mqtt.async_subscribe(hass, TOPIC, async_sensor_event_received, 0) - return True class ArwnSensor(SensorEntity): diff --git a/homeassistant/components/bbox/sensor.py b/homeassistant/components/bbox/sensor.py index 5ab897de797..b85c75569d4 100644 --- a/homeassistant/components/bbox/sensor.py +++ b/homeassistant/components/bbox/sensor.py @@ -20,7 +20,10 @@ from homeassistant.const import ( CONF_NAME, DATA_RATE_MEGABITS_PER_SECOND, ) +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 homeassistant.util import Throttle from homeassistant.util.dt import utcnow @@ -86,7 +89,12 @@ 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 Bbox sensor.""" # Create a data fetcher to support all of the configured sensors. Then make # the first call to init the data. @@ -95,7 +103,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): bbox_data.update() except requests.exceptions.HTTPError as error: _LOGGER.error(error) - return False + return name = config[CONF_NAME] diff --git a/homeassistant/components/bh1750/sensor.py b/homeassistant/components/bh1750/sensor.py index a25a645d47f..d6239f90d43 100644 --- a/homeassistant/components/bh1750/sensor.py +++ b/homeassistant/components/bh1750/sensor.py @@ -1,4 +1,6 @@ """Support for BH1750 light sensor.""" +from __future__ import annotations + from functools import partial import logging @@ -12,7 +14,10 @@ from homeassistant.components.sensor import ( SensorEntity, ) from homeassistant.const import CONF_NAME, LIGHT_LUX +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__) @@ -62,7 +67,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the BH1750 sensor.""" _LOGGER.warning( "The BH1750 integration is deprecated and will be removed " @@ -91,7 +101,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) if not sensor.sample_ok: _LOGGER.error("BH1750 sensor not detected at %s", i2c_address) - return False + return dev = [BH1750Sensor(sensor, name, LIGHT_LUX, config[CONF_MULTIPLIER])] _LOGGER.info( diff --git a/homeassistant/components/blockchain/sensor.py b/homeassistant/components/blockchain/sensor.py index 9d31d4c0583..92cd7a56e92 100644 --- a/homeassistant/components/blockchain/sensor.py +++ b/homeassistant/components/blockchain/sensor.py @@ -1,4 +1,6 @@ """Support for Blockchain.com sensors.""" +from __future__ import annotations + from datetime import timedelta import logging @@ -7,7 +9,10 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ATTR_ATTRIBUTION, 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__) @@ -29,7 +34,12 @@ 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 Blockchain.com sensors.""" addresses = config[CONF_ADDRESSES] @@ -38,7 +48,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): for address in addresses: if not validate_address(address): _LOGGER.error("Bitcoin address is not valid: %s", address) - return False + return add_entities([BlockchainSensor(name, addresses)], True) diff --git a/homeassistant/components/concord232/binary_sensor.py b/homeassistant/components/concord232/binary_sensor.py index fac16c834d9..dc5f89d84bb 100644 --- a/homeassistant/components/concord232/binary_sensor.py +++ b/homeassistant/components/concord232/binary_sensor.py @@ -1,4 +1,6 @@ """Support for exposing Concord232 elements as sensors.""" +from __future__ import annotations + import datetime import logging @@ -13,7 +15,10 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.const import CONF_HOST, CONF_PORT +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 import homeassistant.util.dt as dt_util _LOGGER = logging.getLogger(__name__) @@ -42,7 +47,12 @@ 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 Concord232 binary sensor platform.""" host = config[CONF_HOST] @@ -59,7 +69,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): except requests.exceptions.ConnectionError as ex: _LOGGER.error("Unable to connect to Concord232: %s", str(ex)) - return False + return # The order of zones returned by client.list_zones() can vary. # When the zones are not named, this can result in the same entity diff --git a/homeassistant/components/currencylayer/sensor.py b/homeassistant/components/currencylayer/sensor.py index 2f0461cc8c4..9c43b5f0bc1 100644 --- a/homeassistant/components/currencylayer/sensor.py +++ b/homeassistant/components/currencylayer/sensor.py @@ -1,4 +1,6 @@ """Support for currencylayer.com exchange rates service.""" +from __future__ import annotations + from datetime import timedelta import logging @@ -13,7 +15,10 @@ from homeassistant.const import ( CONF_NAME, CONF_QUOTE, ) +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__) _RESOURCE = "http://apilayer.net/api/live" @@ -37,7 +42,12 @@ 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 Currencylayer sensor.""" base = config[CONF_BASE] api_key = config[CONF_API_KEY] @@ -50,7 +60,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): for variable in config[CONF_QUOTE]: sensors.append(CurrencylayerSensor(rest, base, variable)) if "error" in response.json(): - return False + return add_entities(sensors, True) diff --git a/homeassistant/components/decora_wifi/light.py b/homeassistant/components/decora_wifi/light.py index 93693b3d52a..3d3eea1f5b9 100644 --- a/homeassistant/components/decora_wifi/light.py +++ b/homeassistant/components/decora_wifi/light.py @@ -1,4 +1,5 @@ """Interfaces with the myLeviton API for Decora Smart WiFi products.""" +from __future__ import annotations import logging @@ -18,7 +19,10 @@ from homeassistant.components.light import ( LightEntity, ) from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP +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__) @@ -31,7 +35,12 @@ NOTIFICATION_ID = "leviton_notification" NOTIFICATION_TITLE = "myLeviton Decora Setup" -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 Decora WiFi platform.""" email = config[CONF_USERNAME] @@ -48,7 +57,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): hass.components.persistent_notification.create( msg, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID ) - return False + return # Gather all the available devices... perms = session.user.get_residential_permissions() diff --git a/homeassistant/components/dht/sensor.py b/homeassistant/components/dht/sensor.py index 27bf7baefc2..ef5cc0f97f3 100644 --- a/homeassistant/components/dht/sensor.py +++ b/homeassistant/components/dht/sensor.py @@ -22,7 +22,10 @@ from homeassistant.const import ( PERCENTAGE, TEMP_CELSIUS, ) +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 homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -85,7 +88,12 @@ 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 DHT sensor.""" _LOGGER.warning( "The DHT Sensor integration is deprecated and will be removed " @@ -107,7 +115,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if not sensor: _LOGGER.error("DHT sensor type is not supported") - return False + return data = DHTClient(sensor, pin, name) diff --git a/homeassistant/components/digital_ocean/binary_sensor.py b/homeassistant/components/digital_ocean/binary_sensor.py index f2222a03d73..b92e009e618 100644 --- a/homeassistant/components/digital_ocean/binary_sensor.py +++ b/homeassistant/components/digital_ocean/binary_sensor.py @@ -1,4 +1,6 @@ """Support for monitoring the state of Digital Ocean droplets.""" +from __future__ import annotations + import logging import voluptuous as vol @@ -9,7 +11,10 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.const import ATTR_ATTRIBUTION +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 ( ATTR_CREATED_AT, @@ -34,10 +39,15 @@ 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 Digital Ocean droplet sensor.""" if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): - return False + return droplets = config[CONF_DROPLETS] @@ -45,7 +55,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): for droplet in droplets: if (droplet_id := digital.get_droplet_id(droplet)) is None: _LOGGER.error("Droplet %s is not available", droplet) - return False + return dev.append(DigitalOceanBinarySensor(digital, droplet_id)) add_entities(dev, True) diff --git a/homeassistant/components/digital_ocean/switch.py b/homeassistant/components/digital_ocean/switch.py index 3ba60c4c457..efaa4fec6be 100644 --- a/homeassistant/components/digital_ocean/switch.py +++ b/homeassistant/components/digital_ocean/switch.py @@ -1,11 +1,16 @@ """Support for interacting with Digital Ocean droplets.""" +from __future__ import annotations + import logging import voluptuous as vol from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import ATTR_ATTRIBUTION +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 ( ATTR_CREATED_AT, @@ -31,10 +36,15 @@ 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 Digital Ocean droplet switch.""" if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): - return False + return droplets = config[CONF_DROPLETS] @@ -42,7 +52,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): for droplet in droplets: if (droplet_id := digital.get_droplet_id(droplet)) is None: _LOGGER.error("Droplet %s is not available", droplet) - return False + return dev.append(DigitalOceanSwitch(digital, droplet_id)) add_entities(dev, True) diff --git a/homeassistant/components/eliqonline/sensor.py b/homeassistant/components/eliqonline/sensor.py index 0ddb123d5f8..ba4d32fbbd8 100644 --- a/homeassistant/components/eliqonline/sensor.py +++ b/homeassistant/components/eliqonline/sensor.py @@ -1,4 +1,6 @@ """Monitors home energy use for the ELIQ Online service.""" +from __future__ import annotations + import asyncio from datetime import timedelta import logging @@ -12,8 +14,11 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.const import CONF_ACCESS_TOKEN, CONF_NAME, POWER_WATT +from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession 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__) @@ -36,7 +41,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the ELIQ Online sensor.""" access_token = config.get(CONF_ACCESS_TOKEN) name = config.get(CONF_NAME, DEFAULT_NAME) @@ -50,7 +60,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= await api.get_data_now(channelid=channel_id) except OSError as error: _LOGGER.error("Could not access the ELIQ Online API: %s", error) - return False + return async_add_entities([EliqSensor(api, channel_id, name)], True) diff --git a/homeassistant/components/emoncms/sensor.py b/homeassistant/components/emoncms/sensor.py index 2db0f0373c9..8879743446e 100644 --- a/homeassistant/components/emoncms/sensor.py +++ b/homeassistant/components/emoncms/sensor.py @@ -1,4 +1,6 @@ """Support for monitoring emoncms feeds.""" +from __future__ import annotations + from datetime import timedelta from http import HTTPStatus import logging @@ -22,8 +24,11 @@ from homeassistant.const import ( POWER_WATT, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import template 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 _LOGGER = logging.getLogger(__name__) @@ -71,7 +76,12 @@ def get_id(sensorid, feedtag, feedname, feedid, feeduserid): return f"emoncms{sensorid}_{feedtag}_{feedname}_{feedid}_{feeduserid}" -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 Emoncms sensor.""" apikey = config.get(CONF_API_KEY) url = config.get(CONF_URL) @@ -91,7 +101,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): data.update() if data.data is None: - return False + return sensors = [] diff --git a/homeassistant/components/envirophat/sensor.py b/homeassistant/components/envirophat/sensor.py index ac51d7310ca..8c37a11123c 100644 --- a/homeassistant/components/envirophat/sensor.py +++ b/homeassistant/components/envirophat/sensor.py @@ -20,7 +20,10 @@ from homeassistant.const import ( PRESSURE_HPA, TEMP_CELSIUS, ) +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 homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -133,13 +136,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 Sense HAT sensor platform.""" try: envirophat = importlib.import_module("envirophat") except OSError: _LOGGER.error("No Enviro pHAT was found") - return False + return data = EnvirophatData(envirophat, config.get(CONF_USE_LEDS)) diff --git a/homeassistant/components/frontier_silicon/media_player.py b/homeassistant/components/frontier_silicon/media_player.py index bc9f0f35b57..a7829e23c57 100644 --- a/homeassistant/components/frontier_silicon/media_player.py +++ b/homeassistant/components/frontier_silicon/media_player.py @@ -1,4 +1,6 @@ """Support for Frontier Silicon Devices (Medion, Hama, Auna,...).""" +from __future__ import annotations + import logging from afsapi import AFSAPI @@ -33,7 +35,10 @@ from homeassistant.const import ( STATE_PLAYING, STATE_UNKNOWN, ) +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__) @@ -66,14 +71,19 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the Frontier Silicon platform.""" if discovery_info is not None: async_add_entities( [AFSAPIDevice(discovery_info["ssdp_description"], DEFAULT_PASSWORD, None)], True, ) - return True + return host = config.get(CONF_HOST) port = config.get(CONF_PORT) @@ -85,14 +95,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= [AFSAPIDevice(f"http://{host}:{port}/device", password, name)], True ) _LOGGER.debug("FSAPI device %s:%s -> %s", host, port, password) - return True except requests.exceptions.RequestException: _LOGGER.error( "Could not add the FSAPI device at %s:%s -> %s", host, port, password ) - return False - class AFSAPIDevice(MediaPlayerEntity): """Representation of a Frontier Silicon device on the network.""" diff --git a/homeassistant/components/geofency/device_tracker.py b/homeassistant/components/geofency/device_tracker.py index 2904d1a1b1d..c92b2905be2 100644 --- a/homeassistant/components/geofency/device_tracker.py +++ b/homeassistant/components/geofency/device_tracker.py @@ -1,17 +1,23 @@ """Support for the Geofency device tracker platform.""" from homeassistant.components.device_tracker import SOURCE_TYPE_GPS from homeassistant.components.device_tracker.config_entry import TrackerEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo +from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity from . import DOMAIN as GF_DOMAIN, TRACKER_UPDATE -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 Geofency config entry.""" @callback @@ -41,8 +47,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): hass.data[GF_DOMAIN]["devices"].update(dev_ids) async_add_entities(GeofencyEntity(dev_id) for dev_id in dev_ids) - return True - class GeofencyEntity(TrackerEntity, RestoreEntity): """Represent a tracked device.""" diff --git a/homeassistant/components/gpsd/sensor.py b/homeassistant/components/gpsd/sensor.py index 1b502827996..28ca9d3f075 100644 --- a/homeassistant/components/gpsd/sensor.py +++ b/homeassistant/components/gpsd/sensor.py @@ -1,4 +1,6 @@ """Support for GPSD.""" +from __future__ import annotations + import logging import socket @@ -14,7 +16,10 @@ from homeassistant.const import ( CONF_NAME, CONF_PORT, ) +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__) @@ -36,7 +41,12 @@ 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 GPSD component.""" name = config.get(CONF_NAME) host = config.get(CONF_HOST) @@ -59,7 +69,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.debug("Connection to GPSD possible") except OSError: _LOGGER.error("Not able to connect to GPSD") - return False + return add_entities([GpsdSensor(hass, name, host, port)]) diff --git a/homeassistant/components/hikvisioncam/switch.py b/homeassistant/components/hikvisioncam/switch.py index aa4a430e72e..d6be7067e8a 100644 --- a/homeassistant/components/hikvisioncam/switch.py +++ b/homeassistant/components/hikvisioncam/switch.py @@ -1,4 +1,6 @@ """Support turning on/off motion detection on Hikvision cameras.""" +from __future__ import annotations + import logging import hikvision.api @@ -15,7 +17,10 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, ) +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 # This is the last working version, please test before updating @@ -37,7 +42,12 @@ 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 Hikvision camera.""" host = config.get(CONF_HOST) port = config.get(CONF_PORT) @@ -51,10 +61,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ) except MissingParamError as param_err: _LOGGING.error("Missing required param: %s", param_err) - return False + return except HikvisionError as conn_err: _LOGGING.error("Unable to connect: %s", conn_err) - return False + return add_entities([HikvisionMotionSwitch(name, hikvision_cam)]) diff --git a/homeassistant/components/history_stats/sensor.py b/homeassistant/components/history_stats/sensor.py index 0db311b0354..2af3706e4e8 100644 --- a/homeassistant/components/history_stats/sensor.py +++ b/homeassistant/components/history_stats/sensor.py @@ -1,4 +1,6 @@ """Component to make instant statistics about your history.""" +from __future__ import annotations + import datetime import logging import math @@ -16,11 +18,13 @@ from homeassistant.const import ( PERCENTAGE, TIME_HOURS, ) -from homeassistant.core import CoreState, callback +from homeassistant.core import CoreState, HomeAssistant, callback from homeassistant.exceptions import TemplateError import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.reload import async_setup_reload_service +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType import homeassistant.util.dt as dt_util from . import DOMAIN, PLATFORMS @@ -74,7 +78,12 @@ PLATFORM_SCHEMA = vol.All( # noinspection PyUnusedLocal -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the History Stats sensor.""" await async_setup_reload_service(hass, DOMAIN, PLATFORMS) @@ -98,8 +107,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ] ) - return True - class HistoryStatsSensor(SensorEntity): """Representation of a HistoryStats sensor.""" diff --git a/homeassistant/components/htu21d/sensor.py b/homeassistant/components/htu21d/sensor.py index 2385521a795..e0f7e6d6fbc 100644 --- a/homeassistant/components/htu21d/sensor.py +++ b/homeassistant/components/htu21d/sensor.py @@ -16,7 +16,10 @@ from homeassistant.components.sensor import ( SensorEntityDescription, ) from homeassistant.const import CONF_NAME, PERCENTAGE, TEMP_CELSIUS +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 homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) @@ -52,7 +55,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): +async def async_setup_platform( + hass: HomeAssistant, + config: ConfigType, + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType | None = None, +) -> None: """Set up the HTU21D sensor.""" _LOGGER.warning( "The HTU21D(F) Sensor integration is deprecated and will be removed " @@ -68,7 +76,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= sensor = await hass.async_add_executor_job(partial(HTU21D, bus, logger=_LOGGER)) if not sensor.sample_ok: _LOGGER.error("HTU21D sensor not detected in bus %s", bus_number) - return False + return sensor_handler = await hass.async_add_executor_job(HTU21DHandler, sensor)