Add entity translations to Renson (#96040)

This commit is contained in:
Joost Lekkerkerker 2023-07-23 20:11:26 +02:00 committed by GitHub
parent dd6cd0096a
commit 54044161c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 152 additions and 38 deletions

View File

@ -50,6 +50,16 @@ from . import RensonCoordinator, RensonData
from .const import DOMAIN from .const import DOMAIN
from .entity import RensonEntity from .entity import RensonEntity
OPTIONS_MAPPING = {
"Off": "off",
"Level1": "level1",
"Level2": "level2",
"Level3": "level3",
"Level4": "level4",
"Breeze": "breeze",
"Holiday": "holiday",
}
@dataclass @dataclass
class RensonSensorEntityDescriptionMixin: class RensonSensorEntityDescriptionMixin:
@ -63,13 +73,13 @@ class RensonSensorEntityDescriptionMixin:
class RensonSensorEntityDescription( class RensonSensorEntityDescription(
SensorEntityDescription, RensonSensorEntityDescriptionMixin SensorEntityDescription, RensonSensorEntityDescriptionMixin
): ):
"""Description of sensor.""" """Description of a Renson sensor."""
SENSORS: tuple[RensonSensorEntityDescription, ...] = ( SENSORS: tuple[RensonSensorEntityDescription, ...] = (
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CO2_QUALITY_FIELD", key="CO2_QUALITY_FIELD",
name="CO2 quality category", translation_key="co2_quality_category",
field=CO2_QUALITY_FIELD, field=CO2_QUALITY_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
@ -77,7 +87,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="AIR_QUALITY_FIELD", key="AIR_QUALITY_FIELD",
name="Air quality category", translation_key="air_quality_category",
field=AIR_QUALITY_FIELD, field=AIR_QUALITY_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
@ -85,7 +95,6 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CO2_FIELD", key="CO2_FIELD",
name="CO2 quality",
field=CO2_FIELD, field=CO2_FIELD,
raw_format=True, raw_format=True,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -94,7 +103,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="AIR_FIELD", key="AIR_FIELD",
name="Air quality", translation_key="air_quality",
field=AIR_QUALITY_FIELD, field=AIR_QUALITY_FIELD,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
raw_format=True, raw_format=True,
@ -102,15 +111,15 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CURRENT_LEVEL_FIELD", key="CURRENT_LEVEL_FIELD",
name="Ventilation level", translation_key="ventilation_level",
field=CURRENT_LEVEL_FIELD, field=CURRENT_LEVEL_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=["Off", "Level1", "Level2", "Level3", "Level4", "Breeze", "Holiday"], options=["off", "level1", "level2", "level3", "level4", "breeze", "holiday"],
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CURRENT_AIRFLOW_EXTRACT_FIELD", key="CURRENT_AIRFLOW_EXTRACT_FIELD",
name="Total airflow out", translation_key="total_airflow_out",
field=CURRENT_AIRFLOW_EXTRACT_FIELD, field=CURRENT_AIRFLOW_EXTRACT_FIELD,
raw_format=False, raw_format=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -118,7 +127,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CURRENT_AIRFLOW_INGOING_FIELD", key="CURRENT_AIRFLOW_INGOING_FIELD",
name="Total airflow in", translation_key="total_airflow_in",
field=CURRENT_AIRFLOW_INGOING_FIELD, field=CURRENT_AIRFLOW_INGOING_FIELD,
raw_format=False, raw_format=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -126,7 +135,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="OUTDOOR_TEMP_FIELD", key="OUTDOOR_TEMP_FIELD",
name="Outdoor air temperature", translation_key="outdoor_air_temperature",
field=OUTDOOR_TEMP_FIELD, field=OUTDOOR_TEMP_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
@ -135,7 +144,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="INDOOR_TEMP_FIELD", key="INDOOR_TEMP_FIELD",
name="Extract air temperature", translation_key="extract_air_temperature",
field=INDOOR_TEMP_FIELD, field=INDOOR_TEMP_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
@ -144,7 +153,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="FILTER_REMAIN_FIELD", key="FILTER_REMAIN_FIELD",
name="Filter change", translation_key="filter_change",
field=FILTER_REMAIN_FIELD, field=FILTER_REMAIN_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
@ -153,7 +162,6 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="HUMIDITY_FIELD", key="HUMIDITY_FIELD",
name="Relative humidity",
field=HUMIDITY_FIELD, field=HUMIDITY_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
@ -162,15 +170,15 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="MANUAL_LEVEL_FIELD", key="MANUAL_LEVEL_FIELD",
name="Manual level", translation_key="manual_level",
field=MANUAL_LEVEL_FIELD, field=MANUAL_LEVEL_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=["Off", "Level1", "Level2", "Level3", "Level4", "Breeze", "Holiday"], options=["off", "level1", "level2", "level3", "level4", "breeze", "holiday"],
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="BREEZE_TEMPERATURE_FIELD", key="BREEZE_TEMPERATURE_FIELD",
name="Breeze temperature", translation_key="breeze_temperature",
field=BREEZE_TEMPERATURE_FIELD, field=BREEZE_TEMPERATURE_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
@ -179,58 +187,48 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="BREEZE_LEVEL_FIELD", key="BREEZE_LEVEL_FIELD",
name="Breeze level", translation_key="breeze_level",
field=BREEZE_LEVEL_FIELD, field=BREEZE_LEVEL_FIELD,
raw_format=False, raw_format=False,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=["Off", "Level1", "Level2", "Level3", "Level4", "Breeze"], options=["off", "level1", "level2", "level3", "level4", "breeze"],
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="DAYTIME_FIELD", key="DAYTIME_FIELD",
name="Start day time", translation_key="start_day_time",
field=DAYTIME_FIELD, field=DAYTIME_FIELD,
raw_format=False, raw_format=False,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="NIGHTTIME_FIELD", key="NIGHTTIME_FIELD",
name="Start night time", translation_key="start_night_time",
field=NIGHTTIME_FIELD, field=NIGHTTIME_FIELD,
raw_format=False, raw_format=False,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="DAY_POLLUTION_FIELD", key="DAY_POLLUTION_FIELD",
name="Day pollution level", translation_key="day_pollution_level",
field=DAY_POLLUTION_FIELD, field=DAY_POLLUTION_FIELD,
raw_format=False, raw_format=False,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=[ options=["level1", "level2", "level3", "level4"],
"Level1",
"Level2",
"Level3",
"Level4",
],
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="NIGHT_POLLUTION_FIELD", key="NIGHT_POLLUTION_FIELD",
name="Night pollution level", translation_key="co2_quality_category",
field=NIGHT_POLLUTION_FIELD, field=NIGHT_POLLUTION_FIELD,
raw_format=False, raw_format=False,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=[ options=["level1", "level2", "level3", "level4"],
"Level1",
"Level2",
"Level3",
"Level4",
],
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CO2_THRESHOLD_FIELD", key="CO2_THRESHOLD_FIELD",
name="CO2 threshold", translation_key="co2_threshold",
field=CO2_THRESHOLD_FIELD, field=CO2_THRESHOLD_FIELD,
raw_format=False, raw_format=False,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION, native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
@ -238,7 +236,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="CO2_HYSTERESIS_FIELD", key="CO2_HYSTERESIS_FIELD",
name="CO2 hysteresis", translation_key="co2_hysteresis",
field=CO2_HYSTERESIS_FIELD, field=CO2_HYSTERESIS_FIELD,
raw_format=False, raw_format=False,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION, native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
@ -246,7 +244,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="BYPASS_TEMPERATURE_FIELD", key="BYPASS_TEMPERATURE_FIELD",
name="Bypass activation temperature", translation_key="bypass_activation_temperature",
field=BYPASS_TEMPERATURE_FIELD, field=BYPASS_TEMPERATURE_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
@ -255,7 +253,7 @@ SENSORS: tuple[RensonSensorEntityDescription, ...] = (
), ),
RensonSensorEntityDescription( RensonSensorEntityDescription(
key="BYPASS_LEVEL_FIELD", key="BYPASS_LEVEL_FIELD",
name="Bypass level", translation_key="bypass_level",
field=BYPASS_LEVEL_FIELD, field=BYPASS_LEVEL_FIELD,
raw_format=False, raw_format=False,
device_class=SensorDeviceClass.POWER_FACTOR, device_class=SensorDeviceClass.POWER_FACTOR,
@ -292,6 +290,10 @@ class RensonSensor(RensonEntity, SensorEntity):
if self.raw_format: if self.raw_format:
self._attr_native_value = value self._attr_native_value = value
elif self.entity_description.device_class == SensorDeviceClass.ENUM:
self._attr_native_value = OPTIONS_MAPPING.get(
self.api.parse_value(value, self.data_type), None
)
else: else:
self._attr_native_value = self.api.parse_value(value, self.data_type) self._attr_native_value = self.api.parse_value(value, self.data_type)

View File

@ -11,5 +11,117 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"unknown": "[%key:common::config_flow::error::unknown%]" "unknown": "[%key:common::config_flow::error::unknown%]"
} }
},
"entity": {
"sensor": {
"co2_quality_category": {
"name": "CO2 quality category",
"state": {
"good": "Good",
"bad": "Bad",
"poor": "Poor"
}
},
"air_quality_category": {
"name": "Air quality category",
"state": {
"good": "[%key:component::renson::entity::sensor::co2_quality_category::state::good%]",
"bad": "[%key:component::renson::entity::sensor::co2_quality_category::state::bad%]",
"poor": "[%key:component::renson::entity::sensor::co2_quality_category::state::poor%]"
}
},
"air_quality": {
"name": "Air quality"
},
"ventilation_level": {
"name": "Ventilation level",
"state": {
"off": "[%key:common::state::off%]",
"level1": "Level 1",
"level2": "Level 2",
"level3": "Level 3",
"level4": "Level 4",
"breeze": "Breeze",
"holiday": "Holiday"
}
},
"total_airflow_out": {
"name": "Total airflow out"
},
"total_airflow_in": {
"name": "Total airflow in"
},
"outdoor_air_temperature": {
"name": "Outdoor air temperature"
},
"extract_air_temperature": {
"name": "Extract air temperature"
},
"filter_change": {
"name": "Filter change"
},
"manual_level": {
"name": "Manual level",
"state": {
"off": "[%key:common::state::off%]",
"level1": "[%key:component::renson::entity::sensor::ventilation_level::state::level1%]",
"level2": "[%key:component::renson::entity::sensor::ventilation_level::state::level2%]",
"level3": "[%key:component::renson::entity::sensor::ventilation_level::state::level3%]",
"level4": "[%key:component::renson::entity::sensor::ventilation_level::state::level4%]",
"breeze": "[%key:component::renson::entity::sensor::ventilation_level::state::breeze%]",
"holiday": "[%key:component::renson::entity::sensor::ventilation_level::state::holiday%]"
}
},
"breeze_temperature": {
"name": "Breeze temperature"
},
"breeze_level": {
"name": "Breeze level",
"state": {
"off": "[%key:common::state::off%]",
"level1": "[%key:component::renson::entity::sensor::ventilation_level::state::level1%]",
"level2": "[%key:component::renson::entity::sensor::ventilation_level::state::level2%]",
"level3": "[%key:component::renson::entity::sensor::ventilation_level::state::level3%]",
"level4": "[%key:component::renson::entity::sensor::ventilation_level::state::level4%]",
"breeze": "[%key:component::renson::entity::sensor::ventilation_level::state::breeze%]"
}
},
"start_day_time": {
"name": "Start day time"
},
"start_night_time": {
"name": "Start night time"
},
"day_pollution_level": {
"name": "Day pollution level",
"state": {
"level1": "[%key:component::renson::entity::sensor::ventilation_level::state::level1%]",
"level2": "[%key:component::renson::entity::sensor::ventilation_level::state::level2%]",
"level3": "[%key:component::renson::entity::sensor::ventilation_level::state::level3%]",
"level4": "[%key:component::renson::entity::sensor::ventilation_level::state::level4%]"
}
},
"night_pollution_level": {
"name": "Night pollution level",
"state": {
"level1": "[%key:component::renson::entity::sensor::ventilation_level::state::level1%]",
"level2": "[%key:component::renson::entity::sensor::ventilation_level::state::level2%]",
"level3": "[%key:component::renson::entity::sensor::ventilation_level::state::level3%]",
"level4": "[%key:component::renson::entity::sensor::ventilation_level::state::level4%]"
}
},
"co2_threshold": {
"name": "CO2 threshold"
},
"co2_hysteresis": {
"name": "CO2 hysteresis"
},
"bypass_activation_temperature": {
"name": "Bypass activation temperature"
},
"bypass_level": {
"name": "Bypass level"
}
}
} }
} }