Add entity translations to Mill (#96541)

This commit is contained in:
Joost Lekkerkerker 2023-08-31 10:13:39 +02:00 committed by GitHub
parent e08661dad3
commit c25b3e55e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 15 deletions

View file

@ -44,17 +44,17 @@ from .const import (
HEATER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key=CONSUMPTION_YEAR,
translation_key="year_consumption",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
name="Year consumption",
),
SensorEntityDescription(
key=CONSUMPTION_TODAY,
translation_key="day_consumption",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
name="Day consumption",
),
)
@ -63,21 +63,18 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key=TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
name="Temperature",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=HUMIDITY,
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
name="Humidity",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=BATTERY,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
name="Battery",
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
),
@ -85,13 +82,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key=ECO2,
device_class=SensorDeviceClass.CO2,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
name="Estimated CO2",
translation_key="estimated_co2",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=TVOC,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
name="TVOC",
translation_key="tvoc",
state_class=SensorStateClass.MEASUREMENT,
),
)
@ -99,22 +96,22 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="control_signal",
translation_key="control_signal",
native_unit_of_measurement=PERCENTAGE,
name="Control signal",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="current_power",
translation_key="current_power",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
name="Current power",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="raw_ambient_temperature",
translation_key="uncalibrated_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
name="Uncalibrated temperature",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
@ -159,6 +156,8 @@ async def async_setup_entry(
class MillSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Mill Sensor device."""
_attr_has_entity_name = True
def __init__(self, coordinator, entity_description, mill_device):
"""Initialize the sensor."""
super().__init__(coordinator)
@ -166,8 +165,6 @@ class MillSensor(CoordinatorEntity, SensorEntity):
self._id = mill_device.device_id
self.entity_description = entity_description
self._available = False
self._attr_name = f"{mill_device.name} {entity_description.name}"
self._attr_unique_id = f"{mill_device.device_id}_{entity_description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, mill_device.device_id)},
@ -197,14 +194,13 @@ class MillSensor(CoordinatorEntity, SensorEntity):
class LocalMillSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Mill Sensor device."""
_attr_has_entity_name = True
def __init__(self, coordinator, entity_description):
"""Initialize the sensor."""
super().__init__(coordinator)
self.entity_description = entity_description
self._attr_name = (
f"{coordinator.mill_data_connection.name} {entity_description.name}"
)
if mac := coordinator.mill_data_connection.mac_address:
self._attr_unique_id = f"{mac}_{entity_description.key}"
self._attr_device_info = DeviceInfo(