Enable basic type checking for awair (#55046)

pull/60246/head
Erik Montnemery 2021-11-23 22:49:42 +01:00 committed by GitHub
parent 9088a6a138
commit 135778fe91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 10 deletions

View File

@ -69,6 +69,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
if error is None:
entry = await self.async_set_unique_id(self.unique_id)
assert entry
self.hass.config_entries.async_update_entry(entry, data=user_input)
return self.async_abort(reason="reauth_successful")

View File

@ -5,6 +5,7 @@ from dataclasses import dataclass
from datetime import timedelta
import logging
from python_awair.air_data import AirData
from python_awair.devices import AwairDevice
from homeassistant.components.sensor import SensorEntityDescription
@ -134,4 +135,4 @@ class AwairResult:
"""Wrapper class to hold an awair device and set of air data."""
device: AwairDevice
air_data: dict
air_data: AirData

View File

@ -1,12 +1,13 @@
"""Support for Awair sensors."""
from __future__ import annotations
from python_awair.air_data import AirData
from python_awair.devices import AwairDevice
import voluptuous as vol
from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_CONNECTIONS,
@ -18,7 +19,6 @@ from homeassistant.helpers import device_registry as dr
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import (
@ -59,7 +59,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigType,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up Awair sensor entity based on a config entry."""
@ -131,6 +131,7 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
# for users with first-gen devices that are upgrading.
if (
self.entity_description.key == API_PM25
and self._air_data
and API_DUST in self._air_data.sensors
):
unique_id_tag = "DUST"
@ -161,8 +162,11 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
return False
@property
def native_value(self) -> float:
def native_value(self) -> float | None:
"""Return the state, rounding off to reasonable values."""
if not self._air_data:
return None
state: float
sensor_type = self.entity_description.key
@ -206,6 +210,8 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
"""
sensor_type = self.entity_description.key
attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
if not self._air_data:
return attrs
if sensor_type in self._air_data.indices:
attrs["awair_index"] = abs(self._air_data.indices[sensor_type])
elif sensor_type in DUST_ALIASES and API_DUST in self._air_data.indices:
@ -233,7 +239,7 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
return info
@property
def _air_data(self) -> AwairResult | None:
def _air_data(self) -> AirData | None:
"""Return the latest data for our device, or None."""
result: AwairResult | None = self.coordinator.data.get(self._device.uuid)
if result:

View File

@ -1672,9 +1672,6 @@ no_implicit_optional = false
warn_return_any = false
warn_unreachable = false
[mypy-homeassistant.components.awair.*]
ignore_errors = true
[mypy-homeassistant.components.blueprint.*]
ignore_errors = true

View File

@ -14,7 +14,6 @@ from .model import Config, Integration
# remove your component from this list to enable type checks.
# Do your best to not add anything new here.
IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.awair.*",
"homeassistant.components.blueprint.*",
"homeassistant.components.climacell.*",
"homeassistant.components.config.*",