From fd57f4c3cb8219bf2a66ed39e0b14848f708b68a Mon Sep 17 00:00:00 2001 From: Anand Radhakrishnan Date: Fri, 21 Oct 2022 17:52:21 +0300 Subject: [PATCH 1/3] draft, needs testing --- manifest.json | 2 +- sensor.py | 9 +++++++++ weather.py | 30 +++++++++++++++--------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/manifest.json b/manifest.json index 5cc9127..f80f312 100755 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "Finnish Meteorological Institute", "documentation": "https://www.home-assistant.io/integrations/fmi/", "requirements": [ - "fmi-weather-client==0.1.1", + "fmi-weather-client==0.1.2", "geopy>=2.1.0" ], "dependencies": [], diff --git a/sensor.py b/sensor.py index 38ad68e..8cf5286 100755 --- a/sensor.py +++ b/sensor.py @@ -14,6 +14,10 @@ PERCENTAGE ) +from homeassistant.components.sensor import ( + SensorStateClass +) + from homeassistant.const import CONF_NAME from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -393,6 +397,11 @@ def unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" return self._unit_of_measurement + @property + def state_class(self): + """Return the state class.""" + return SensorStateClass.MEASUREMENT + @property def icon(self): """Icon to use in the frontend, if any.""" diff --git a/weather.py b/weather.py index 7747793..09455e0 100755 --- a/weather.py +++ b/weather.py @@ -3,14 +3,14 @@ from homeassistant.components.weather import ( ATTR_FORECAST_CONDITION, - ATTR_FORECAST_PRECIPITATION, - ATTR_FORECAST_TEMP, + ATTR_FORECAST_NATIVE_PRECIPITATION, + ATTR_FORECAST_NATIVE_TEMP, ATTR_FORECAST_TIME, ATTR_FORECAST_WIND_BEARING, - ATTR_FORECAST_WIND_SPEED, + ATTR_FORECAST_NATIVE_WIND_SPEED, ATTR_WEATHER_HUMIDITY, ATTR_WEATHER_PRESSURE, - ATTR_FORECAST_TEMP_LOW, + ATTR_FORECAST_NATIVE_TEMP_LOW, WeatherEntity, ) @@ -197,20 +197,20 @@ def forecast(self): ATTR_FORECAST_CONDITION: get_weather_symbol( forecast.symbol.value ), - ATTR_FORECAST_TEMP: forecast.temperature.value, - ATTR_FORECAST_TEMP_LOW: forecast.temperature.value, - ATTR_FORECAST_PRECIPITATION: forecast.precipitation_amount.value, - ATTR_FORECAST_WIND_SPEED: forecast.wind_speed.value, + ATTR_FORECAST_NATIVE_TEMP: forecast.temperature.value, + ATTR_FORECAST_NATIVE_TEMP_LOW: forecast.temperature.value, + ATTR_FORECAST_NATIVE_PRECIPITATION: forecast.precipitation_amount.value, + ATTR_FORECAST_NATIVE_WIND_SPEED: forecast.wind_speed.value, ATTR_FORECAST_WIND_BEARING: forecast.wind_direction.value, ATTR_WEATHER_PRESSURE: forecast.pressure.value, ATTR_WEATHER_HUMIDITY: forecast.humidity.value, } ) else: - if data[-1][ATTR_FORECAST_TEMP] < forecast.temperature.value: - data[-1][ATTR_FORECAST_TEMP] = forecast.temperature.value - if data[-1][ATTR_FORECAST_TEMP_LOW] > forecast.temperature.value: - data[-1][ATTR_FORECAST_TEMP_LOW] = forecast.temperature.value + if data[-1][ATTR_FORECAST_NATIVE_TEMP] < forecast.temperature.value: + data[-1][ATTR_FORECAST_NATIVE_TEMP] = forecast.temperature.value + if data[-1][ATTR_FORECAST_NATIVE_TEMP_LOW] > forecast.temperature.value: + data[-1][ATTR_FORECAST_NATIVE_TEMP_LOW] = forecast.temperature.value else: data = [] for forecast in self._fmi.forecast.forecasts: @@ -221,9 +221,9 @@ def forecast(self): ATTR_FORECAST_CONDITION: get_weather_symbol( forecast.symbol.value ), - ATTR_FORECAST_TEMP: forecast.temperature.value, - ATTR_FORECAST_PRECIPITATION: forecast.precipitation_amount.value, - ATTR_FORECAST_WIND_SPEED: forecast.wind_speed.value, + ATTR_FORECAST_NATIVE_TEMP: forecast.temperature.value, + ATTR_FORECAST_NATIVE_PRECIPITATION: forecast.precipitation_amount.value, + ATTR_FORECAST_NATIVE_WIND_SPEED: forecast.wind_speed.value, ATTR_FORECAST_WIND_BEARING: forecast.wind_direction.value, ATTR_WEATHER_PRESSURE: forecast.pressure.value, ATTR_WEATHER_HUMIDITY: forecast.humidity.value, From 6b577e16104d77ec2a231eecda21e3b1533e2908 Mon Sep 17 00:00:00 2001 From: Anand Radhakrishnan Date: Fri, 21 Oct 2022 17:57:40 +0300 Subject: [PATCH 2/3] updated version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index f80f312..20660d0 100755 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "domain": "fmi", - "version": "0.4.9", + "version": "0.5.0", "name": "Finnish Meteorological Institute", "documentation": "https://www.home-assistant.io/integrations/fmi/", "requirements": [ From 7df6ecaf7957699099f9fe3ce800789a3899e9c0 Mon Sep 17 00:00:00 2001 From: Anand Radhakrishnan Date: Fri, 21 Oct 2022 18:55:29 +0300 Subject: [PATCH 3/3] updated as per new weather properties --- weather.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/weather.py b/weather.py index 09455e0..858c48c 100755 --- a/weather.py +++ b/weather.py @@ -108,7 +108,7 @@ def available(self): return self._fmi.current is not None @property - def temperature(self): + def native_temperature(self): """Return the temperature.""" if self._fmi is None: return None @@ -116,7 +116,7 @@ def temperature(self): return self._fmi.current.data.temperature.value @property - def temperature_unit(self): + def native_temperature_unit(self): """Return the unit of measurement.""" if self._fmi is None: return None @@ -132,7 +132,7 @@ def humidity(self): return self._fmi.current.data.humidity.value @property - def precipitation(self): + def native_precipitation(self): """Return the humidity.""" if self._fmi is None: return None @@ -140,7 +140,7 @@ def precipitation(self): return self._fmi.current.data.precipitation_amount.value @property - def wind_speed(self): + def native_wind_speed(self): """Return the wind speed.""" if self._fmi is None: return None @@ -158,7 +158,7 @@ def wind_bearing(self): return self._fmi.current.data.wind_direction.value @property - def pressure(self): + def native_pressure(self): """Return the pressure.""" if self._fmi is None: return None