From f6a9be937b8144973ea9402a9f0a7852048cc6f1 Mon Sep 17 00:00:00 2001 From: lymanepp <4195527+lymanepp@users.noreply.github.com> Date: Fri, 18 Aug 2023 01:41:25 -0400 Subject: [PATCH] Add humidity and dew point to tomorrow.io integration (#98496) * Add humidity and dew point to tomorrow.io integration * Fix ruff complaints * Make mypy happy * Merge emontnemery's changes * Fix formatting error * Add fake humidity and dew point to test data (first interval only) * Fix inconsistency * Fix inconsistency --- homeassistant/components/tomorrowio/weather.py | 11 +++++++++++ tests/components/tomorrowio/fixtures/v4.json | 4 ++++ .../tomorrowio/snapshots/test_weather.ambr | 12 ++++++++++++ tests/components/tomorrowio/test_weather.py | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/homeassistant/components/tomorrowio/weather.py b/homeassistant/components/tomorrowio/weather.py index 333aa0cd472..ec77a2c8040 100644 --- a/homeassistant/components/tomorrowio/weather.py +++ b/homeassistant/components/tomorrowio/weather.py @@ -7,6 +7,8 @@ from pytomorrowio.const import DAILY, FORECASTS, HOURLY, NOWCAST, WeatherCode from homeassistant.components.weather import ( ATTR_FORECAST_CONDITION, + ATTR_FORECAST_HUMIDITY, + ATTR_FORECAST_NATIVE_DEW_POINT, ATTR_FORECAST_NATIVE_PRECIPITATION, ATTR_FORECAST_NATIVE_TEMP, ATTR_FORECAST_NATIVE_TEMP_LOW, @@ -44,6 +46,7 @@ from .const import ( DOMAIN, MAX_FORECASTS, TMRW_ATTR_CONDITION, + TMRW_ATTR_DEW_POINT, TMRW_ATTR_HUMIDITY, TMRW_ATTR_OZONE, TMRW_ATTR_PRECIPITATION, @@ -138,6 +141,8 @@ class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity): precipitation_probability: int | None, temp: float | None, temp_low: float | None, + humidity: float | None, + dew_point: float | None, wind_direction: float | None, wind_speed: float | None, ) -> Forecast: @@ -156,6 +161,8 @@ class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity): ATTR_FORECAST_PRECIPITATION_PROBABILITY: precipitation_probability, ATTR_FORECAST_NATIVE_TEMP: temp, ATTR_FORECAST_NATIVE_TEMP_LOW: temp_low, + ATTR_FORECAST_HUMIDITY: humidity, + ATTR_FORECAST_NATIVE_DEW_POINT: dew_point, ATTR_FORECAST_WIND_BEARING: wind_direction, ATTR_FORECAST_NATIVE_WIND_SPEED: wind_speed, } @@ -259,6 +266,8 @@ class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity): temp = values.get(TMRW_ATTR_TEMPERATURE_HIGH) temp_low = None + dew_point = values.get(TMRW_ATTR_DEW_POINT) + humidity = values.get(TMRW_ATTR_HUMIDITY) wind_direction = values.get(TMRW_ATTR_WIND_DIRECTION) wind_speed = values.get(TMRW_ATTR_WIND_SPEED) @@ -285,6 +294,8 @@ class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity): precipitation_probability, temp, temp_low, + humidity, + dew_point, wind_direction, wind_speed, ) diff --git a/tests/components/tomorrowio/fixtures/v4.json b/tests/components/tomorrowio/fixtures/v4.json index 0ca4f348956..c511263fb5f 100644 --- a/tests/components/tomorrowio/fixtures/v4.json +++ b/tests/components/tomorrowio/fixtures/v4.json @@ -908,6 +908,8 @@ "values": { "temperatureMin": 44.13, "temperatureMax": 44.13, + "dewPoint": 12.76, + "humidity": 58.46, "windSpeed": 9.33, "windDirection": 315.14, "weatherCode": 1000, @@ -2206,6 +2208,8 @@ "values": { "temperatureMin": 26.11, "temperatureMax": 45.93, + "dewPoint": 12.76, + "humidity": 58.46, "windSpeed": 9.49, "windDirection": 239.6, "weatherCode": 1000, diff --git a/tests/components/tomorrowio/snapshots/test_weather.ambr b/tests/components/tomorrowio/snapshots/test_weather.ambr index 40ff18658c6..a938cb10e44 100644 --- a/tests/components/tomorrowio/snapshots/test_weather.ambr +++ b/tests/components/tomorrowio/snapshots/test_weather.ambr @@ -4,6 +4,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T11:00:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 45.9, @@ -148,6 +150,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T11:00:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 45.9, @@ -292,6 +296,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T17:48:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 44.1, @@ -512,6 +518,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T17:48:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 44.1, @@ -733,6 +741,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T11:00:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 45.9, @@ -879,6 +889,8 @@ dict({ 'condition': 'sunny', 'datetime': '2021-03-07T17:48:00+00:00', + 'dew_point': 12.8, + 'humidity': 58, 'precipitation': 0.0, 'precipitation_probability': 0, 'temperature': 44.1, diff --git a/tests/components/tomorrowio/test_weather.py b/tests/components/tomorrowio/test_weather.py index 8490b94a7f9..a6a5e935614 100644 --- a/tests/components/tomorrowio/test_weather.py +++ b/tests/components/tomorrowio/test_weather.py @@ -24,6 +24,8 @@ from homeassistant.components.weather import ( ATTR_CONDITION_SUNNY, ATTR_FORECAST, ATTR_FORECAST_CONDITION, + ATTR_FORECAST_DEW_POINT, + ATTR_FORECAST_HUMIDITY, ATTR_FORECAST_PRECIPITATION, ATTR_FORECAST_PRECIPITATION_PROBABILITY, ATTR_FORECAST_TEMP, @@ -164,6 +166,8 @@ async def test_v4_weather(hass: HomeAssistant) -> None: ATTR_FORECAST_PRECIPITATION_PROBABILITY: 0, ATTR_FORECAST_TEMP: 45.9, ATTR_FORECAST_TEMP_LOW: 26.1, + ATTR_FORECAST_DEW_POINT: 12.8, + ATTR_FORECAST_HUMIDITY: 58, ATTR_FORECAST_WIND_BEARING: 239.6, ATTR_FORECAST_WIND_SPEED: 34.16, # 9.49 m/s -> km/h } @@ -191,6 +195,8 @@ async def test_v4_weather_legacy_entities(hass: HomeAssistant) -> None: assert weather_state.attributes[ATTR_FORECAST][0] == { ATTR_FORECAST_CONDITION: ATTR_CONDITION_SUNNY, ATTR_FORECAST_TIME: "2021-03-07T11:00:00+00:00", + ATTR_FORECAST_DEW_POINT: 12.8, + ATTR_FORECAST_HUMIDITY: 58, ATTR_FORECAST_PRECIPITATION: 0, ATTR_FORECAST_PRECIPITATION_PROBABILITY: 0, ATTR_FORECAST_TEMP: 45.9,