Remove invalid return values in setup methods [r-z] (#63365)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63367/head
epenet 2022-01-04 10:52:30 +01:00 committed by GitHub
parent dc15c9ed75
commit b14ac1b94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 146 additions and 36 deletions

View File

@ -1,4 +1,6 @@
"""Support for interfacing with Russound via RNET Protocol.""" """Support for interfacing with Russound via RNET Protocol."""
from __future__ import annotations
import logging import logging
from russound import russound from russound import russound
@ -13,7 +15,10 @@ from homeassistant.components.media_player.const import (
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_SET,
) )
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, 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
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -43,14 +48,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 Russound RNET platform.""" """Set up the Russound RNET platform."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
port = config.get(CONF_PORT) port = config.get(CONF_PORT)
if host is None or port is None: if host is None or port is None:
_LOGGER.error("Invalid config. Expected %s and %s", CONF_HOST, CONF_PORT) _LOGGER.error("Invalid config. Expected %s and %s", CONF_HOST, CONF_PORT)
return False return
russ = russound.Russound(host, port) russ = russound.Russound(host, port)
russ.connect() russ.connect()

View File

@ -7,8 +7,10 @@ from schluter.authenticator import AuthenticationState, Authenticator
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN from .const import DOMAIN
@ -31,7 +33,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
def setup(hass, config): def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Schluter component.""" """Set up the Schluter component."""
_LOGGER.debug("Starting setup of schluter") _LOGGER.debug("Starting setup of schluter")
@ -51,7 +53,7 @@ def setup(hass, config):
authentication = authenticator.authenticate() authentication = authenticator.authenticate()
except RequestException as ex: except RequestException as ex:
_LOGGER.error("Unable to connect to Schluter service: %s", ex) _LOGGER.error("Unable to connect to Schluter service: %s", ex)
return return False
state = authentication.state state = authentication.state

View File

@ -1,4 +1,6 @@
"""Sensor for displaying the number of result on Shodan.io.""" """Sensor for displaying the number of result on Shodan.io."""
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_API_KEY, CONF_NAME from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, 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,7 +35,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 Shodan sensor.""" """Set up the Shodan sensor."""
api_key = config.get(CONF_API_KEY) api_key = config.get(CONF_API_KEY)
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
@ -41,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
data.update() data.update()
except shodan.exception.APIError as error: except shodan.exception.APIError as error:
_LOGGER.warning("Unable to connect to Shodan.io: %s", error) _LOGGER.warning("Unable to connect to Shodan.io: %s", error)
return False return
add_entities([ShodanSensor(data, name)], True) add_entities([ShodanSensor(data, name)], True)

View File

@ -1,4 +1,6 @@
"""Sensor for SigFox devices.""" """Sensor for SigFox devices."""
from __future__ import annotations
import datetime import datetime
from http import HTTPStatus from http import HTTPStatus
import json import json
@ -10,7 +12,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 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__)
@ -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 sigfox sensor.""" """Set up the sigfox sensor."""
api_login = config[CONF_API_LOGIN] api_login = config[CONF_API_LOGIN]
api_password = config[CONF_API_PASSWORD] api_password = config[CONF_API_PASSWORD]
@ -37,7 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
try: try:
sigfox = SigfoxAPI(api_login, api_password) sigfox = SigfoxAPI(api_login, api_password)
except ValueError: except ValueError:
return False return
auth = sigfox.auth auth = sigfox.auth
devices = sigfox.devices devices = sigfox.devices

View File

@ -1,4 +1,6 @@
"""Support for Sony projectors via SDCP network control.""" """Support for Sony projectors via SDCP network control."""
from __future__ import annotations
import logging import logging
import pysdcp import pysdcp
@ -6,7 +8,10 @@ import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON from homeassistant.const import CONF_HOST, CONF_NAME, STATE_OFF, 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
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -20,7 +25,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:
"""Connect to Sony projector using network.""" """Connect to Sony projector using network."""
host = config[CONF_HOST] host = config[CONF_HOST]
@ -32,10 +42,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
sdcp_connection.get_power() sdcp_connection.get_power()
except ConnectionError: except ConnectionError:
_LOGGER.error("Failed to connect to projector '%s'", host) _LOGGER.error("Failed to connect to projector '%s'", host)
return False return
_LOGGER.debug("Validated projector '%s' OK", host) _LOGGER.debug("Validated projector '%s' OK", host)
add_entities([SonyProjector(sdcp_connection, name)], True) add_entities([SonyProjector(sdcp_connection, name)], True)
return True
class SonyProjector(SwitchEntity): class SonyProjector(SwitchEntity):

View File

@ -26,7 +26,7 @@ from homeassistant.components.media_player.const import (
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_SET,
) )
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_COMMAND, ATTR_COMMAND,
CONF_HOST, CONF_HOST,
@ -39,7 +39,7 @@ from homeassistant.const import (
STATE_PAUSED, STATE_PAUSED,
STATE_PLAYING, STATE_PLAYING,
) )
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.device_registry import format_mac
@ -47,6 +47,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from .browse_media import build_item_response, generate_playlist, library_payload from .browse_media import build_item_response, generate_playlist, library_payload
@ -123,7 +124,11 @@ async def start_server_discovery(hass):
) )
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 an LMS Server from a config entry.""" """Set up an LMS Server from a config entry."""
config = config_entry.data config = config_entry.data
_LOGGER.debug("Reached async_setup_entry for host=%s", config[CONF_HOST]) _LOGGER.debug("Reached async_setup_entry for host=%s", config[CONF_HOST])
@ -215,8 +220,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
EVENT_HOMEASSISTANT_START, start_server_discovery(hass) EVENT_HOMEASSISTANT_START, start_server_discovery(hass)
) )
return True
class SqueezeBoxEntity(MediaPlayerEntity): class SqueezeBoxEntity(MediaPlayerEntity):
""" """

View File

@ -1,4 +1,6 @@
"""Support gathering ted5000 information.""" """Support gathering ted5000 information."""
from __future__ import annotations
from contextlib import suppress from contextlib import suppress
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -19,7 +21,10 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
POWER_WATT, POWER_WATT,
) )
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import 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__)
@ -38,7 +43,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 Ted5000 sensor.""" """Set up the Ted5000 sensor."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
port = config.get(CONF_PORT) port = config.get(CONF_PORT)
@ -56,7 +66,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
dev.append(Ted5000Sensor(gateway, name, mtu, ELECTRIC_POTENTIAL_VOLT)) dev.append(Ted5000Sensor(gateway, name, mtu, ELECTRIC_POTENTIAL_VOLT))
add_entities(dev) add_entities(dev)
return True
class Ted5000Sensor(SensorEntity): class Ted5000Sensor(SensorEntity):

View File

@ -20,7 +20,10 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
TIME_SECONDS, TIME_SECONDS,
) )
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__)
@ -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 Travis CI sensor.""" """Set up the Travis CI sensor."""
token = config[CONF_API_KEY] token = config[CONF_API_KEY]
@ -105,7 +113,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
title=NOTIFICATION_TITLE, title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID, notification_id=NOTIFICATION_ID,
) )
return False return
# non specific repository selected, then show all associated # non specific repository selected, then show all associated
if not repositories: if not repositories:

View File

@ -11,8 +11,11 @@ import voluptuous as vol
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera
from homeassistant.const import CONF_PASSWORD, CONF_PORT, CONF_SSL from homeassistant.const import CONF_PASSWORD, CONF_PORT, CONF_SSL
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
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.dt import utc_from_timestamp from homeassistant.util.dt import utc_from_timestamp
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -35,7 +38,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:
"""Discover cameras on a Unifi NVR.""" """Discover cameras on a Unifi NVR."""
addr = config[CONF_NVR] addr = config[CONF_NVR]
key = config[CONF_KEY] key = config[CONF_KEY]
@ -58,7 +66,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
] ]
except nvr.NotAuthorized: except nvr.NotAuthorized:
_LOGGER.error("Authorization failure while connecting to NVR") _LOGGER.error("Authorization failure while connecting to NVR")
return False return
except nvr.NvrError as ex: except nvr.NvrError as ex:
_LOGGER.error("NVR refuses to talk to me: %s", str(ex)) _LOGGER.error("NVR refuses to talk to me: %s", str(ex))
raise PlatformNotReady from ex raise PlatformNotReady from ex
@ -73,7 +81,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
], ],
True, True,
) )
return True
class UnifiVideoCamera(Camera): class UnifiVideoCamera(Camera):

View File

@ -2,8 +2,10 @@
import logging import logging
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.core import callback from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .common import VeSyncDevice from .common import VeSyncDevice
from .const import DOMAIN, VS_DISCOVERY, VS_DISPATCHERS, VS_SWITCHES from .const import DOMAIN, VS_DISCOVERY, VS_DISPATCHERS, VS_SWITCHES
@ -21,7 +23,11 @@ DEV_TYPE_TO_HA = {
} }
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.""" """Set up switches."""
async def async_discover(devices): async def async_discover(devices):
@ -34,7 +40,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
hass.data[DOMAIN][VS_DISPATCHERS].append(disp) hass.data[DOMAIN][VS_DISPATCHERS].append(disp)
_async_setup_entities(hass.data[DOMAIN][VS_SWITCHES], async_add_entities) _async_setup_entities(hass.data[DOMAIN][VS_SWITCHES], async_add_entities)
return True
@callback @callback

View File

@ -1,4 +1,6 @@
"""Support for Yeelight Sunflower color bulbs (not Yeelight Blue or WiFi).""" """Support for Yeelight Sunflower color bulbs (not Yeelight Blue or WiFi)."""
from __future__ import annotations
import logging import logging
import voluptuous as vol import voluptuous as vol
@ -13,7 +15,10 @@ from homeassistant.components.light import (
LightEntity, LightEntity,
) )
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_HOST
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.color as color_util import homeassistant.util.color as color_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -23,14 +28,19 @@ SUPPORT_YEELIGHT_SUNFLOWER = SUPPORT_BRIGHTNESS | SUPPORT_COLOR
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string}) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
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 Yeelight Sunflower Light platform.""" """Set up the Yeelight Sunflower Light platform."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
hub = yeelightsunflower.Hub(host) hub = yeelightsunflower.Hub(host)
if not hub.available: if not hub.available:
_LOGGER.error("Could not connect to Yeelight Sunflower hub") _LOGGER.error("Could not connect to Yeelight Sunflower hub")
return False return
add_entities(SunflowerBulb(light) for light in hub.get_lights()) add_entities(SunflowerBulb(light) for light in hub.get_lights())

View File

@ -34,7 +34,10 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
__version__, __version__,
) )
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, dt as dt_util from homeassistant.util import Throttle, dt as dt_util
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -198,7 +201,12 @@ PLATFORM_SCHEMA = cv.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 ZAMG sensor platform.""" """Set up the ZAMG sensor platform."""
name = config[CONF_NAME] name = config[CONF_NAME]
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
@ -213,14 +221,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
CONF_STATION_ID, CONF_STATION_ID,
station_id, station_id,
) )
return False return
probe = ZamgData(station_id=station_id) probe = ZamgData(station_id=station_id)
try: try:
probe.update() probe.update()
except (ValueError, TypeError) as err: except (ValueError, TypeError) as err:
_LOGGER.error("Received error from ZAMG: %s", err) _LOGGER.error("Received error from ZAMG: %s", err)
return False return
monitored_conditions = config[CONF_MONITORED_CONDITIONS] monitored_conditions = config[CONF_MONITORED_CONDITIONS]
add_entities( add_entities(

View File

@ -1,4 +1,6 @@
"""Sensor for data from Austrian Zentralanstalt für Meteorologie.""" """Sensor for data from Austrian Zentralanstalt für Meteorologie."""
from __future__ import annotations
import logging import logging
import voluptuous as vol import voluptuous as vol
@ -13,7 +15,10 @@ from homeassistant.components.weather import (
WeatherEntity, WeatherEntity,
) )
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
# Reuse data and API logic from the sensor implementation # Reuse data and API logic from the sensor implementation
from .sensor import ( from .sensor import (
@ -40,7 +45,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 ZAMG weather platform.""" """Set up the ZAMG weather platform."""
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
@ -55,14 +65,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
CONF_STATION_ID, CONF_STATION_ID,
station_id, station_id,
) )
return False return
probe = ZamgData(station_id=station_id) probe = ZamgData(station_id=station_id)
try: try:
probe.update() probe.update()
except (ValueError, TypeError) as err: except (ValueError, TypeError) as err:
_LOGGER.error("Received error from ZAMG: %s", err) _LOGGER.error("Received error from ZAMG: %s", err)
return False return
add_entities([ZamgWeather(probe, name)], True) add_entities([ZamgWeather(probe, name)], True)

View File

@ -1,19 +1,28 @@
"""Support for ZoneMinder binary sensors.""" """Support for ZoneMinder binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass, BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.core import HomeAssistant
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
async def async_setup_platform(hass, config, add_entities, discovery_info=None): async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the ZoneMinder binary sensor platform.""" """Set up the ZoneMinder binary sensor platform."""
sensors = [] sensors = []
for host_name, zm_client in hass.data[ZONEMINDER_DOMAIN].items(): for host_name, zm_client in hass.data[ZONEMINDER_DOMAIN].items():
sensors.append(ZMAvailabilitySensor(host_name, zm_client)) sensors.append(ZMAvailabilitySensor(host_name, zm_client))
add_entities(sensors) add_entities(sensors)
return True
class ZMAvailabilitySensor(BinarySensorEntity): class ZMAvailabilitySensor(BinarySensorEntity):