From 0f41a2c532479478bd499bd0e71acf04d36f2e98 Mon Sep 17 00:00:00 2001 From: Kev Date: Sat, 27 Apr 2024 15:22:37 -0400 Subject: [PATCH 1/6] Start Adding Sensors for V2 Features --- custom_components/pirateweather/sensor.py | 74 +++++++++++++++++++ .../weather_update_coordinator.py | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index dec84ab..84aaf35 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -194,6 +194,45 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): icon="mdi:weather-snowy", forecast_mode=["hourly", "daily"], ), + "liquid_accumulation": PirateWeatherSensorEntityDescription( + key="liquid_accumulation", + name="Liquid Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + 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=["hourly", "daily"], + ), + "snow_accumulation": PirateWeatherSensorEntityDescription( + key="snow_accumulation", + name="Snow Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + 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=["hourly", "daily"], + ), + "ice_accumulation": PirateWeatherSensorEntityDescription( + key="ice_accumulation", + name="Ice Accumulation", + device_class=SensorDeviceClass.PRECIPITATION, + 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=["hourly", "daily"], + ), "temperature": PirateWeatherSensorEntityDescription( key="temperature", name="Temperature", @@ -333,6 +372,34 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): suggested_display_precision=2, forecast_mode=["currently", "hourly", "daily"], ), + "fire_index": PirateWeatherSensorEntityDescription( + key="fire_index", + name="Fire Index", + state_class=None, + suggested_display_precision=2, + forecast_mode=["currently", "hourly"], + ), + "fire_index_max": PirateWeatherSensorEntityDescription( + key="fire_index_max", + name="Fire Index Max", + state_class=None, + suggested_display_precision=2, + forecast_mode=["daily"], + ), + "smoke": PirateWeatherSensorEntityDescription( + key="smoke", + name="Smoke", + state_class=SensorDeviceClass.PM25, + suggested_display_precision=2, + forecast_mode=["currently", "hourly"], + ), + "smoke_max": PirateWeatherSensorEntityDescription( + key="smoke_max", + name="Smoke Max", + state_class=SensorDeviceClass.PM25, + suggested_display_precision=2, + forecast_mode=["daily"], + ), "apparent_temperature_max": PirateWeatherSensorEntityDescription( key="apparent_temperature_max", name="Daily High Apparent Temperature", @@ -1020,11 +1087,15 @@ def get_state(self, data): "apparent_temperature_max", "pressure", "ozone", + "fire_index", + "fire_index_max", "uv_index", "wind_speed", "wind_gust", "visibility", "nearest_storm_distance", + "smoke", + "smoke_max" ]: if roundingVal == 0: outState = int(round(state, roundingVal)) @@ -1033,6 +1104,9 @@ def get_state(self, data): elif self.type in [ "precip_accumulation", + "liquid_accumulation", + "snow_accumulation", + "ice_accumulation", "precip_intensity", "precip_intensity_max", ]: diff --git a/custom_components/pirateweather/weather_update_coordinator.py b/custom_components/pirateweather/weather_update_coordinator.py index bce315f..bde3e05 100644 --- a/custom_components/pirateweather/weather_update_coordinator.py +++ b/custom_components/pirateweather/weather_update_coordinator.py @@ -68,7 +68,7 @@ async def _get_pw_weather(self): + "?units=" + self.requested_units + "&extend=hourly" - + "&tz=precise" + + "&version=2" ) async with ( From 24a061cbf14ae31bc541f049ba52e105e54e09ad Mon Sep 17 00:00:00 2001 From: cloneofghosts Date: Sat, 27 Apr 2024 19:23:09 +0000 Subject: [PATCH 2/6] style fixes by ruff --- custom_components/pirateweather/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 84aaf35..4ccb114 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -1095,7 +1095,7 @@ def get_state(self, data): "visibility", "nearest_storm_distance", "smoke", - "smoke_max" + "smoke_max", ]: if roundingVal == 0: outState = int(round(state, roundingVal)) From 9bb315c472bd51b2a1e6328a151a1d7c331eb3d5 Mon Sep 17 00:00:00 2001 From: Kev Date: Sun, 28 Apr 2024 20:10:27 +0000 Subject: [PATCH 3/6] Finish setup of sensors for V2 features --- .gitignore | 5 +++++ custom_components/pirateweather/const.py | 7 +++++++ custom_components/pirateweather/manifest.json | 16 ++++++++++------ custom_components/pirateweather/sensor.py | 4 ++++ scripts/develop | 0 scripts/setup | 0 6 files changed, 26 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/develop mode change 100644 => 100755 scripts/setup diff --git a/.gitignore b/.gitignore index 13b6f67..566cd66 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ pythonenv* venv .venv .coverage +*.db* +*.log* +.HA_VERSION +config/.storage/* +config/blueprints/* diff --git a/custom_components/pirateweather/const.py b/custom_components/pirateweather/const.py index 6c00d1a..da0998e 100644 --- a/custom_components/pirateweather/const.py +++ b/custom_components/pirateweather/const.py @@ -116,6 +116,13 @@ "nearest_storm_bearing": "Nearest Storm Bearing", "alerts": "Alerts", "time": "Time", + "fire_index": "Fire Index", + "fire_index_max": "Fire Index Max", + "smoke": "Smoke", + "smoke_max": "Smoke Max", + "liquid_accumulation": "Liquid Accumulation", + "snow_accumulation": "Snow Accumulation", + "ice_accumulation": "Ice Accumulation", } LANGUAGES = [ diff --git a/custom_components/pirateweather/manifest.json b/custom_components/pirateweather/manifest.json index 52fb2dd..c73c9c8 100644 --- a/custom_components/pirateweather/manifest.json +++ b/custom_components/pirateweather/manifest.json @@ -1,12 +1,16 @@ { "domain": "pirateweather", "name": "Pirate Weather", - "codeowners": ["@alexander0042"], + "codeowners": [ + "@alexander0042" + ], "config_flow": true, - "dependencies": [], + "dependencies": [], "documentation": "https://github.com/alexander0042/pirate-weather-ha", "iot_class": "cloud_polling", - "issue_tracker": "https://github.com/alexander0042/pirate-weather-ha/issues", - "requirements": ["python-forecastio==1.4.0"], - "version": "1.4.5.1" -} + "issue_tracker": "https://github.com/alexander0042/pirate-weather-ha/issues", + "requirements": [ + "python-forecastio==1.4.0" + ], + "version": "1.5" +} \ No newline at end of file diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 4ccb114..49a47b2 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -377,6 +377,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): name="Fire Index", state_class=None, suggested_display_precision=2, + icon="mdi:fire", forecast_mode=["currently", "hourly"], ), "fire_index_max": PirateWeatherSensorEntityDescription( @@ -384,6 +385,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): name="Fire Index Max", state_class=None, suggested_display_precision=2, + icon="mdi:fire", forecast_mode=["daily"], ), "smoke": PirateWeatherSensorEntityDescription( @@ -391,6 +393,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): name="Smoke", state_class=SensorDeviceClass.PM25, suggested_display_precision=2, + icon="mdi:smoke", forecast_mode=["currently", "hourly"], ), "smoke_max": PirateWeatherSensorEntityDescription( @@ -398,6 +401,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): name="Smoke Max", state_class=SensorDeviceClass.PM25, suggested_display_precision=2, + icon="mdi:smoke", forecast_mode=["daily"], ), "apparent_temperature_max": PirateWeatherSensorEntityDescription( diff --git a/scripts/develop b/scripts/develop old mode 100644 new mode 100755 diff --git a/scripts/setup b/scripts/setup old mode 100644 new mode 100755 From 74940c01666c4fe3217e239178dcfa65dee25509 Mon Sep 17 00:00:00 2001 From: Kev Date: Sun, 28 Apr 2024 19:46:38 -0400 Subject: [PATCH 4/6] Add units to smoke sensor --- custom_components/pirateweather/sensor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 49a47b2..a474ce6 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -26,6 +26,7 @@ from homeassistant.const import ( ATTR_ATTRIBUTION, + CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, @@ -392,6 +393,11 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): key="smoke", name="Smoke", state_class=SensorDeviceClass.PM25, + si_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + us_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + ca_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + uk_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + uk2_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, suggested_display_precision=2, icon="mdi:smoke", forecast_mode=["currently", "hourly"], @@ -400,6 +406,11 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): key="smoke_max", name="Smoke Max", state_class=SensorDeviceClass.PM25, + si_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + us_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + ca_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + uk_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + uk2_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, suggested_display_precision=2, icon="mdi:smoke", forecast_mode=["daily"], From 4aadc1404b20108c342d08f4298f2411f712483f Mon Sep 17 00:00:00 2001 From: Kev Date: Mon, 29 Apr 2024 10:38:10 -0400 Subject: [PATCH 5/6] Fix smoke sensor classes --- custom_components/pirateweather/sensor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index a474ce6..4fcc090 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -376,7 +376,6 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "fire_index": PirateWeatherSensorEntityDescription( key="fire_index", name="Fire Index", - state_class=None, suggested_display_precision=2, icon="mdi:fire", forecast_mode=["currently", "hourly"], @@ -384,7 +383,6 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "fire_index_max": PirateWeatherSensorEntityDescription( key="fire_index_max", name="Fire Index Max", - state_class=None, suggested_display_precision=2, icon="mdi:fire", forecast_mode=["daily"], @@ -392,7 +390,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "smoke": PirateWeatherSensorEntityDescription( key="smoke", name="Smoke", - state_class=SensorDeviceClass.PM25, + device_class=SensorDeviceClass.PM25, si_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, us_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, ca_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, @@ -405,7 +403,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "smoke_max": PirateWeatherSensorEntityDescription( key="smoke_max", name="Smoke Max", - state_class=SensorDeviceClass.PM25, + device_class=SensorDeviceClass.PM25, si_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, us_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, ca_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, From 43db5dcb8e0a073ce335e2cd8f7d30bd9822d60a Mon Sep 17 00:00:00 2001 From: Kev Date: Mon, 29 Apr 2024 17:08:06 +0000 Subject: [PATCH 6/6] Add Measurement state class to fire index --- custom_components/pirateweather/sensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 4fcc090..0320a0a 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -376,6 +376,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "fire_index": PirateWeatherSensorEntityDescription( key="fire_index", name="Fire Index", + state_class=SensorStateClass.MEASUREMENT, suggested_display_precision=2, icon="mdi:fire", forecast_mode=["currently", "hourly"], @@ -383,6 +384,7 @@ class PirateWeatherSensorEntityDescription(SensorEntityDescription): "fire_index_max": PirateWeatherSensorEntityDescription( key="fire_index_max", name="Fire Index Max", + state_class=SensorStateClass.MEASUREMENT, suggested_display_precision=2, icon="mdi:fire", forecast_mode=["daily"],