Add entity name translations to Broadlink sensors (#90783)

* Add entity name translations to Broadlink sensors

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Update tests

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Apply suggestions from code review

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Patrick ZAJDA 2023-04-04 21:18:41 +02:00 committed by Paulus Schoutsen
parent af34e25c89
commit 9f7b2ba6c1
3 changed files with 50 additions and 16 deletions

View File

@ -25,61 +25,61 @@ from .entity import BroadlinkEntity
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="temperature",
name="Temperature",
translation_key="temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="air_quality",
name="Air quality",
translation_key="air_quality",
),
SensorEntityDescription(
key="humidity",
name="Humidity",
translation_key="humidity",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="light",
name="Light",
translation_key="light",
),
SensorEntityDescription(
key="noise",
name="Noise",
translation_key="noise",
),
SensorEntityDescription(
key="power",
name="Current power",
translation_key="power",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="volt",
name="Voltage",
translation_key="voltage",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="current",
name="Current",
translation_key="current",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="overload",
name="Overload",
translation_key="overload",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="totalconsum",
name="Total consumption",
translation_key="total_consumption",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,

View File

@ -43,5 +43,39 @@
"invalid_host": "[%key:common::config_flow::error::invalid_host%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"entity": {
"sensor": {
"temperature": {
"name": "[%key:component::sensor::entity_component::temperature::name%]"
},
"air_quality": {
"name": "[%key:component::sensor::entity_component::aqi::name%]"
},
"humidity": {
"name": "[%key:component::sensor::entity_component::humidity::name%]"
},
"light": {
"name": "[%key:component::sensor::entity_component::illuminance::name%]"
},
"noise": {
"name": "Noise"
},
"power": {
"name": "[%key:component::sensor::entity_component::power::name%]"
},
"voltage": {
"name": "[%key:component::sensor::entity_component::voltage::name%]"
},
"current": {
"name": "[%key:component::sensor::entity_component::current::name%]"
},
"overload": {
"name": "Overload"
},
"total_consumption": {
"name": "Total consumption"
}
}
}
}

View File

@ -50,8 +50,8 @@ async def test_a1_sensor_setup(
assert sensors_and_states == {
(f"{device.name} Temperature", "27.4"),
(f"{device.name} Humidity", "59.3"),
(f"{device.name} Air quality", "3"),
(f"{device.name} Light", "2"),
(f"{device.name} Air quality index", "3"),
(f"{device.name} Illuminance", "2"),
(f"{device.name} Noise", "1"),
}
@ -101,8 +101,8 @@ async def test_a1_sensor_update(
assert sensors_and_states == {
(f"{device.name} Temperature", "22.5"),
(f"{device.name} Humidity", "47.4"),
(f"{device.name} Air quality", "2"),
(f"{device.name} Light", "3"),
(f"{device.name} Air quality index", "2"),
(f"{device.name} Illuminance", "3"),
(f"{device.name} Noise", "2"),
}
@ -355,7 +355,7 @@ async def test_scb1e_sensor_setup(
for sensor in sensors
}
assert sensors_and_states == {
(f"{device.name} Current power", "255.57"),
(f"{device.name} Power", "255.57"),
(f"{device.name} Voltage", "121.7"),
(f"{device.name} Current", "2.1"),
(f"{device.name} Overload", "0"),
@ -421,7 +421,7 @@ async def test_scb1e_sensor_update(
for sensor in sensors
}
assert sensors_and_states == {
(f"{device.name} Current power", "291.8"),
(f"{device.name} Power", "291.8"),
(f"{device.name} Voltage", "121.6"),
(f"{device.name} Current", "2.4"),
(f"{device.name} Overload", "0"),