Skip to content

Commit

Permalink
Add sensor setup type hints [c-d] (#63318)
Browse files Browse the repository at this point in the history
Co-authored-by: epenet <epenet@users.noreply.github.com>
  • Loading branch information
epenet and epenet authored Jan 3, 2022
1 parent 30a64bd commit 84221f6
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 27 deletions.
17 changes: 13 additions & 4 deletions homeassistant/components/cert_expiry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
SensorDeviceClass,
SensorEntity,
)
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_START
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DEFAULT_PORT, DOMAIN
Expand All @@ -29,7 +31,12 @@
)


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 certificate expiry sensor."""

@callback
Expand All @@ -49,7 +56,9 @@ def do_import(_):
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_import)


async def async_setup_entry(hass, entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Add cert-expiry entry."""
coordinator = hass.data[DOMAIN][entry.entry_id]

Expand Down
12 changes: 11 additions & 1 deletion homeassistant/components/citybikes/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Sensor for the CityBikes data."""
from __future__ import annotations

import asyncio
from datetime import timedelta
import logging
Expand Down Expand Up @@ -26,11 +28,14 @@
LENGTH_FEET,
LENGTH_METERS,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import distance, location

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -149,7 +154,12 @@ async def async_citybikes_request(hass, uri, schema):
raise CityBikesRequestError


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 CityBikes platform."""
if PLATFORM not in hass.data:
hass.data[PLATFORM] = {MONITORED_NETWORKS: {}}
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/co2signal/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from typing import cast

from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import update_coordinator
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from . import CO2SignalCoordinator, CO2SignalResponse
Expand Down Expand Up @@ -44,7 +47,9 @@ class CO2SensorEntityDescription:
)


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 CO2signal sensor."""
coordinator: CO2SignalCoordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities(CO2Sensor(coordinator, description) for description in SENSORS)
Expand Down
10 changes: 9 additions & 1 deletion homeassistant/components/comed_hourly_pricing/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
SensorEntityDescription,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, CONF_OFFSET
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
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__)
_RESOURCE = "https://hourlypricing.comed.com/api"
Expand Down Expand Up @@ -61,7 +64,12 @@
)


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 ComEd Hourly Pricing sensor."""
websession = async_get_clientsession(hass)

Expand Down
12 changes: 11 additions & 1 deletion homeassistant/components/comfoconnect/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Platform to control a Zehnder ComfoAir Q350/450/600 ventilation unit."""
from __future__ import annotations

from dataclasses import dataclass
import logging

Expand Down Expand Up @@ -43,8 +45,11 @@
TIME_DAYS,
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import DOMAIN, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, ComfoConnectBridge

Expand Down Expand Up @@ -273,7 +278,12 @@ class ComfoconnectSensorEntityDescription(
)


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 ComfoConnect sensor platform."""
ccb = hass.data[DOMAIN]

Expand Down
13 changes: 11 additions & 2 deletions homeassistant/components/compensation/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for compensation sensor."""
from __future__ import annotations

import logging

from homeassistant.components.sensor import SensorEntity
Expand All @@ -10,8 +12,10 @@
CONF_UNIT_OF_MEASUREMENT,
STATE_UNKNOWN,
)
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from .const import (
CONF_COMPENSATION,
Expand All @@ -28,7 +32,12 @@
ATTR_SOURCE_ATTRIBUTE = "source_attribute"


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 Compensation sensor."""
if discovery_info is None:
return
Expand Down
9 changes: 8 additions & 1 deletion homeassistant/components/coronavirus/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Sensor platform for the Corona virus."""
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from . import get_coordinator
Expand All @@ -14,7 +17,11 @@
}


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:
"""Defer sensor setup to the shared sensor module."""
coordinator = await get_coordinator(hass)

Expand Down
15 changes: 13 additions & 2 deletions homeassistant/components/daikin/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
PERCENTAGE,
POWER_KILO_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import DOMAIN as DAIKIN_DOMAIN, DaikinApi
from .const import (
Expand Down Expand Up @@ -111,15 +115,22 @@ class DaikinSensorEntityDescription(SensorEntityDescription, DaikinRequiredKeysM
)


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:
"""Old way of setting up the Daikin sensors.
Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""


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 Daikin climate based on config_entry."""
daikin_api = hass.data[DAIKIN_DOMAIN].get(entry.entry_id)
sensors = [ATTR_INSIDE_TEMPERATURE]
Expand Down
12 changes: 11 additions & 1 deletion homeassistant/components/danfoss_air/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for the for Danfoss Air HRV sensors."""
from __future__ import annotations

import logging

from pydanfossair.commands import ReadCommand
Expand All @@ -9,13 +11,21 @@
SensorStateClass,
)
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import DOMAIN as DANFOSS_AIR_DOMAIN

_LOGGER = logging.getLogger(__name__)


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 available Danfoss Air sensors etc."""
data = hass.data[DANFOSS_AIR_DOMAIN]

Expand Down
12 changes: 11 additions & 1 deletion homeassistant/components/delijn/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for De Lijn (Flemish public transport) information."""
from __future__ import annotations

import logging

from pydelijn.api import Passages
Expand All @@ -11,8 +13,11 @@
SensorEntity,
)
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
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__)

Expand Down Expand Up @@ -46,7 +51,12 @@
)


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:
"""Create the sensor."""
api_key = config[CONF_API_KEY]

Expand Down
10 changes: 9 additions & 1 deletion homeassistant/components/deluge/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
DATA_RATE_KILOBYTES_PER_SECOND,
STATE_IDLE,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
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__)
_THROTTLED_REFRESH = None
Expand Down Expand Up @@ -64,7 +67,12 @@
)


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 Deluge sensors."""

name = config[CONF_NAME]
Expand Down
13 changes: 11 additions & 2 deletions homeassistant/components/derivative/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Numeric derivative of data coming from a source sensor over time."""
from __future__ import annotations

from decimal import Decimal, DecimalException
import logging

Expand All @@ -16,10 +18,12 @@
TIME_MINUTES,
TIME_SECONDS,
)
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

# mypy: allow-untyped-defs, no-check-untyped-defs

Expand Down Expand Up @@ -71,7 +75,12 @@
)


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 derivative sensor."""
derivative = DerivativeSensor(
source_entity=config[CONF_SOURCE],
Expand Down
Loading

0 comments on commit 84221f6

Please sign in to comment.