Add entity translations to Mill (#96541)
This commit is contained in:
parent
e08661dad3
commit
c25b3e55e4
2 changed files with 36 additions and 15 deletions
|
@ -44,17 +44,17 @@ from .const import (
|
||||||
HEATER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
HEATER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=CONSUMPTION_YEAR,
|
key=CONSUMPTION_YEAR,
|
||||||
|
translation_key="year_consumption",
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
name="Year consumption",
|
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=CONSUMPTION_TODAY,
|
key=CONSUMPTION_TODAY,
|
||||||
|
translation_key="day_consumption",
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
name="Day consumption",
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,21 +63,18 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
key=TEMPERATURE,
|
key=TEMPERATURE,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
name="Temperature",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=HUMIDITY,
|
key=HUMIDITY,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
name="Humidity",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=BATTERY,
|
key=BATTERY,
|
||||||
device_class=SensorDeviceClass.BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
name="Battery",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
|
@ -85,13 +82,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
key=ECO2,
|
key=ECO2,
|
||||||
device_class=SensorDeviceClass.CO2,
|
device_class=SensorDeviceClass.CO2,
|
||||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||||
name="Estimated CO2",
|
translation_key="estimated_co2",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key=TVOC,
|
key=TVOC,
|
||||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
|
||||||
name="TVOC",
|
translation_key="tvoc",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -99,22 +96,22 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
LOCAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="control_signal",
|
key="control_signal",
|
||||||
|
translation_key="control_signal",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
name="Control signal",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="current_power",
|
key="current_power",
|
||||||
|
translation_key="current_power",
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
name="Current power",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="raw_ambient_temperature",
|
key="raw_ambient_temperature",
|
||||||
|
translation_key="uncalibrated_temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
name="Uncalibrated temperature",
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
|
@ -159,6 +156,8 @@ async def async_setup_entry(
|
||||||
class MillSensor(CoordinatorEntity, SensorEntity):
|
class MillSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Mill Sensor device."""
|
"""Representation of a Mill Sensor device."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, coordinator, entity_description, mill_device):
|
def __init__(self, coordinator, entity_description, mill_device):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
@ -166,8 +165,6 @@ class MillSensor(CoordinatorEntity, SensorEntity):
|
||||||
self._id = mill_device.device_id
|
self._id = mill_device.device_id
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
self._available = False
|
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_unique_id = f"{mill_device.device_id}_{entity_description.key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, mill_device.device_id)},
|
identifiers={(DOMAIN, mill_device.device_id)},
|
||||||
|
@ -197,14 +194,13 @@ class MillSensor(CoordinatorEntity, SensorEntity):
|
||||||
class LocalMillSensor(CoordinatorEntity, SensorEntity):
|
class LocalMillSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Mill Sensor device."""
|
"""Representation of a Mill Sensor device."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, coordinator, entity_description):
|
def __init__(self, coordinator, entity_description):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self.entity_description = entity_description
|
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:
|
if mac := coordinator.mill_data_connection.mac_address:
|
||||||
self._attr_unique_id = f"{mac}_{entity_description.key}"
|
self._attr_unique_id = f"{mac}_{entity_description.key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
|
|
|
@ -27,6 +27,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"year_consumption": {
|
||||||
|
"name": "Year consumption"
|
||||||
|
},
|
||||||
|
"day_consumption": {
|
||||||
|
"name": "Day consumption"
|
||||||
|
},
|
||||||
|
"estimated_co2": {
|
||||||
|
"name": "Estimated CO2"
|
||||||
|
},
|
||||||
|
"tvoc": {
|
||||||
|
"name": "TVOC"
|
||||||
|
},
|
||||||
|
"control_signal": {
|
||||||
|
"name": "Control signal"
|
||||||
|
},
|
||||||
|
"current_power": {
|
||||||
|
"name": "Current power"
|
||||||
|
},
|
||||||
|
"uncalibrated_temperature": {
|
||||||
|
"name": "Uncalibrated temperature"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"set_room_temperature": {
|
"set_room_temperature": {
|
||||||
"name": "Set room temperature",
|
"name": "Set room temperature",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue