mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Capture local Awair firmware version to DeviceInfo (#76700)
This commit is contained in:
@ -61,6 +61,7 @@ homeassistant.components.aseko_pool_live.*
|
||||
homeassistant.components.asuswrt.*
|
||||
homeassistant.components.auth.*
|
||||
homeassistant.components.automation.*
|
||||
homeassistant.components.awair.*
|
||||
homeassistant.components.backup.*
|
||||
homeassistant.components.baf.*
|
||||
homeassistant.components.binary_sensor.*
|
||||
|
@ -2,7 +2,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from asyncio import gather
|
||||
from datetime import timedelta
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from async_timeout import timeout
|
||||
from python_awair import Awair, AwairLocal
|
||||
from python_awair.devices import AwairBaseDevice, AwairLocalDevice
|
||||
@ -63,13 +65,18 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
class AwairDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Define a wrapper class to update Awair data."""
|
||||
|
||||
def __init__(self, hass, config_entry, update_interval) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
update_interval: timedelta | None,
|
||||
) -> None:
|
||||
"""Set up the AwairDataUpdateCoordinator class."""
|
||||
self._config_entry = config_entry
|
||||
|
||||
super().__init__(hass, LOGGER, name=DOMAIN, update_interval=update_interval)
|
||||
|
||||
async def _fetch_air_data(self, device: AwairBaseDevice):
|
||||
async def _fetch_air_data(self, device: AwairBaseDevice) -> AwairResult:
|
||||
"""Fetch latest air quality data."""
|
||||
LOGGER.debug("Fetching data for %s", device.uuid)
|
||||
air_data = await device.air_data_latest()
|
||||
@ -80,7 +87,9 @@ class AwairDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
class AwairCloudDataUpdateCoordinator(AwairDataUpdateCoordinator):
|
||||
"""Define a wrapper class to update Awair data from Cloud API."""
|
||||
|
||||
def __init__(self, hass, config_entry, session) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry, session: ClientSession
|
||||
) -> None:
|
||||
"""Set up the AwairCloudDataUpdateCoordinator class."""
|
||||
access_token = config_entry.data[CONF_ACCESS_TOKEN]
|
||||
self._awair = Awair(access_token=access_token, session=session)
|
||||
@ -109,7 +118,9 @@ class AwairLocalDataUpdateCoordinator(AwairDataUpdateCoordinator):
|
||||
|
||||
_device: AwairLocalDevice | None = None
|
||||
|
||||
def __init__(self, hass, config_entry, session) -> None:
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry, session: ClientSession
|
||||
) -> None:
|
||||
"""Set up the AwairLocalDataUpdateCoordinator class."""
|
||||
self._awair = AwairLocal(
|
||||
session=session, device_addrs=[config_entry.data[CONF_HOST]]
|
||||
|
@ -7,6 +7,7 @@ from typing import Any
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
from python_awair import Awair, AwairLocal, AwairLocalDevice
|
||||
from python_awair.exceptions import AuthError, AwairError
|
||||
from python_awair.user import AwairUser
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
@ -97,7 +98,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
title = user.email
|
||||
return self.async_create_entry(title=title, data=user_input)
|
||||
|
||||
if error != "invalid_access_token":
|
||||
if error and error != "invalid_access_token":
|
||||
return self.async_abort(reason=error)
|
||||
|
||||
errors = {CONF_ACCESS_TOKEN: "invalid_access_token"}
|
||||
@ -215,7 +216,9 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def _check_local_connection(self, device_address: str):
|
||||
async def _check_local_connection(
|
||||
self, device_address: str
|
||||
) -> tuple[AwairLocalDevice | None, str | None]:
|
||||
"""Check the access token is valid."""
|
||||
session = async_get_clientsession(self.hass)
|
||||
awair = AwairLocal(session=session, device_addrs=[device_address])
|
||||
@ -232,7 +235,9 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
LOGGER.error("Unexpected API error: %s", err)
|
||||
return (None, "unknown")
|
||||
|
||||
async def _check_cloud_connection(self, access_token: str):
|
||||
async def _check_cloud_connection(
|
||||
self, access_token: str
|
||||
) -> tuple[AwairUser | None, str | None]:
|
||||
"""Check the access token is valid."""
|
||||
session = async_get_clientsession(self.hass)
|
||||
awair = Awair(access_token=access_token, session=session)
|
||||
|
@ -2,7 +2,7 @@
|
||||
"domain": "awair",
|
||||
"name": "Awair",
|
||||
"documentation": "https://www.home-assistant.io/integrations/awair",
|
||||
"requirements": ["python_awair==0.2.3"],
|
||||
"requirements": ["python_awair==0.2.4"],
|
||||
"codeowners": ["@ahayworth", "@danielsjf"],
|
||||
"config_flow": true,
|
||||
"iot_class": "local_polling",
|
||||
|
@ -2,11 +2,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from python_awair.air_data import AirData
|
||||
from python_awair.devices import AwairBaseDevice
|
||||
from python_awair.devices import AwairBaseDevice, AwairLocalDevice
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_CONNECTIONS, ATTR_NAME
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_CONNECTIONS,
|
||||
ATTR_NAME,
|
||||
ATTR_SW_VERSION,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
@ -209,6 +214,9 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
||||
(dr.CONNECTION_NETWORK_MAC, self._device.mac_address)
|
||||
}
|
||||
|
||||
if isinstance(self._device, AwairLocalDevice):
|
||||
info[ATTR_SW_VERSION] = self._device.fw_version
|
||||
|
||||
return info
|
||||
|
||||
@property
|
||||
|
10
mypy.ini
10
mypy.ini
@ -369,6 +369,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.awair.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.backup.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
@ -1981,7 +1981,7 @@ python-telegram-bot==13.1
|
||||
python-vlc==1.1.2
|
||||
|
||||
# homeassistant.components.awair
|
||||
python_awair==0.2.3
|
||||
python_awair==0.2.4
|
||||
|
||||
# homeassistant.components.swiss_public_transport
|
||||
python_opendata_transport==0.3.0
|
||||
|
@ -1347,7 +1347,7 @@ python-tado==0.12.0
|
||||
python-telegram-bot==13.1
|
||||
|
||||
# homeassistant.components.awair
|
||||
python_awair==0.2.3
|
||||
python_awair==0.2.4
|
||||
|
||||
# homeassistant.components.tile
|
||||
pytile==2022.02.0
|
||||
|
Reference in New Issue
Block a user