Add setup type hints [s] (part 1) (#63476)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-05 17:34:47 +01:00 committed by GitHub
parent 992f9c3c6c
commit 4c48705fe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 17 deletions

View file

@ -6,10 +6,11 @@ from satel_integra.satel_integra import AsyncSatel
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.typing import ConfigType
DEFAULT_ALARM_NAME = "satel_integra" DEFAULT_ALARM_NAME = "satel_integra"
DEFAULT_PORT = 7094 DEFAULT_PORT = 7094
@ -90,9 +91,9 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass, config): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Satel Integra component.""" """Set up the Satel Integra component."""
conf = config.get(DOMAIN) conf = config[DOMAIN]
zones = conf.get(CONF_ZONES) zones = conf.get(CONF_ZONES)
outputs = conf.get(CONF_OUTPUTS) outputs = conf.get(CONF_OUTPUTS)

View file

@ -1,4 +1,6 @@
"""Support for getting data from websites with scraping.""" """Support for getting data from websites with scraping."""
from __future__ import annotations
import logging import logging
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -27,8 +29,11 @@ from homeassistant.const import (
HTTP_BASIC_AUTHENTICATION, HTTP_BASIC_AUTHENTICATION,
HTTP_DIGEST_AUTHENTICATION, HTTP_DIGEST_AUTHENTICATION,
) )
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
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -61,7 +66,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 Web scrape sensor.""" """Set up the Web scrape sensor."""
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
resource = config.get(CONF_RESOURCE) resource = config.get(CONF_RESOURCE)
@ -81,6 +91,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
if (value_template := config.get(CONF_VALUE_TEMPLATE)) is not None: if (value_template := config.get(CONF_VALUE_TEMPLATE)) is not None:
value_template.hass = hass value_template.hass = hass
auth: httpx.DigestAuth | tuple[str, str] | None
if username and password: if username and password:
if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION: if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
auth = httpx.DigestAuth(username, password) auth = httpx.DigestAuth(username, password)

View file

@ -8,6 +8,7 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import http, websocket_api from homeassistant.components import http, websocket_api
from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_NAME from homeassistant.const import ATTR_NAME
from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.core import HomeAssistant, ServiceCall, callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -77,7 +78,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True return True
async def async_setup_entry(hass, config_entry): async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set up shopping list from config flow.""" """Set up shopping list from config flow."""
async def add_item_service(call: ServiceCall) -> None: async def add_item_service(call: ServiceCall) -> None:

View file

@ -6,9 +6,11 @@ from sisyphus_control import Table
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STOP from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STOP
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.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -28,7 +30,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass, config): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the sisyphus component.""" """Set up the sisyphus component."""
class SocketIONoiseFilter(logging.Filter): class SocketIONoiseFilter(logging.Filter):
@ -41,7 +43,7 @@ async def async_setup(hass, config):
logging.getLogger("socketIO-client").addFilter(SocketIONoiseFilter()) logging.getLogger("socketIO-client").addFilter(SocketIONoiseFilter())
tables = hass.data.setdefault(DATA_SISYPHUS, {}) tables = hass.data.setdefault(DATA_SISYPHUS, {})
table_configs = config.get(DOMAIN) table_configs = config[DOMAIN]
session = async_get_clientsession(hass) session = async_get_clientsession(hass)
async def add_table(host, name=None): async def add_table(host, name=None):

View file

@ -13,7 +13,10 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
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 DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice from . import DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice
@ -46,9 +49,14 @@ 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 platform for a Skybell device.""" """Set up the platform for a Skybell device."""
skybell = hass.data.get(SKYBELL_DOMAIN) skybell = hass.data[SKYBELL_DOMAIN]
binary_sensors = [ binary_sensors = [
SkybellBinarySensor(device, BINARY_SENSOR_TYPES[sensor_type]) SkybellBinarySensor(device, BINARY_SENSOR_TYPES[sensor_type])

View file

@ -9,7 +9,10 @@ import voluptuous as vol
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
from homeassistant.const import CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_MONITORED_CONDITIONS
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 DOMAIN as SKYBELL_DOMAIN, SkybellDevice from . import DOMAIN as SKYBELL_DOMAIN, SkybellDevice
@ -34,13 +37,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 platform for a Skybell device.""" """Set up the platform for a Skybell device."""
cond = config[CONF_MONITORED_CONDITIONS] cond = config[CONF_MONITORED_CONDITIONS]
names = {} names = {}
names[IMAGE_ACTIVITY] = config.get(CONF_ACTIVITY_NAME) names[IMAGE_ACTIVITY] = config.get(CONF_ACTIVITY_NAME)
names[IMAGE_AVATAR] = config.get(CONF_AVATAR_NAME) names[IMAGE_AVATAR] = config.get(CONF_AVATAR_NAME)
skybell = hass.data.get(SKYBELL_DOMAIN) skybell = hass.data[SKYBELL_DOMAIN]
sensors = [] sensors = []
for device in skybell.get_devices(): for device in skybell.get_devices():

View file

@ -1,4 +1,6 @@
"""Light/LED support for the Skybell HD Doorbell.""" """Light/LED support for the Skybell HD Doorbell."""
from __future__ import annotations
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_HS_COLOR, ATTR_HS_COLOR,
@ -6,14 +8,22 @@ from homeassistant.components.light import (
SUPPORT_COLOR, SUPPORT_COLOR,
LightEntity, LightEntity,
) )
from homeassistant.core import HomeAssistant
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
from . import DOMAIN as SKYBELL_DOMAIN, SkybellDevice from . import DOMAIN as SKYBELL_DOMAIN, SkybellDevice
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 platform for a Skybell device.""" """Set up the platform for a Skybell device."""
skybell = hass.data.get(SKYBELL_DOMAIN) skybell = hass.data[SKYBELL_DOMAIN]
sensors = [] sensors = []
for device in skybell.get_devices(): for device in skybell.get_devices():

View file

@ -11,7 +11,10 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
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 DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice from . import DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice
@ -39,9 +42,14 @@ 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 platform for a Skybell device.""" """Set up the platform for a Skybell device."""
skybell = hass.data.get(SKYBELL_DOMAIN) skybell = hass.data[SKYBELL_DOMAIN]
sensors = [ sensors = [
SkybellSensor(device, description) SkybellSensor(device, description)

View file

@ -9,7 +9,10 @@ from homeassistant.components.switch import (
SwitchEntityDescription, SwitchEntityDescription,
) )
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
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 DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice from . import DEFAULT_ENTITY_NAMESPACE, DOMAIN as SKYBELL_DOMAIN, SkybellDevice
@ -38,9 +41,14 @@ 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 platform for a Skybell device.""" """Set up the platform for a Skybell device."""
skybell = hass.data.get(SKYBELL_DOMAIN) skybell = hass.data[SKYBELL_DOMAIN]
switches = [ switches = [
SkybellSwitch(device, description) SkybellSwitch(device, description)