From 2a5923a2abd55141c370e0281061cb353a2b5f30 Mon Sep 17 00:00:00 2001 From: acidpizza <2451313+acidpizza@users.noreply.github.com> Date: Sat, 19 Aug 2023 15:48:49 +0800 Subject: [PATCH 1/2] use name instead of default_name --- custom_components/nea_sg_weather/camera.py | 2 +- custom_components/nea_sg_weather/sensor.py | 6 +++--- custom_components/nea_sg_weather/weather.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom_components/nea_sg_weather/camera.py b/custom_components/nea_sg_weather/camera.py index 86911aa301..14bfff0796 100644 --- a/custom_components/nea_sg_weather/camera.py +++ b/custom_components/nea_sg_weather/camera.py @@ -206,7 +206,7 @@ def extra_state_attributes(self) -> dict: def device_info(self) -> DeviceInfo: """Device info.""" return DeviceInfo( - default_name="Weather forecast coordinator", + name="Weather forecast coordinator", identifiers={(DOMAIN,)}, # type: ignore[arg-type] manufacturer="NEA Weather", model="data.gov.sg API Polling", diff --git a/custom_components/nea_sg_weather/sensor.py b/custom_components/nea_sg_weather/sensor.py index 7a3d3541fe..38070a189b 100644 --- a/custom_components/nea_sg_weather/sensor.py +++ b/custom_components/nea_sg_weather/sensor.py @@ -123,7 +123,7 @@ def extra_state_attributes(self) -> dict: def device_info(self) -> DeviceInfo: """Device info.""" return DeviceInfo( - default_name="Weather forecast coordinator", + name="Weather forecast coordinator", identifiers={(DOMAIN,)}, # type: ignore[arg-type] manufacturer="NEA Weather", model="data.gov.sg API Polling", @@ -195,7 +195,7 @@ def extra_state_attributes(self) -> dict: def device_info(self) -> DeviceInfo: """Device info.""" return DeviceInfo( - default_name="Weather forecast coordinator", + name="Weather forecast coordinator", identifiers={(DOMAIN,)}, # type: ignore[arg-type] manufacturer="NEA Weather", model="data.gov.sg API Polling", @@ -286,7 +286,7 @@ def extra_state_attributes(self) -> dict: def device_info(self) -> DeviceInfo: """Device info.""" return DeviceInfo( - default_name="Weather forecast coordinator", + name="Weather forecast coordinator", identifiers={(DOMAIN,)}, # type: ignore[arg-type] manufacturer="NEA Weather", model="data.gov.sg API Polling", diff --git a/custom_components/nea_sg_weather/weather.py b/custom_components/nea_sg_weather/weather.py index 6a2c29fe5d..d70eb01222 100644 --- a/custom_components/nea_sg_weather/weather.py +++ b/custom_components/nea_sg_weather/weather.py @@ -135,7 +135,7 @@ def extra_state_attributes(self) -> dict: def device_info(self) -> DeviceInfo: """Device info.""" return DeviceInfo( - default_name="Weather forecast coordinator", + name="Weather forecast coordinator", identifiers={(DOMAIN,)}, # type: ignore[arg-type] manufacturer="NEA Weather", model="data.gov.sg API Polling", From 7ae8aee15374533ef1c6313218713cf8448b87b3 Mon Sep 17 00:00:00 2001 From: kianhean Date: Mon, 2 Oct 2023 15:46:06 +0800 Subject: [PATCH 2/2] use new async forecast to remove warning --- custom_components/nea_sg_weather/weather.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/custom_components/nea_sg_weather/weather.py b/custom_components/nea_sg_weather/weather.py index d70eb01222..2d3491f8fe 100644 --- a/custom_components/nea_sg_weather/weather.py +++ b/custom_components/nea_sg_weather/weather.py @@ -5,7 +5,11 @@ from types import MappingProxyType from typing import Any -from homeassistant.components.weather import WeatherEntity +from homeassistant.components.weather import ( + Forecast, + WeatherEntity, + WeatherEntityFeature, +) from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import ( CONF_NAME, @@ -65,6 +69,8 @@ class NeaWeather(CoordinatorEntity, WeatherEntity): _attr_native_precipitation_unit = LENGTH_MILLIMETERS _attr_native_pressure_unit = PRESSURE_HPA _attr_native_wind_speed_unit = SPEED_KNOTS + _attr_supported_features = (WeatherEntityFeature.FORECAST_DAILY + | WeatherEntityFeature.FORECAST_HOURLY) def __init__( self, @@ -140,3 +146,16 @@ def device_info(self) -> DeviceInfo: manufacturer="NEA Weather", model="data.gov.sg API Polling", ) + + async def async_forecast_daily(self) -> list[Forecast] | None: + """Return the daily forecast in native units. + Only implement this method if `WeatherEntityFeature.FORECAST_DAILY` is set + """ + return self.coordinator.data.forecast24hr.forecast + + async def async_forecast_hourly(self) -> list[Forecast] | None: + """Return the hourly forecast in native units. + We do not have hourly forecast data so 2 hourly will do + Only implement this method if `WeatherEntityFeature.FORECAST_HOURLY` is set + """ + return self.coordinator.data.forecast2hr.forecast