Awair local use config entry name + add measurement state class (#77383)
This commit is contained in:
parent
481205535c
commit
79b5147b46
6 changed files with 85 additions and 33 deletions
|
@ -1,17 +1,14 @@
|
|||
"""Support for Awair sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
|
||||
from python_awair.air_data import AirData
|
||||
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,
|
||||
ATTR_SW_VERSION,
|
||||
)
|
||||
from homeassistant.const import ATTR_CONNECTIONS, ATTR_SW_VERSION
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -78,6 +75,8 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
|||
"""Defines an Awair sensor entity."""
|
||||
|
||||
entity_description: AwairSensorEntityDescription
|
||||
_attr_has_entity_name = True
|
||||
_attr_attribution = ATTRIBUTION
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -90,14 +89,6 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
|||
self.entity_description = description
|
||||
self._device = device
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the name of the sensor."""
|
||||
if self._device.name:
|
||||
return f"{self._device.name} {self.entity_description.name}"
|
||||
|
||||
return self.entity_description.name
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return the uuid as the unique_id."""
|
||||
|
@ -187,7 +178,7 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
|||
https://docs.developer.getawair.com/?version=latest#awair-score-and-index
|
||||
"""
|
||||
sensor_type = self.entity_description.key
|
||||
attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
attrs: dict = {}
|
||||
if not self._air_data:
|
||||
return attrs
|
||||
if sensor_type in self._air_data.indices:
|
||||
|
@ -204,11 +195,13 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
|||
identifiers={(DOMAIN, self._device.uuid)},
|
||||
manufacturer="Awair",
|
||||
model=self._device.model,
|
||||
name=(
|
||||
self._device.name
|
||||
or cast(ConfigEntry, self.coordinator.config_entry).title
|
||||
or f"{self._device.model} ({self._device.device_id})"
|
||||
),
|
||||
)
|
||||
|
||||
if self._device.name:
|
||||
info[ATTR_NAME] = self._device.name
|
||||
|
||||
if self._device.mac_address:
|
||||
info[ATTR_CONNECTIONS] = {
|
||||
(dr.CONNECTION_NETWORK_MAC, self._device.mac_address)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue