Enable basic type checking for awair (#55046)
This commit is contained in:
parent
9088a6a138
commit
135778fe91
5 changed files with 14 additions and 10 deletions
|
@ -69,6 +69,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
if error is None:
|
if error is None:
|
||||||
entry = await self.async_set_unique_id(self.unique_id)
|
entry = await self.async_set_unique_id(self.unique_id)
|
||||||
|
assert entry
|
||||||
self.hass.config_entries.async_update_entry(entry, data=user_input)
|
self.hass.config_entries.async_update_entry(entry, data=user_input)
|
||||||
return self.async_abort(reason="reauth_successful")
|
return self.async_abort(reason="reauth_successful")
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from python_awair.air_data import AirData
|
||||||
from python_awair.devices import AwairDevice
|
from python_awair.devices import AwairDevice
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntityDescription
|
from homeassistant.components.sensor import SensorEntityDescription
|
||||||
|
@ -134,4 +135,4 @@ class AwairResult:
|
||||||
"""Wrapper class to hold an awair device and set of air data."""
|
"""Wrapper class to hold an awair device and set of air data."""
|
||||||
|
|
||||||
device: AwairDevice
|
device: AwairDevice
|
||||||
air_data: dict
|
air_data: AirData
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
"""Support for Awair sensors."""
|
"""Support for Awair sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from python_awair.air_data import AirData
|
||||||
from python_awair.devices import AwairDevice
|
from python_awair.devices import AwairDevice
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult
|
from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
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 (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
ATTR_CONNECTIONS,
|
ATTR_CONNECTIONS,
|
||||||
|
@ -18,7 +19,6 @@ from homeassistant.helpers import device_registry as dr
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
@ -59,7 +59,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigType,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
):
|
):
|
||||||
"""Set up Awair sensor entity based on a config entry."""
|
"""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.
|
# for users with first-gen devices that are upgrading.
|
||||||
if (
|
if (
|
||||||
self.entity_description.key == API_PM25
|
self.entity_description.key == API_PM25
|
||||||
|
and self._air_data
|
||||||
and API_DUST in self._air_data.sensors
|
and API_DUST in self._air_data.sensors
|
||||||
):
|
):
|
||||||
unique_id_tag = "DUST"
|
unique_id_tag = "DUST"
|
||||||
|
@ -161,8 +162,11 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float:
|
def native_value(self) -> float | None:
|
||||||
"""Return the state, rounding off to reasonable values."""
|
"""Return the state, rounding off to reasonable values."""
|
||||||
|
if not self._air_data:
|
||||||
|
return None
|
||||||
|
|
||||||
state: float
|
state: float
|
||||||
sensor_type = self.entity_description.key
|
sensor_type = self.entity_description.key
|
||||||
|
|
||||||
|
@ -206,6 +210,8 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""
|
"""
|
||||||
sensor_type = self.entity_description.key
|
sensor_type = self.entity_description.key
|
||||||
attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||||
|
if not self._air_data:
|
||||||
|
return attrs
|
||||||
if sensor_type in self._air_data.indices:
|
if sensor_type in self._air_data.indices:
|
||||||
attrs["awair_index"] = abs(self._air_data.indices[sensor_type])
|
attrs["awair_index"] = abs(self._air_data.indices[sensor_type])
|
||||||
elif sensor_type in DUST_ALIASES and API_DUST in self._air_data.indices:
|
elif sensor_type in DUST_ALIASES and API_DUST in self._air_data.indices:
|
||||||
|
@ -233,7 +239,7 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _air_data(self) -> AwairResult | None:
|
def _air_data(self) -> AirData | None:
|
||||||
"""Return the latest data for our device, or None."""
|
"""Return the latest data for our device, or None."""
|
||||||
result: AwairResult | None = self.coordinator.data.get(self._device.uuid)
|
result: AwairResult | None = self.coordinator.data.get(self._device.uuid)
|
||||||
if result:
|
if result:
|
||||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -1672,9 +1672,6 @@ no_implicit_optional = false
|
||||||
warn_return_any = false
|
warn_return_any = false
|
||||||
warn_unreachable = false
|
warn_unreachable = false
|
||||||
|
|
||||||
[mypy-homeassistant.components.awair.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.blueprint.*]
|
[mypy-homeassistant.components.blueprint.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ from .model import Config, Integration
|
||||||
# remove your component from this list to enable type checks.
|
# remove your component from this list to enable type checks.
|
||||||
# Do your best to not add anything new here.
|
# Do your best to not add anything new here.
|
||||||
IGNORED_MODULES: Final[list[str]] = [
|
IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.awair.*",
|
|
||||||
"homeassistant.components.blueprint.*",
|
"homeassistant.components.blueprint.*",
|
||||||
"homeassistant.components.climacell.*",
|
"homeassistant.components.climacell.*",
|
||||||
"homeassistant.components.config.*",
|
"homeassistant.components.config.*",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue