Add setup type hints [g] (#63432)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63467/head
epenet 2022-01-05 13:49:14 +01:00 committed by GitHub
parent 1ac3e71462
commit eed6ca51e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 15 deletions

View File

@ -1,4 +1,6 @@
"""Platform for the Garadget cover component."""
from __future__ import annotations
import logging
import requests
@ -15,8 +17,11 @@ from homeassistant.const import (
STATE_CLOSED,
STATE_OPEN,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import track_utc_time_change
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__)
@ -55,10 +60,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 Garadget covers."""
covers = []
devices = config.get(CONF_COVERS)
devices = config[CONF_COVERS]
for device_id, device_config in devices.items():
args = {

View File

@ -1,9 +1,14 @@
"""Support for binary sensor using GC100."""
from __future__ import annotations
import voluptuous as vol
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
from homeassistant.const import DEVICE_DEFAULT_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
from . import CONF_PORTS, DATA_GC100
@ -14,10 +19,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 GC100 devices."""
binary_sensors = []
ports = config.get(CONF_PORTS)
ports = config[CONF_PORTS]
for port in ports:
for port_addr, port_name in port.items():
binary_sensors.append(

View File

@ -1,10 +1,15 @@
"""Support for switches using GC100."""
from __future__ import annotations
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import CONF_PORTS, DATA_GC100
@ -15,10 +20,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 GC100 devices."""
switches = []
ports = config.get(CONF_PORTS)
ports = config[CONF_PORTS]
for port in ports:
for port_addr, port_name in port.items():
switches.append(GC100Switch(port_name, port_addr, hass.data[DATA_GC100]))

View File

@ -8,8 +8,11 @@ import logging
from goodwe import Inverter, InverterError
from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG, PERCENTAGE, POWER_WATT
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
@ -59,7 +62,11 @@ NUMBERS = (
)
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 the inverter select entities from a config entry."""
inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]

View File

@ -4,8 +4,11 @@ import logging
from goodwe import Inverter, InverterError
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
@ -27,7 +30,11 @@ OPERATION_MODE = SelectEntityDescription(
)
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 the inverter select entities from a config entry."""
inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]

View File

@ -13,6 +13,7 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
@ -29,7 +30,9 @@ from homeassistant.const import (
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -119,9 +122,13 @@ DIAG_SENSOR = GoodweSensorEntityDescription(
)
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 the GoodWe inverter from a config entry."""
entities = []
entities: list[InverterSensor] = []
inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
coordinator = hass.data[DOMAIN][config_entry.entry_id][KEY_COORDINATOR]
device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]

View File

@ -1,4 +1,6 @@
"""Support for Greenwave Reality (TCP Connected) lights."""
from __future__ import annotations
from datetime import timedelta
import logging
import os
@ -13,7 +15,10 @@ from homeassistant.components.light import (
LightEntity,
)
from homeassistant.const import CONF_HOST
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,13 +34,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
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 Greenwave Reality Platform."""
host = config.get(CONF_HOST)
tokenfile = hass.config.path(".greenwave")
tokenfilename = hass.config.path(".greenwave")
if config.get(CONF_VERSION) == 3:
if os.path.exists(tokenfile):
with open(tokenfile, encoding="utf8") as tokenfile:
if os.path.exists(tokenfilename):
with open(tokenfilename, encoding="utf8") as tokenfile:
token = tokenfile.read()
else:
try:
@ -43,7 +53,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
except PermissionError:
_LOGGER.error("The Gateway Is Not In Sync Mode")
raise
with open(tokenfile, "w+", encoding="utf8") as tokenfile:
with open(tokenfilename, "w+", encoding="utf8") as tokenfile:
tokenfile.write(token)
else:
token = None