Add tomorrow.io state translations and dynamically assign enum device class (#96603)

* Add state translations and dynamically assign enum device class

* Reference existing keys

* Handle additional entity descriptions
pull/96890/head
Raman Gupta 2023-07-19 03:50:09 -04:00 committed by GitHub
parent 87d0b026c2
commit 67e3203d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 28 deletions

View File

@ -95,6 +95,10 @@ class TomorrowioSensorEntityDescription(SensorEntityDescription):
"they must both be None"
)
if self.value_map is not None:
self.device_class = SensorDeviceClass.ENUM
self.options = [item.name.lower() for item in self.value_map]
# From https://cfpub.epa.gov/ncer_abstracts/index.cfm/fuseaction/display.files/fileID/14285
# x ug/m^3 = y ppb * molecular weight / 24.45
@ -176,8 +180,6 @@ SENSOR_TYPES = (
key=TMRW_ATTR_PRECIPITATION_TYPE,
name="Precipitation Type",
value_map=PrecipitationType,
device_class=SensorDeviceClass.ENUM,
options=["freezing_rain", "ice_pellets", "none", "rain", "snow"],
translation_key="precipitation_type",
icon="mdi:weather-snowy-rainy",
),
@ -237,20 +239,12 @@ SENSOR_TYPES = (
key=TMRW_ATTR_EPA_PRIMARY_POLLUTANT,
name="US EPA Primary Pollutant",
value_map=PrimaryPollutantType,
translation_key="primary_pollutant",
),
TomorrowioSensorEntityDescription(
key=TMRW_ATTR_EPA_HEALTH_CONCERN,
name="US EPA Health Concern",
value_map=HealthConcernType,
device_class=SensorDeviceClass.ENUM,
options=[
"good",
"hazardous",
"moderate",
"unhealthy_for_sensitive_groups",
"unhealthy",
"very_unhealthy",
],
translation_key="health_concern",
icon="mdi:hospital",
),
@ -263,20 +257,12 @@ SENSOR_TYPES = (
key=TMRW_ATTR_CHINA_PRIMARY_POLLUTANT,
name="China MEP Primary Pollutant",
value_map=PrimaryPollutantType,
translation_key="primary_pollutant",
),
TomorrowioSensorEntityDescription(
key=TMRW_ATTR_CHINA_HEALTH_CONCERN,
name="China MEP Health Concern",
value_map=HealthConcernType,
device_class=SensorDeviceClass.ENUM,
options=[
"good",
"hazardous",
"moderate",
"unhealthy_for_sensitive_groups",
"unhealthy",
"very_unhealthy",
],
translation_key="health_concern",
icon="mdi:hospital",
),
@ -284,8 +270,6 @@ SENSOR_TYPES = (
key=TMRW_ATTR_POLLEN_TREE,
name="Tree Pollen Index",
value_map=PollenIndex,
device_class=SensorDeviceClass.ENUM,
options=["high", "low", "medium", "none", "very_high", "very_low"],
translation_key="pollen_index",
icon="mdi:flower-pollen",
),
@ -293,8 +277,6 @@ SENSOR_TYPES = (
key=TMRW_ATTR_POLLEN_WEED,
name="Weed Pollen Index",
value_map=PollenIndex,
device_class=SensorDeviceClass.ENUM,
options=["high", "low", "medium", "none", "very_high", "very_low"],
translation_key="pollen_index",
icon="mdi:flower-pollen",
),
@ -302,8 +284,6 @@ SENSOR_TYPES = (
key=TMRW_ATTR_POLLEN_GRASS,
name="Grass Pollen Index",
value_map=PollenIndex,
device_class=SensorDeviceClass.ENUM,
options=["high", "low", "medium", "none", "very_high", "very_low"],
translation_key="pollen_index",
icon="mdi:flower-pollen",
),
@ -321,8 +301,6 @@ SENSOR_TYPES = (
key=TMRW_ATTR_UV_HEALTH_CONCERN,
name="UV Radiation Health Concern",
value_map=UVDescription,
device_class=SensorDeviceClass.ENUM,
options=["high", "low", "moderate", "very_high", "extreme"],
translation_key="uv_index",
icon="mdi:sun-wireless",
),

View File

@ -62,6 +62,16 @@
"ice_pellets": "Ice Pellets"
}
},
"primary_pollutant": {
"state": {
"pm25": "[%key:component::sensor::entity_component::pm25::name%]",
"pm10": "[%key:component::sensor::entity_component::pm10::name%]",
"o3": "[%key:component::sensor::entity_component::ozone::name%]",
"no2": "[%key:component::sensor::entity_component::nitrogen_dioxide::name%]",
"co": "[%key:component::sensor::entity_component::carbon_monoxide::name%]",
"so2": "[%key:component::sensor::entity_component::sulphur_dioxide::name%]"
}
},
"uv_index": {
"state": {
"low": "Low",