Add setup type hints [o-q] (#63465)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-05 16:29:21 +01:00 committed by GitHub
parent 754f4c52c2
commit 8756fa28e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 106 additions and 25 deletions

View file

@ -1,4 +1,6 @@
"""Support for monitoring pyLoad."""
from __future__ import annotations
from datetime import timedelta
import logging
@ -18,7 +20,10 @@ from homeassistant.const import (
CONTENT_TYPE_JSON,
DATA_RATE_MEGABYTES_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
_LOGGER = logging.getLogger(__name__)
@ -46,15 +51,20 @@ 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 pyLoad sensors."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
host = config[CONF_HOST]
port = config[CONF_PORT]
protocol = "https" if config[CONF_SSL] else "http"
name = config.get(CONF_NAME)
name = config[CONF_NAME]
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
monitored_types = config.get(CONF_MONITORED_VARIABLES)
monitored_types = config[CONF_MONITORED_VARIABLES]
url = f"{protocol}://{host}:{port}/api/"
try:
@ -64,7 +74,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
requests.exceptions.HTTPError,
) as conn_err:
_LOGGER.error("Error setting up pyLoad API: %s", conn_err)
return False
return
devices = []
for ng_type in monitored_types: