Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Add Humidity to Hourly Forecast #74

Closed
Colorado4Wheeler opened this issue Aug 8, 2023 · 1 comment
Closed

Add Humidity to Hourly Forecast #74

Colorado4Wheeler opened this issue Aug 8, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Colorado4Wheeler
Copy link

This is a pretty simple one that I hope you will incorporate into the next release. The ATTR_FORECAST_HUMIDITY is supported in the weather entity forecast model and is very helpful for me to help control evaporative cooling. I was poking around in the code when the hourly forecast visuals broke and decided to add it with just a couple of lines and it's really nice to have:

Added the attribute to weather.py:

from homeassistant.components.weather import (
    ATTR_FORECAST_CONDITION,
    ATTR_FORECAST_NATIVE_PRECIPITATION,
    ATTR_FORECAST_PRECIPITATION_PROBABILITY,
    ATTR_FORECAST_NATIVE_TEMP,
    ATTR_FORECAST_NATIVE_TEMP_LOW,
    ATTR_FORECAST_TIME,
    ATTR_FORECAST_WIND_BEARING,
    ATTR_FORECAST_NATIVE_WIND_SPEED,
    ATTR_FORECAST_HUMIDITY,
    Forecast,
    WeatherEntity,
    WeatherEntityDescription,
)

and then read into the attribute in the hourly forecast in weather.py:

    @property
    def forecast(self) -> list[Forecast] | None:
        """Return the forecast array."""
        ha_forecast_day: list[Forecast] = []
        if self.daily_forecast:
            forecast_data_daily: ForecastDailyDescription = getattr(
                self.forecast_coordinator.data, "forecast_daily"
            )
            for item in forecast_data_daily:
                ha_item = {
                    ATTR_FORECAST_CONDITION: format_condition(item.icon),
                    ATTR_FORECAST_NATIVE_PRECIPITATION: item.precip,
                    ATTR_FORECAST_PRECIPITATION_PROBABILITY: item.precip_probability,
                    ATTR_FORECAST_NATIVE_TEMP: item.air_temp_high,
                    ATTR_FORECAST_NATIVE_TEMP_LOW: item.air_temp_low,
                    ATTR_FORECAST_TIME: item.utc_time,
                    ATTR_FORECAST_WIND_BEARING: item.wind_direction,
                    ATTR_FORECAST_NATIVE_WIND_SPEED: item.wind_avg,
                }
                ha_forecast_day.append(ha_item)
            return ha_forecast_day

        ha_forecast_hour: list[Forecast] = []
        forecast_data_hourly: ForecastHourlyDescription = getattr(
            self.forecast_coordinator.data, "forecast_hourly"
        )
        for item in forecast_data_hourly:
            ha_forecast_hour.append(
                {
                    ATTR_FORECAST_TIME: item.utc_time,
                    ATTR_FORECAST_NATIVE_TEMP: item.air_temperature,
                    ATTR_FORECAST_NATIVE_PRECIPITATION: item.precip,
                    ATTR_FORECAST_PRECIPITATION_PROBABILITY: item.precip_probability,
                    ATTR_FORECAST_CONDITION: format_condition(item.icon),
                    ATTR_FORECAST_NATIVE_WIND_SPEED: item.wind_avg,
                    ATTR_FORECAST_WIND_BEARING: item.wind_direction,
                    ATTR_FORECAST_WIND_GUST: item.wind_gust,
                    ATTR_FORECAST_FEELS_LIKE: item.feels_like,
                    ATTR_FORECAST_UV: item.uv,
                    ATTR_FORECAST_HUMIDITY: item.relative_humidity,
                }
            )
        return ha_forecast_hour
@briis briis added the enhancement New feature or request label Aug 30, 2023
@briis
Copy link
Owner

briis commented Aug 30, 2023

This is now fixed. Will be in release 1.0.16

@briis briis closed this as completed Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants