Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rounding #193

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: "Lint"
on:
push:
pull_request:

permissions:
contents: write

jobs:
ruff:
Expand Down Expand Up @@ -30,4 +33,4 @@ jobs:
- name: "Auto Commit"
uses: stefanzweifel/git-auto-commit-action@v5.0.0
with:
commit_message: 'style fixes by ruff'
commit_message: 'style fixes by ruff'
22 changes: 16 additions & 6 deletions custom_components/pirateweather/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]:
Expand Down Expand Up @@ -1015,17 +1017,25 @@ def get_state(self, data):
"apparent_temperature_high",
"temperature_max",
"apparent_temperature_max",
"precip_accumulation",
"pressure",
"ozone",
"uvIndex",
"uv_index",
"wind_speed",
"wind_gust",
"visibility",
"nearest_storm_distance",
]:
if roundingVal == 0:
outState = int(round(state, roundingVal))
else:
outState = state
outState = round(state, roundingVal)

elif self.type in [
"precip_accumulation",
"precip_intensity",
"precip_intensity_max",
]:
outState = round(state, roundingPrecip)

else:
outState = state
Expand Down