Add setup type hints [t-u] (#63480)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
246338f93d
commit
a4fdaffb14
7 changed files with 83 additions and 29 deletions
|
@ -1,4 +1,5 @@
|
||||||
"""Support for the Tank Utility propane monitor."""
|
"""Support for the Tank Utility propane monitor."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
@ -9,7 +10,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_DEVICES, CONF_EMAIL, CONF_PASSWORD, PERCENTAGE
|
from homeassistant.const import CONF_DEVICES, CONF_EMAIL, CONF_PASSWORD, PERCENTAGE
|
||||||
|
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__)
|
||||||
|
|
||||||
|
@ -37,12 +41,17 @@ SENSOR_ATTRS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
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 Tank Utility sensor."""
|
"""Set up the Tank Utility sensor."""
|
||||||
|
|
||||||
email = config.get(CONF_EMAIL)
|
email = config[CONF_EMAIL]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
devices = config.get(CONF_DEVICES)
|
devices = config[CONF_DEVICES]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = auth.get_token(email, password)
|
token = auth.get_token(email, password)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for The Things Network's Data storage integration."""
|
"""Support for The Things Network's Data storage integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
@ -15,8 +17,11 @@ from homeassistant.const import (
|
||||||
CONF_DEVICE_ID,
|
CONF_DEVICE_ID,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
)
|
)
|
||||||
|
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
|
||||||
|
|
||||||
from . import DATA_TTN, TTN_ACCESS_KEY, TTN_APP_ID, TTN_DATA_STORAGE_URL
|
from . import DATA_TTN, TTN_ACCESS_KEY, TTN_APP_ID, TTN_DATA_STORAGE_URL
|
||||||
|
|
||||||
|
@ -35,11 +40,16 @@ 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 Things Network Data storage sensors."""
|
"""Set up The Things Network Data storage sensors."""
|
||||||
ttn = hass.data.get(DATA_TTN)
|
ttn = hass.data[DATA_TTN]
|
||||||
device_id = config.get(CONF_DEVICE_ID)
|
device_id = config[CONF_DEVICE_ID]
|
||||||
values = config.get(CONF_VALUES)
|
values = config[CONF_VALUES]
|
||||||
app_id = ttn.get(TTN_APP_ID)
|
app_id = ttn.get(TTN_APP_ID)
|
||||||
access_key = ttn.get(TTN_ACCESS_KEY)
|
access_key = ttn.get(TTN_ACCESS_KEY)
|
||||||
|
|
||||||
|
|
|
@ -74,12 +74,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, PLATFORMS
|
config_entry, PLATFORMS
|
||||||
)
|
)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
tibber_connection = hass.data.get(DOMAIN)
|
tibber_connection = hass.data[DOMAIN]
|
||||||
await tibber_connection.rt_disconnect()
|
await tibber_connection.rt_disconnect()
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ELECTRIC_CURRENT_AMPERE,
|
ELECTRIC_CURRENT_AMPERE,
|
||||||
ELECTRIC_POTENTIAL_VOLT,
|
ELECTRIC_POTENTIAL_VOLT,
|
||||||
|
@ -29,11 +30,12 @@ from homeassistant.const import (
|
||||||
POWER_WATT,
|
POWER_WATT,
|
||||||
SIGNAL_STRENGTH_DECIBELS,
|
SIGNAL_STRENGTH_DECIBELS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers import update_coordinator
|
from homeassistant.helpers import update_coordinator
|
||||||
from homeassistant.helpers.device_registry import async_get as async_get_dev_reg
|
from homeassistant.helpers.device_registry import async_get as async_get_dev_reg
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_reg
|
from homeassistant.helpers.entity_registry import async_get as async_get_entity_reg
|
||||||
from homeassistant.util import Throttle, dt as dt_util
|
from homeassistant.util import Throttle, dt as dt_util
|
||||||
|
|
||||||
|
@ -227,16 +229,18 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
) -> None:
|
||||||
"""Set up the Tibber sensor."""
|
"""Set up the Tibber sensor."""
|
||||||
|
|
||||||
tibber_connection = hass.data.get(TIBBER_DOMAIN)
|
tibber_connection = hass.data[TIBBER_DOMAIN]
|
||||||
|
|
||||||
entity_registry = async_get_entity_reg(hass)
|
entity_registry = async_get_entity_reg(hass)
|
||||||
device_registry = async_get_dev_reg(hass)
|
device_registry = async_get_dev_reg(hass)
|
||||||
|
|
||||||
coordinator = None
|
coordinator: update_coordinator.DataUpdateCoordinator | None = None
|
||||||
entities = []
|
entities: list[TibberSensor] = []
|
||||||
for home in tibber_connection.get_homes(only_active=False):
|
for home in tibber_connection.get_homes(only_active=False):
|
||||||
try:
|
try:
|
||||||
await home.update_info()
|
await home.update_info()
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for TMB (Transports Metropolitans de Barcelona) Barcelona public transport."""
|
"""Support for TMB (Transports Metropolitans de Barcelona) Barcelona public transport."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -8,7 +10,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, TIME_MINUTES
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES
|
||||||
|
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__)
|
||||||
|
@ -44,13 +49,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 sensors."""
|
"""Set up the sensors."""
|
||||||
ibus_client = IBus(config[CONF_APP_ID], config[CONF_APP_KEY])
|
ibus_client = IBus(config[CONF_APP_ID], config[CONF_APP_KEY])
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
for line_stop in config.get(CONF_BUS_STOPS):
|
for line_stop in config[CONF_BUS_STOPS]:
|
||||||
line = line_stop[CONF_LINE]
|
line = line_stop[CONF_LINE]
|
||||||
stop = line_stop[CONF_BUS_STOP]
|
stop = line_stop[CONF_BUS_STOP]
|
||||||
if line_stop.get(CONF_NAME):
|
if line_stop.get(CONF_NAME):
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for the Torque OBD application."""
|
"""Support for the Torque OBD application."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -6,8 +8,10 @@ import voluptuous as vol
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_NAME, DEGREE
|
from homeassistant.const import CONF_EMAIL, CONF_NAME, DEGREE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
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
|
||||||
|
|
||||||
API_PATH = "/api/torque"
|
API_PATH = "/api/torque"
|
||||||
|
|
||||||
|
@ -38,16 +42,20 @@ def convert_pid(value):
|
||||||
return int(value, 16)
|
return int(value, 16)
|
||||||
|
|
||||||
|
|
||||||
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 Torque platform."""
|
"""Set up the Torque platform."""
|
||||||
vehicle = config.get(CONF_NAME)
|
vehicle = config.get(CONF_NAME)
|
||||||
email = config.get(CONF_EMAIL)
|
email = config.get(CONF_EMAIL)
|
||||||
sensors = {}
|
sensors: dict[int, TorqueSensor] = {}
|
||||||
|
|
||||||
hass.http.register_view(
|
hass.http.register_view(
|
||||||
TorqueReceiveDataView(email, vehicle, sensors, add_entities)
|
TorqueReceiveDataView(email, vehicle, sensors, add_entities)
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class TorqueReceiveDataView(HomeAssistantView):
|
class TorqueReceiveDataView(HomeAssistantView):
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Support for UK public transport data provided by transportapi.com."""
|
"""Support for UK public transport data provided by transportapi.com."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
@ -9,7 +11,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_MODE, TIME_MINUTES
|
from homeassistant.const import CONF_MODE, TIME_MINUTES
|
||||||
|
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
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
@ -47,20 +52,28 @@ 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:
|
||||||
"""Get the uk_transport sensor."""
|
"""Get the uk_transport sensor."""
|
||||||
sensors = []
|
sensors: list[UkTransportSensor] = []
|
||||||
number_sensors = len(config.get(CONF_QUERIES))
|
number_sensors = len(queries := config[CONF_QUERIES])
|
||||||
interval = timedelta(seconds=87 * number_sensors)
|
interval = timedelta(seconds=87 * number_sensors)
|
||||||
|
|
||||||
for query in config.get(CONF_QUERIES):
|
api_app_id = config[CONF_API_APP_ID]
|
||||||
|
api_app_key = config[CONF_API_APP_KEY]
|
||||||
|
|
||||||
|
for query in queries:
|
||||||
if "bus" in query.get(CONF_MODE):
|
if "bus" in query.get(CONF_MODE):
|
||||||
stop_atcocode = query.get(CONF_ORIGIN)
|
stop_atcocode = query.get(CONF_ORIGIN)
|
||||||
bus_direction = query.get(CONF_DESTINATION)
|
bus_direction = query.get(CONF_DESTINATION)
|
||||||
sensors.append(
|
sensors.append(
|
||||||
UkTransportLiveBusTimeSensor(
|
UkTransportLiveBusTimeSensor(
|
||||||
config.get(CONF_API_APP_ID),
|
api_app_id,
|
||||||
config.get(CONF_API_APP_KEY),
|
api_app_key,
|
||||||
stop_atcocode,
|
stop_atcocode,
|
||||||
bus_direction,
|
bus_direction,
|
||||||
interval,
|
interval,
|
||||||
|
@ -72,8 +85,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
calling_at = query.get(CONF_DESTINATION)
|
calling_at = query.get(CONF_DESTINATION)
|
||||||
sensors.append(
|
sensors.append(
|
||||||
UkTransportLiveTrainTimeSensor(
|
UkTransportLiveTrainTimeSensor(
|
||||||
config.get(CONF_API_APP_ID),
|
api_app_id,
|
||||||
config.get(CONF_API_APP_KEY),
|
api_app_key,
|
||||||
station_code,
|
station_code,
|
||||||
calling_at,
|
calling_at,
|
||||||
interval,
|
interval,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue