Remove invalid return values in setup methods [a-h] (#63362)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-04 11:08:28 +01:00 committed by GitHub
parent b14ac1b94a
commit 2709db008c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 242 additions and 55 deletions

View File

@ -1,4 +1,6 @@
"""Support for an exposed aREST RESTful API of a device.""" """Support for an exposed aREST RESTful API of a device."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
import logging import logging
@ -12,7 +14,10 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME, CONF_PIN, CONF_RESOURCE 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 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 import Throttle
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the aREST binary sensor."""
resource = config[CONF_RESOURCE] resource = config[CONF_RESOURCE]
pin = config[CONF_PIN] pin = config[CONF_PIN]
@ -41,10 +51,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.error( _LOGGER.error(
"Missing resource or schema in configuration. Add http:// to your URL" "Missing resource or schema in configuration. Add http:// to your URL"
) )
return False return
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
_LOGGER.error("No route to device at %s", resource) _LOGGER.error("No route to device at %s", resource)
return False return
arest = ArestData(resource, pin) arest = ArestData(resource, pin)

View File

@ -1,4 +1,6 @@
"""Support for an exposed aREST RESTful API of a device.""" """Support for an exposed aREST RESTful API of a device."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
import logging import logging
@ -14,8 +16,11 @@ from homeassistant.const import (
CONF_UNIT_OF_MEASUREMENT, CONF_UNIT_OF_MEASUREMENT,
CONF_VALUE_TEMPLATE, CONF_VALUE_TEMPLATE,
) )
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
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 homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the aREST sensor."""
resource = config[CONF_RESOURCE] resource = config[CONF_RESOURCE]
var_conf = config[CONF_MONITORED_VARIABLES] var_conf = config[CONF_MONITORED_VARIABLES]
@ -61,10 +71,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.error( _LOGGER.error(
"Missing resource or schema in configuration. Add http:// to your URL" "Missing resource or schema in configuration. Add http:// to your URL"
) )
return False return
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
_LOGGER.error("No route to device at %s", resource) _LOGGER.error("No route to device at %s", resource)
return False return
arest = ArestData(resource) arest = ArestData(resource)

View File

@ -1,4 +1,6 @@
"""Support for collecting data from the ARWN project.""" """Support for collecting data from the ARWN project."""
from __future__ import annotations
import json import json
import logging import logging
@ -10,7 +12,9 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, 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 from homeassistant.util import slugify
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -72,7 +76,12 @@ def _slug(name):
return f"sensor.arwn_{slugify(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.""" """Set up the ARWN platform."""
@callback @callback
@ -121,7 +130,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
store[sensor.name].set_event(event) store[sensor.name].set_event(event)
await mqtt.async_subscribe(hass, TOPIC, async_sensor_event_received, 0) await mqtt.async_subscribe(hass, TOPIC, async_sensor_event_received, 0)
return True
class ArwnSensor(SensorEntity): class ArwnSensor(SensorEntity):

View File

@ -20,7 +20,10 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
DATA_RATE_MEGABITS_PER_SECOND, DATA_RATE_MEGABITS_PER_SECOND,
) )
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 homeassistant.util import Throttle from homeassistant.util import Throttle
from homeassistant.util.dt import utcnow 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.""" """Set up the Bbox sensor."""
# Create a data fetcher to support all of the configured sensors. Then make # Create a data fetcher to support all of the configured sensors. Then make
# the first call to init the data. # the first call to init the data.
@ -95,7 +103,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
bbox_data.update() bbox_data.update()
except requests.exceptions.HTTPError as error: except requests.exceptions.HTTPError as error:
_LOGGER.error(error) _LOGGER.error(error)
return False return
name = config[CONF_NAME] name = config[CONF_NAME]

View File

@ -1,4 +1,6 @@
"""Support for BH1750 light sensor.""" """Support for BH1750 light sensor."""
from __future__ import annotations
from functools import partial from functools import partial
import logging import logging
@ -12,7 +14,10 @@ from homeassistant.components.sensor import (
SensorEntity, SensorEntity,
) )
from homeassistant.const import CONF_NAME, LIGHT_LUX from homeassistant.const import CONF_NAME, LIGHT_LUX
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__)
@ -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.""" """Set up the BH1750 sensor."""
_LOGGER.warning( _LOGGER.warning(
"The BH1750 integration is deprecated and will be removed " "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: if not sensor.sample_ok:
_LOGGER.error("BH1750 sensor not detected at %s", i2c_address) _LOGGER.error("BH1750 sensor not detected at %s", i2c_address)
return False return
dev = [BH1750Sensor(sensor, name, LIGHT_LUX, config[CONF_MULTIPLIER])] dev = [BH1750Sensor(sensor, name, LIGHT_LUX, config[CONF_MULTIPLIER])]
_LOGGER.info( _LOGGER.info(

View File

@ -1,4 +1,6 @@
"""Support for Blockchain.com sensors.""" """Support for Blockchain.com sensors."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -7,7 +9,10 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME from homeassistant.const import ATTR_ATTRIBUTION, 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__)
@ -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.""" """Set up the Blockchain.com sensors."""
addresses = config[CONF_ADDRESSES] addresses = config[CONF_ADDRESSES]
@ -38,7 +48,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for address in addresses: for address in addresses:
if not validate_address(address): if not validate_address(address):
_LOGGER.error("Bitcoin address is not valid: %s", address) _LOGGER.error("Bitcoin address is not valid: %s", address)
return False return
add_entities([BlockchainSensor(name, addresses)], True) add_entities([BlockchainSensor(name, addresses)], True)

View File

@ -1,4 +1,6 @@
"""Support for exposing Concord232 elements as sensors.""" """Support for exposing Concord232 elements as sensors."""
from __future__ import annotations
import datetime import datetime
import logging import logging
@ -13,7 +15,10 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.const import CONF_HOST, CONF_PORT
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
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the Concord232 binary sensor platform."""
host = config[CONF_HOST] host = config[CONF_HOST]
@ -59,7 +69,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
except requests.exceptions.ConnectionError as ex: except requests.exceptions.ConnectionError as ex:
_LOGGER.error("Unable to connect to Concord232: %s", str(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. # The order of zones returned by client.list_zones() can vary.
# When the zones are not named, this can result in the same entity # When the zones are not named, this can result in the same entity

View File

@ -1,4 +1,6 @@
"""Support for currencylayer.com exchange rates service.""" """Support for currencylayer.com exchange rates service."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -13,7 +15,10 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
CONF_QUOTE, CONF_QUOTE,
) )
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__)
_RESOURCE = "http://apilayer.net/api/live" _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.""" """Set up the Currencylayer sensor."""
base = config[CONF_BASE] base = config[CONF_BASE]
api_key = config[CONF_API_KEY] 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]: for variable in config[CONF_QUOTE]:
sensors.append(CurrencylayerSensor(rest, base, variable)) sensors.append(CurrencylayerSensor(rest, base, variable))
if "error" in response.json(): if "error" in response.json():
return False return
add_entities(sensors, True) add_entities(sensors, True)

View File

@ -1,4 +1,5 @@
"""Interfaces with the myLeviton API for Decora Smart WiFi products.""" """Interfaces with the myLeviton API for Decora Smart WiFi products."""
from __future__ import annotations
import logging import logging
@ -18,7 +19,10 @@ from homeassistant.components.light import (
LightEntity, LightEntity,
) )
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
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__)
@ -31,7 +35,12 @@ NOTIFICATION_ID = "leviton_notification"
NOTIFICATION_TITLE = "myLeviton Decora Setup" 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.""" """Set up the Decora WiFi platform."""
email = config[CONF_USERNAME] email = config[CONF_USERNAME]
@ -48,7 +57,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
hass.components.persistent_notification.create( hass.components.persistent_notification.create(
msg, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID msg, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID
) )
return False return
# Gather all the available devices... # Gather all the available devices...
perms = session.user.get_residential_permissions() perms = session.user.get_residential_permissions()

View File

@ -22,7 +22,10 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
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 homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the DHT sensor."""
_LOGGER.warning( _LOGGER.warning(
"The DHT Sensor integration is deprecated and will be removed " "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: if not sensor:
_LOGGER.error("DHT sensor type is not supported") _LOGGER.error("DHT sensor type is not supported")
return False return
data = DHTClient(sensor, pin, name) data = DHTClient(sensor, pin, name)

View File

@ -1,4 +1,6 @@
"""Support for monitoring the state of Digital Ocean droplets.""" """Support for monitoring the state of Digital Ocean droplets."""
from __future__ import annotations
import logging import logging
import voluptuous as vol import voluptuous as vol
@ -9,7 +11,10 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
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 (
ATTR_CREATED_AT, 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.""" """Set up the Digital Ocean droplet sensor."""
if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)):
return False return
droplets = config[CONF_DROPLETS] droplets = config[CONF_DROPLETS]
@ -45,7 +55,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for droplet in droplets: for droplet in droplets:
if (droplet_id := digital.get_droplet_id(droplet)) is None: if (droplet_id := digital.get_droplet_id(droplet)) is None:
_LOGGER.error("Droplet %s is not available", droplet) _LOGGER.error("Droplet %s is not available", droplet)
return False return
dev.append(DigitalOceanBinarySensor(digital, droplet_id)) dev.append(DigitalOceanBinarySensor(digital, droplet_id))
add_entities(dev, True) add_entities(dev, True)

View File

@ -1,11 +1,16 @@
"""Support for interacting with Digital Ocean droplets.""" """Support for interacting with Digital Ocean droplets."""
from __future__ import annotations
import logging import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
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 (
ATTR_CREATED_AT, 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.""" """Set up the Digital Ocean droplet switch."""
if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)): if not (digital := hass.data.get(DATA_DIGITAL_OCEAN)):
return False return
droplets = config[CONF_DROPLETS] droplets = config[CONF_DROPLETS]
@ -42,7 +52,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for droplet in droplets: for droplet in droplets:
if (droplet_id := digital.get_droplet_id(droplet)) is None: if (droplet_id := digital.get_droplet_id(droplet)) is None:
_LOGGER.error("Droplet %s is not available", droplet) _LOGGER.error("Droplet %s is not available", droplet)
return False return
dev.append(DigitalOceanSwitch(digital, droplet_id)) dev.append(DigitalOceanSwitch(digital, droplet_id))
add_entities(dev, True) add_entities(dev, True)

View File

@ -1,4 +1,6 @@
"""Monitors home energy use for the ELIQ Online service.""" """Monitors home energy use for the ELIQ Online service."""
from __future__ import annotations
import asyncio import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -12,8 +14,11 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_NAME, POWER_WATT 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 from homeassistant.helpers.aiohttp_client import async_get_clientsession
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__)
@ -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.""" """Set up the ELIQ Online sensor."""
access_token = config.get(CONF_ACCESS_TOKEN) access_token = config.get(CONF_ACCESS_TOKEN)
name = config.get(CONF_NAME, DEFAULT_NAME) 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) await api.get_data_now(channelid=channel_id)
except OSError as error: except OSError as error:
_LOGGER.error("Could not access the ELIQ Online API: %s", error) _LOGGER.error("Could not access the ELIQ Online API: %s", error)
return False return
async_add_entities([EliqSensor(api, channel_id, name)], True) async_add_entities([EliqSensor(api, channel_id, name)], True)

View File

@ -1,4 +1,6 @@
"""Support for monitoring emoncms feeds.""" """Support for monitoring emoncms feeds."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
import logging import logging
@ -22,8 +24,11 @@ from homeassistant.const import (
POWER_WATT, POWER_WATT,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.core import HomeAssistant
from homeassistant.helpers import template from homeassistant.helpers import template
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 homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -71,7 +76,12 @@ def get_id(sensorid, feedtag, feedname, feedid, feeduserid):
return f"emoncms{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.""" """Set up the Emoncms sensor."""
apikey = config.get(CONF_API_KEY) apikey = config.get(CONF_API_KEY)
url = config.get(CONF_URL) url = config.get(CONF_URL)
@ -91,7 +101,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
data.update() data.update()
if data.data is None: if data.data is None:
return False return
sensors = [] sensors = []

View File

@ -20,7 +20,10 @@ from homeassistant.const import (
PRESSURE_HPA, PRESSURE_HPA,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
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 homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the Sense HAT sensor platform."""
try: try:
envirophat = importlib.import_module("envirophat") envirophat = importlib.import_module("envirophat")
except OSError: except OSError:
_LOGGER.error("No Enviro pHAT was found") _LOGGER.error("No Enviro pHAT was found")
return False return
data = EnvirophatData(envirophat, config.get(CONF_USE_LEDS)) data = EnvirophatData(envirophat, config.get(CONF_USE_LEDS))

View File

@ -1,4 +1,6 @@
"""Support for Frontier Silicon Devices (Medion, Hama, Auna,...).""" """Support for Frontier Silicon Devices (Medion, Hama, Auna,...)."""
from __future__ import annotations
import logging import logging
from afsapi import AFSAPI from afsapi import AFSAPI
@ -33,7 +35,10 @@ from homeassistant.const import (
STATE_PLAYING, STATE_PLAYING,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
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__)
@ -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.""" """Set up the Frontier Silicon platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_entities( async_add_entities(
[AFSAPIDevice(discovery_info["ssdp_description"], DEFAULT_PASSWORD, None)], [AFSAPIDevice(discovery_info["ssdp_description"], DEFAULT_PASSWORD, None)],
True, True,
) )
return True return
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
port = config.get(CONF_PORT) 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 [AFSAPIDevice(f"http://{host}:{port}/device", password, name)], True
) )
_LOGGER.debug("FSAPI device %s:%s -> %s", host, port, password) _LOGGER.debug("FSAPI device %s:%s -> %s", host, port, password)
return True
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
_LOGGER.error( _LOGGER.error(
"Could not add the FSAPI device at %s:%s -> %s", host, port, password "Could not add the FSAPI device at %s:%s -> %s", host, port, password
) )
return False
class AFSAPIDevice(MediaPlayerEntity): class AFSAPIDevice(MediaPlayerEntity):
"""Representation of a Frontier Silicon device on the network.""" """Representation of a Frontier Silicon device on the network."""

View File

@ -1,17 +1,23 @@
"""Support for the Geofency device tracker platform.""" """Support for the Geofency device tracker platform."""
from homeassistant.components.device_tracker import SOURCE_TYPE_GPS from homeassistant.components.device_tracker import SOURCE_TYPE_GPS
from homeassistant.components.device_tracker.config_entry import TrackerEntity 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.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 import device_registry
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from . import DOMAIN as GF_DOMAIN, TRACKER_UPDATE 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.""" """Set up Geofency config entry."""
@callback @callback
@ -41,8 +47,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
hass.data[GF_DOMAIN]["devices"].update(dev_ids) hass.data[GF_DOMAIN]["devices"].update(dev_ids)
async_add_entities(GeofencyEntity(dev_id) for dev_id in dev_ids) async_add_entities(GeofencyEntity(dev_id) for dev_id in dev_ids)
return True
class GeofencyEntity(TrackerEntity, RestoreEntity): class GeofencyEntity(TrackerEntity, RestoreEntity):
"""Represent a tracked device.""" """Represent a tracked device."""

View File

@ -1,4 +1,6 @@
"""Support for GPSD.""" """Support for GPSD."""
from __future__ import annotations
import logging import logging
import socket import socket
@ -14,7 +16,10 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
CONF_PORT, CONF_PORT,
) )
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__)
@ -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.""" """Set up the GPSD component."""
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
host = config.get(CONF_HOST) 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") _LOGGER.debug("Connection to GPSD possible")
except OSError: except OSError:
_LOGGER.error("Not able to connect to GPSD") _LOGGER.error("Not able to connect to GPSD")
return False return
add_entities([GpsdSensor(hass, name, host, port)]) add_entities([GpsdSensor(hass, name, host, port)])

View File

@ -1,4 +1,6 @@
"""Support turning on/off motion detection on Hikvision cameras.""" """Support turning on/off motion detection on Hikvision cameras."""
from __future__ import annotations
import logging import logging
import hikvision.api import hikvision.api
@ -15,7 +17,10 @@ from homeassistant.const import (
STATE_OFF, STATE_OFF,
STATE_ON, STATE_ON,
) )
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
# This is the last working version, please test before updating # 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.""" """Set up Hikvision camera."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
port = config.get(CONF_PORT) port = config.get(CONF_PORT)
@ -51,10 +61,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
) )
except MissingParamError as param_err: except MissingParamError as param_err:
_LOGGING.error("Missing required param: %s", param_err) _LOGGING.error("Missing required param: %s", param_err)
return False return
except HikvisionError as conn_err: except HikvisionError as conn_err:
_LOGGING.error("Unable to connect: %s", conn_err) _LOGGING.error("Unable to connect: %s", conn_err)
return False return
add_entities([HikvisionMotionSwitch(name, hikvision_cam)]) add_entities([HikvisionMotionSwitch(name, hikvision_cam)])

View File

@ -1,4 +1,6 @@
"""Component to make instant statistics about your history.""" """Component to make instant statistics about your history."""
from __future__ import annotations
import datetime import datetime
import logging import logging
import math import math
@ -16,11 +18,13 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TIME_HOURS, TIME_HOURS,
) )
from homeassistant.core import CoreState, callback from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
import homeassistant.helpers.config_validation as cv 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.event import async_track_state_change_event
from homeassistant.helpers.reload import async_setup_reload_service from homeassistant.helpers.reload import async_setup_reload_service
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from . import DOMAIN, PLATFORMS from . import DOMAIN, PLATFORMS
@ -74,7 +78,12 @@ PLATFORM_SCHEMA = vol.All(
# noinspection PyUnusedLocal # 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.""" """Set up the History Stats sensor."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS) 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): class HistoryStatsSensor(SensorEntity):
"""Representation of a HistoryStats sensor.""" """Representation of a HistoryStats sensor."""

View File

@ -16,7 +16,10 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.const import CONF_NAME, PERCENTAGE, TEMP_CELSIUS from homeassistant.const import CONF_NAME, PERCENTAGE, TEMP_CELSIUS
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 homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _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.""" """Set up the HTU21D sensor."""
_LOGGER.warning( _LOGGER.warning(
"The HTU21D(F) Sensor integration is deprecated and will be removed " "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)) sensor = await hass.async_add_executor_job(partial(HTU21D, bus, logger=_LOGGER))
if not sensor.sample_ok: if not sensor.sample_ok:
_LOGGER.error("HTU21D sensor not detected in bus %s", bus_number) _LOGGER.error("HTU21D sensor not detected in bus %s", bus_number)
return False return
sensor_handler = await hass.async_add_executor_job(HTU21DHandler, sensor) sensor_handler = await hass.async_add_executor_job(HTU21DHandler, sensor)