Name unnamed binary sensors by their device class (#92940)

* Name unnamed binary sensors by their device class

* Update type annotations

* Fix loading of entity component translations

* Add test

* Update integrations

* Set abode and rfxtrx binary_sensor name to None

* Revert changes in homekit_controller
This commit is contained in:
Erik Montnemery 2023-06-13 19:48:54 +02:00 committed by GitHub
parent 223394eaee
commit 2406b235b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 287 additions and 47 deletions

View file

@ -1,6 +1,8 @@
"""Support for Aranet sensors."""
from __future__ import annotations
from dataclasses import dataclass
from aranet4.client import Aranet4Advertisement
from bleak.backends.device import BLEDevice
@ -33,43 +35,54 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
@dataclass
class AranetSensorEntityDescription(SensorEntityDescription):
"""Class to describe an Aranet sensor entity."""
# PassiveBluetoothDataUpdate does not support UNDEFINED
# Restrict the type to satisfy the type checker and catch attempts
# to use UNDEFINED in the entity descriptions.
name: str | None = None
SENSOR_DESCRIPTIONS = {
"temperature": SensorEntityDescription(
"temperature": AranetSensorEntityDescription(
key="temperature",
name="Temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
"humidity": SensorEntityDescription(
"humidity": AranetSensorEntityDescription(
key="humidity",
name="Humidity",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
"pressure": SensorEntityDescription(
"pressure": AranetSensorEntityDescription(
key="pressure",
name="Pressure",
device_class=SensorDeviceClass.PRESSURE,
native_unit_of_measurement=UnitOfPressure.HPA,
state_class=SensorStateClass.MEASUREMENT,
),
"co2": SensorEntityDescription(
"co2": AranetSensorEntityDescription(
key="co2",
name="Carbon Dioxide",
device_class=SensorDeviceClass.CO2,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=SensorStateClass.MEASUREMENT,
),
"battery": SensorEntityDescription(
"battery": AranetSensorEntityDescription(
key="battery",
name="Battery",
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
"interval": SensorEntityDescription(
"interval": AranetSensorEntityDescription(
key="update_interval",
name="Update Interval",
device_class=SensorDeviceClass.DURATION,