From 1b2535d497e56877259c2d45d2a76fb72c77754b Mon Sep 17 00:00:00 2001 From: Kev Date: Sun, 27 Oct 2024 15:46:51 -0400 Subject: [PATCH] Add V2.4 Sensors (#335) --- custom_components/pirateweather/const.py | 3 ++ .../pirateweather/forecast_models.py | 2 +- custom_components/pirateweather/manifest.json | 2 +- custom_components/pirateweather/sensor.py | 50 ++++++++++++++++++- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/custom_components/pirateweather/const.py b/custom_components/pirateweather/const.py index f186523..f85fe2e 100644 --- a/custom_components/pirateweather/const.py +++ b/custom_components/pirateweather/const.py @@ -135,6 +135,9 @@ "hrrr_18_48_update_time": "HRRR 18-48 Update Time", "gfs_update_time": "GFS Update Time", "gefs_update_time": "GEFS Update Time", + "current_day_liquid": "Current Day Liquid Accumulation", + "current_day_snow": "Current Day Snow Accumulation", + "current_day_ice": "Current Day Ice Accumulation", } LANGUAGES = [ diff --git a/custom_components/pirateweather/forecast_models.py b/custom_components/pirateweather/forecast_models.py index d54f381..ff7c145 100644 --- a/custom_components/pirateweather/forecast_models.py +++ b/custom_components/pirateweather/forecast_models.py @@ -78,7 +78,7 @@ def _forcastio_data(self, key): if key == "currently": return ForecastioDataPoint(self.json[key]) return ForecastioDataBlock(self.json[key]) - except requests.HTTPError: + except KeyError: if key == "currently": return ForecastioDataPoint() return ForecastioDataBlock() diff --git a/custom_components/pirateweather/manifest.json b/custom_components/pirateweather/manifest.json index 7c85c15..5534732 100644 --- a/custom_components/pirateweather/manifest.json +++ b/custom_components/pirateweather/manifest.json @@ -9,5 +9,5 @@ "documentation": "https://github.com/alexander0042/pirate-weather-ha", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/alexander0042/pirate-weather-ha/issues", - "version": "1.6.0" + "version": "1.6.1" } diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index f6ba05d..3071b24 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -233,6 +233,48 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): icon="mdi:weather-snowy-rainy", forecast_mode=["hourly", "daily"], ), + "current_day_liquid": PirateWeatherSensorEntityDescription( + key="current_day_liquid", + name="Current Day Liquid Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + state_class=SensorStateClass.MEASUREMENT, + si_unit=UnitOfLength.CENTIMETERS, + us_unit=UnitOfLength.INCHES, + ca_unit=UnitOfLength.CENTIMETERS, + uk_unit=UnitOfLength.CENTIMETERS, + uk2_unit=UnitOfLength.CENTIMETERS, + suggested_display_precision=4, + icon="mdi:weather-rainy", + forecast_mode=["currently"], + ), + "current_day_snow": PirateWeatherSensorEntityDescription( + key="current_day_snow", + name="Current Day Snow Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + state_class=SensorStateClass.MEASUREMENT, + si_unit=UnitOfLength.CENTIMETERS, + us_unit=UnitOfLength.INCHES, + ca_unit=UnitOfLength.CENTIMETERS, + uk_unit=UnitOfLength.CENTIMETERS, + uk2_unit=UnitOfLength.CENTIMETERS, + suggested_display_precision=4, + icon="mdi:weather-snowy", + forecast_mode=["currently"], + ), + "current_day_ice": PirateWeatherSensorEntityDescription( + key="current_day_ice", + name="Current Day Ice Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + state_class=SensorStateClass.MEASUREMENT, + si_unit=UnitOfLength.CENTIMETERS, + us_unit=UnitOfLength.INCHES, + ca_unit=UnitOfLength.CENTIMETERS, + uk_unit=UnitOfLength.CENTIMETERS, + uk2_unit=UnitOfLength.CENTIMETERS, + suggested_display_precision=4, + icon="mdi:weather-snowy-rainy", + forecast_mode=["currently"], + ), "temperature": PirateWeatherSensorEntityDescription( key="temperature", name="Temperature", @@ -1178,13 +1220,16 @@ def get_state(self, data): ]: state = round(state * 9 / 5) + 32 - # Precipitation Accumilation (mm in SI) to inches + # Precipitation Accumilation (cm in SI) to inches if self.requestUnits in ["us"]: if self.type in [ "precip_accumulation", "liquid_accumulation", "snow_accumulation", "ice_accumulation", + "current_day_liquid", + "current_day_snow", + "current_day_ice", ]: state = state * 0.0393701 @@ -1269,6 +1314,9 @@ def get_state(self, data): "ice_accumulation", "precip_intensity", "precip_intensity_max", + "current_day_liquid", + "current_day_snow", + "current_day_ice", ]: outState = round(state, roundingPrecip)