Skip to content

Commit

Permalink
Add UV Index and UV Health Concern sensors to tomorrow.io (#96534)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirrgang authored Jul 15, 2023
1 parent 3b309ca commit edcae75
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions homeassistant/components/tomorrowio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
TMRW_ATTR_TEMPERATURE,
TMRW_ATTR_TEMPERATURE_HIGH,
TMRW_ATTR_TEMPERATURE_LOW,
TMRW_ATTR_UV_HEALTH_CONCERN,
TMRW_ATTR_UV_INDEX,
TMRW_ATTR_VISIBILITY,
TMRW_ATTR_WIND_DIRECTION,
TMRW_ATTR_WIND_GUST,
Expand Down Expand Up @@ -291,6 +293,8 @@ async def _async_update_data(self) -> dict[str, Any]:
TMRW_ATTR_PRESSURE_SURFACE_LEVEL,
TMRW_ATTR_SOLAR_GHI,
TMRW_ATTR_SULPHUR_DIOXIDE,
TMRW_ATTR_UV_INDEX,
TMRW_ATTR_UV_HEALTH_CONCERN,
TMRW_ATTR_WIND_GUST,
],
[
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/tomorrowio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@
TMRW_ATTR_SOLAR_GHI = "solarGHI"
TMRW_ATTR_CLOUD_BASE = "cloudBase"
TMRW_ATTR_CLOUD_CEILING = "cloudCeiling"
TMRW_ATTR_UV_INDEX = "uvIndex"
TMRW_ATTR_UV_HEALTH_CONCERN = "uvHealthConcern"
17 changes: 17 additions & 0 deletions homeassistant/components/tomorrowio/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PollenIndex,
PrecipitationType,
PrimaryPollutantType,
UVDescription,
)

from homeassistant.components.sensor import (
Expand Down Expand Up @@ -64,6 +65,8 @@
TMRW_ATTR_PRESSURE_SURFACE_LEVEL,
TMRW_ATTR_SOLAR_GHI,
TMRW_ATTR_SULPHUR_DIOXIDE,
TMRW_ATTR_UV_HEALTH_CONCERN,
TMRW_ATTR_UV_INDEX,
TMRW_ATTR_WIND_GUST,
)

Expand Down Expand Up @@ -309,6 +312,20 @@ def convert_ppb_to_ugm3(molecular_weight: int | float) -> Callable[[float], floa
name="Fire Index",
icon="mdi:fire",
),
TomorrowioSensorEntityDescription(
key=TMRW_ATTR_UV_INDEX,
name="UV Index",
icon="mdi:sun-wireless",
),
TomorrowioSensorEntityDescription(
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",
),
)


Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/tomorrowio/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
"freezing_rain": "Freezing Rain",
"ice_pellets": "Ice Pellets"
}
},
"uv_index": {
"state": {
"low": "Low",
"moderate": "Moderate",
"high": "High",
"very_high": "Very high",
"extreme": "Extreme"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/tomorrowio/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def forecast(self):

temp = values.get(TMRW_ATTR_TEMPERATURE_HIGH)
temp_low = None

wind_direction = values.get(TMRW_ATTR_WIND_DIRECTION)
wind_speed = values.get(TMRW_ATTR_WIND_SPEED)

Expand Down
4 changes: 3 additions & 1 deletion tests/components/tomorrowio/fixtures/v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"pressureSurfaceLevel": 29.47,
"solarGHI": 0,
"cloudBase": 0.74,
"cloudCeiling": 0.74
"cloudCeiling": 0.74,
"uvIndex": 3,
"uvHealthConcern": 1
},
"forecasts": {
"nowcast": [
Expand Down
9 changes: 9 additions & 0 deletions tests/components/tomorrowio/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
CLOUD_CEILING = "cloud_ceiling"
WIND_GUST = "wind_gust"
PRECIPITATION_TYPE = "precipitation_type"
UV_INDEX = "uv_index"
UV_HEALTH_CONCERN = "uv_radiation_health_concern"


V3_FIELDS = [
O3,
Expand Down Expand Up @@ -91,6 +94,8 @@
CLOUD_CEILING,
WIND_GUST,
PRECIPITATION_TYPE,
UV_INDEX,
UV_HEALTH_CONCERN,
]


Expand Down Expand Up @@ -171,6 +176,8 @@ async def test_v4_sensor(hass: HomeAssistant) -> None:
check_sensor_state(hass, CLOUD_CEILING, "0.74")
check_sensor_state(hass, WIND_GUST, "12.64")
check_sensor_state(hass, PRECIPITATION_TYPE, "rain")
check_sensor_state(hass, UV_INDEX, "3")
check_sensor_state(hass, UV_HEALTH_CONCERN, "moderate")


async def test_v4_sensor_imperial(hass: HomeAssistant) -> None:
Expand Down Expand Up @@ -202,6 +209,8 @@ async def test_v4_sensor_imperial(hass: HomeAssistant) -> None:
check_sensor_state(hass, CLOUD_CEILING, "0.46")
check_sensor_state(hass, WIND_GUST, "28.27")
check_sensor_state(hass, PRECIPITATION_TYPE, "rain")
check_sensor_state(hass, UV_INDEX, "3")
check_sensor_state(hass, UV_HEALTH_CONCERN, "moderate")


async def test_entity_description() -> None:
Expand Down

0 comments on commit edcae75

Please sign in to comment.