Skip to content

Commit

Permalink
Merge pull request #193 from Pirate-Weather/rounding
Browse files Browse the repository at this point in the history
Fix Rounding
  • Loading branch information
cloneofghosts authored Feb 16, 2024
2 parents 6b2cbd2 + a292489 commit d8dd522
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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/[email protected]
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

0 comments on commit d8dd522

Please sign in to comment.