From 67e3203d004e39614dd54119e3100333a5524bcd Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 19 Jul 2023 03:50:09 -0400 Subject: [PATCH] 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 --- homeassistant/components/tomorrowio/sensor.py | 34 ++++--------------- .../components/tomorrowio/strings.json | 10 ++++++ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/tomorrowio/sensor.py b/homeassistant/components/tomorrowio/sensor.py index 6f75679f124..aba5b44f284 100644 --- a/homeassistant/components/tomorrowio/sensor.py +++ b/homeassistant/components/tomorrowio/sensor.py @@ -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", ), diff --git a/homeassistant/components/tomorrowio/strings.json b/homeassistant/components/tomorrowio/strings.json index c795dbfdbaf..a104570f5c8 100644 --- a/homeassistant/components/tomorrowio/strings.json +++ b/homeassistant/components/tomorrowio/strings.json @@ -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",