Add entity name translations to GIOS (#90655)

* Add entity name translations

* Update tests
This commit is contained in:
Maciej Bieniek 2023-04-02 20:25:38 +02:00 committed by GitHub
parent d32fb7c22f
commit fc81b82932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 32 deletions

View File

@ -60,7 +60,6 @@ class GiosSensorEntityDescription(SensorEntityDescription, GiosSensorRequiredKey
SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
GiosSensorEntityDescription(
key=ATTR_AQI,
name="AQI",
value=lambda sensors: sensors.aqi.value if sensors.aqi else None,
icon="mdi:air-filter",
device_class=SensorDeviceClass.ENUM,
@ -69,35 +68,34 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
),
GiosSensorEntityDescription(
key=ATTR_C6H6,
name="C6H6",
value=lambda sensors: sensors.c6h6.value if sensors.c6h6 else None,
suggested_display_precision=0,
icon="mdi:molecule",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="c6h6",
),
GiosSensorEntityDescription(
key=ATTR_CO,
name="CO",
value=lambda sensors: sensors.co.value if sensors.co else None,
suggested_display_precision=0,
icon="mdi:molecule",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="co",
),
GiosSensorEntityDescription(
key=ATTR_NO2,
name="NO2",
value=lambda sensors: sensors.no2.value if sensors.no2 else None,
suggested_display_precision=0,
device_class=SensorDeviceClass.NITROGEN_DIOXIDE,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="no2",
),
GiosSensorEntityDescription(
key=ATTR_NO2,
subkey="index",
name="NO2 index",
value=lambda sensors: sensors.no2.index if sensors.no2 else None,
icon="mdi:molecule",
device_class=SensorDeviceClass.ENUM,
@ -106,17 +104,16 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
),
GiosSensorEntityDescription(
key=ATTR_O3,
name="O3",
value=lambda sensors: sensors.o3.value if sensors.o3 else None,
suggested_display_precision=0,
device_class=SensorDeviceClass.OZONE,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="o3",
),
GiosSensorEntityDescription(
key=ATTR_O3,
subkey="index",
name="O3 index",
value=lambda sensors: sensors.o3.index if sensors.o3 else None,
icon="mdi:molecule",
device_class=SensorDeviceClass.ENUM,
@ -125,17 +122,16 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
),
GiosSensorEntityDescription(
key=ATTR_PM10,
name="PM10",
value=lambda sensors: sensors.pm10.value if sensors.pm10 else None,
suggested_display_precision=0,
device_class=SensorDeviceClass.PM10,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pm10",
),
GiosSensorEntityDescription(
key=ATTR_PM10,
subkey="index",
name="PM10 index",
value=lambda sensors: sensors.pm10.index if sensors.pm10 else None,
icon="mdi:molecule",
device_class=SensorDeviceClass.ENUM,
@ -144,17 +140,16 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
),
GiosSensorEntityDescription(
key=ATTR_PM25,
name="PM2.5",
value=lambda sensors: sensors.pm25.value if sensors.pm25 else None,
suggested_display_precision=0,
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="pm25",
),
GiosSensorEntityDescription(
key=ATTR_PM25,
subkey="index",
name="PM2.5 index",
value=lambda sensors: sensors.pm25.index if sensors.pm25 else None,
icon="mdi:molecule",
device_class=SensorDeviceClass.ENUM,
@ -163,17 +158,16 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = (
),
GiosSensorEntityDescription(
key=ATTR_SO2,
name="SO2",
value=lambda sensors: sensors.so2.value if sensors.so2 else None,
suggested_display_precision=0,
device_class=SensorDeviceClass.SULPHUR_DIOXIDE,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
translation_key="so2",
),
GiosSensorEntityDescription(
key=ATTR_SO2,
subkey="index",
name="SO2 index",
value=lambda sensors: sensors.so2.index if sensors.so2 else None,
icon="mdi:molecule",
device_class=SensorDeviceClass.ENUM,

View File

@ -26,6 +26,7 @@
"entity": {
"sensor": {
"aqi": {
"name": "AQI",
"state": {
"very_bad": "Very bad",
"bad": "Bad",
@ -35,7 +36,17 @@
"very_good": "Very good"
}
},
"c6h6": {
"name": "Benzene"
},
"co": {
"name": "Carbon monoxide"
},
"no2": {
"name": "Nitrogen dioxide"
},
"no2_index": {
"name": "Nitrogen dioxide index",
"state": {
"very_bad": "[%key:component::gios::entity::sensor::aqi::state::very_bad%]",
"bad": "[%key:component::gios::entity::sensor::aqi::state::bad%]",
@ -45,7 +56,11 @@
"very_good": "[%key:component::gios::entity::sensor::aqi::state::very_good%]"
}
},
"o3": {
"name": "Ozone"
},
"o3_index": {
"name": "Ozone index",
"state": {
"very_bad": "[%key:component::gios::entity::sensor::aqi::state::very_bad%]",
"bad": "[%key:component::gios::entity::sensor::aqi::state::bad%]",
@ -55,7 +70,11 @@
"very_good": "[%key:component::gios::entity::sensor::aqi::state::very_good%]"
}
},
"pm10": {
"name": "PM10"
},
"pm10_index": {
"name": "PM10 index",
"state": {
"very_bad": "[%key:component::gios::entity::sensor::aqi::state::very_bad%]",
"bad": "[%key:component::gios::entity::sensor::aqi::state::bad%]",
@ -65,7 +84,11 @@
"very_good": "[%key:component::gios::entity::sensor::aqi::state::very_good%]"
}
},
"pm25": {
"name": "PM2.5"
},
"pm25_index": {
"name": "PM2.5 index",
"state": {
"very_bad": "[%key:component::gios::entity::sensor::aqi::state::very_bad%]",
"bad": "[%key:component::gios::entity::sensor::aqi::state::bad%]",
@ -75,7 +98,11 @@
"very_good": "[%key:component::gios::entity::sensor::aqi::state::very_good%]"
}
},
"so2": {
"name": "Sulphur dioxide"
},
"so2_index": {
"name": "Sulphur dioxide index",
"state": {
"very_bad": "[%key:component::gios::entity::sensor::aqi::state::very_bad%]",
"bad": "[%key:component::gios::entity::sensor::aqi::state::bad%]",

View File

@ -35,7 +35,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
await init_integration(hass)
registry = er.async_get(hass)
state = hass.states.get("sensor.home_c6h6")
state = hass.states.get("sensor.home_benzene")
assert state
assert state.state == "0.23789"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -46,11 +46,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
)
assert state.attributes.get(ATTR_ICON) == "mdi:molecule"
entry = registry.async_get("sensor.home_c6h6")
entry = registry.async_get("sensor.home_benzene")
assert entry
assert entry.unique_id == "123-c6h6"
state = hass.states.get("sensor.home_co")
state = hass.states.get("sensor.home_carbon_monoxide")
assert state
assert state.state == "251.874"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -61,11 +61,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get("sensor.home_co")
entry = registry.async_get("sensor.home_carbon_monoxide")
assert entry
assert entry.unique_id == "123-co"
state = hass.states.get("sensor.home_no2")
state = hass.states.get("sensor.home_nitrogen_dioxide")
assert state
assert state.state == "7.13411"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -76,11 +76,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get("sensor.home_no2")
entry = registry.async_get("sensor.home_nitrogen_dioxide")
assert entry
assert entry.unique_id == "123-no2"
state = hass.states.get("sensor.home_no2_index")
state = hass.states.get("sensor.home_nitrogen_dioxide_index")
assert state
assert state.state == "good"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -94,11 +94,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
"very_good",
]
entry = registry.async_get("sensor.home_no2_index")
entry = registry.async_get("sensor.home_nitrogen_dioxide_index")
assert entry
assert entry.unique_id == "123-no2-index"
state = hass.states.get("sensor.home_o3")
state = hass.states.get("sensor.home_ozone")
assert state
assert state.state == "95.7768"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -109,11 +109,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get("sensor.home_o3")
entry = registry.async_get("sensor.home_ozone")
assert entry
assert entry.unique_id == "123-o3"
state = hass.states.get("sensor.home_o3_index")
state = hass.states.get("sensor.home_ozone_index")
assert state
assert state.state == "good"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -127,7 +127,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
"very_good",
]
entry = registry.async_get("sensor.home_o3_index")
entry = registry.async_get("sensor.home_ozone_index")
assert entry
assert entry.unique_id == "123-o3-index"
@ -197,7 +197,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert entry
assert entry.unique_id == "123-pm25-index"
state = hass.states.get("sensor.home_so2")
state = hass.states.get("sensor.home_sulphur_dioxide")
assert state
assert state.state == "4.35478"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -208,11 +208,11 @@ async def test_sensor(hass: HomeAssistant) -> None:
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get("sensor.home_so2")
entry = registry.async_get("sensor.home_sulphur_dioxide")
assert entry
assert entry.unique_id == "123-so2"
state = hass.states.get("sensor.home_so2_index")
state = hass.states.get("sensor.home_sulphur_dioxide_index")
assert state
assert state.state == "very_good"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
@ -226,7 +226,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
"very_good",
]
entry = registry.async_get("sensor.home_so2_index")
entry = registry.async_get("sensor.home_sulphur_dioxide_index")
assert entry
assert entry.unique_id == "123-so2-index"
@ -341,11 +341,11 @@ async def test_invalid_indexes(hass: HomeAssistant) -> None:
"""Test states of the sensor when API returns invalid indexes."""
await init_integration(hass, invalid_indexes=True)
state = hass.states.get("sensor.home_no2_index")
state = hass.states.get("sensor.home_nitrogen_dioxide_index")
assert state
assert state.state == STATE_UNAVAILABLE
state = hass.states.get("sensor.home_o3_index")
state = hass.states.get("sensor.home_ozone_index")
assert state
assert state.state == STATE_UNAVAILABLE
@ -357,7 +357,7 @@ async def test_invalid_indexes(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_UNAVAILABLE
state = hass.states.get("sensor.home_so2_index")
state = hass.states.get("sensor.home_sulphur_dioxide_index")
assert state
assert state.state == STATE_UNAVAILABLE