From 3ac14900d9019ed9d3e22b26872491fad21af36e Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 14 Feb 2024 13:13:03 -0500 Subject: [PATCH 1/5] Fix Rounding --- custom_components/pirateweather/sensor.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 80568be..b9da5a0 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -943,13 +943,15 @@ def get_state(self, data): # If output rounding is requested, round to nearest integer if self.outputRound == "Yes": roundingVal = 0 + roundingPrecip = 2 else: - roundingVal = 1 + roundingVal = 2 + roundingPrecip = 4 # Some state data needs to be rounded to whole values or converted to # percentages if self.type in ["precip_probability", "cloud_cover", "humidity"]: - state = state * 100 + state = int(state * 100) # Logic to convert from SI to requsested units for compatability # Temps in F @@ -963,7 +965,7 @@ def get_state(self, data): "apparent_temperature_high", "apparent_temperature_low", ]: - state = (state * 9 / 5) + 32 + state = round(state * 9 / 5) + 32 # Precipitation Accumilation (mm in SI) to inches if self.requestUnits in ["us"]: @@ -1015,17 +1017,25 @@ def get_state(self, data): "apparent_temperature_high", "temperature_max", "apparent_temperature_max", - "precip_accumulation", "pressure", "ozone", "uvIndex", "wind_speed", "wind_gust", + "visibility", + "nearest_storm_distance", ]: if roundingVal == 0: outState = int(round(state, roundingVal)) else: - outState = state + outState = round(state, roundingVal) + + if self.type in [ + "precip_accumulation", + "precip_intensity", + "precip_intensity_max", + ]: + outState = round(state, roundingPrecip) else: outState = state From b4671f72b17161b4d48adf36f314937c6cfe8dfc Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 14 Feb 2024 14:40:00 -0500 Subject: [PATCH 2/5] Change if statement to elif --- 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 b9da5a0..88b11b0 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -1030,7 +1030,7 @@ def get_state(self, data): else: outState = round(state, roundingVal) - if self.type in [ + elif self.type in [ "precip_accumulation", "precip_intensity", "precip_intensity_max", From 883e8ca7fca7377cd4cef1597d2433c0ebcf8f7e Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 14 Feb 2024 15:27:38 -0500 Subject: [PATCH 3/5] Change uvIndex to uv_index --- 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 88b11b0..593ecc6 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -1019,7 +1019,7 @@ def get_state(self, data): "apparent_temperature_max", "pressure", "ozone", - "uvIndex", + "uv_index", "wind_speed", "wind_gust", "visibility", From 37ede737147329fa39cb561b0916809202780615 Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 14 Feb 2024 21:41:04 -0500 Subject: [PATCH 4/5] Fix Lint Workflow --- .github/workflows/lint.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 09b32b9..b8c6e3a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,6 +3,9 @@ name: "Lint" on: push: pull_request: + +permissions: + contents: write jobs: ruff: @@ -30,4 +33,4 @@ jobs: - name: "Auto Commit" uses: stefanzweifel/git-auto-commit-action@v5.0.0 with: - commit_message: 'style fixes by ruff' \ No newline at end of file + commit_message: 'style fixes by ruff' From a2924890f7a20bd114783fe91c8777a19e030d62 Mon Sep 17 00:00:00 2001 From: cloneofghosts Date: Thu, 15 Feb 2024 02:41:40 +0000 Subject: [PATCH 5/5] style fixes by ruff --- custom_components/pirateweather/sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/pirateweather/sensor.py b/custom_components/pirateweather/sensor.py index 593ecc6..1af2541 100644 --- a/custom_components/pirateweather/sensor.py +++ b/custom_components/pirateweather/sensor.py @@ -1029,13 +1029,13 @@ def get_state(self, data): outState = int(round(state, roundingVal)) else: outState = round(state, roundingVal) - + elif self.type in [ "precip_accumulation", "precip_intensity", "precip_intensity_max", ]: - outState = round(state, roundingPrecip) + outState = round(state, roundingPrecip) else: outState = state