briis / hass-weatherflow

Home Assistant Integration for WeatherFlow Stations
MIT License
67 stars 11 forks source link

Add Humidity to Hourly Forecast #74

Closed Colorado4Wheeler closed 1 year ago

Colorado4Wheeler commented 1 year ago

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 commented 1 year ago

This is now fixed. Will be in release 1.0.16