Skip to content

Commit

Permalink
Merge pull request #5 from peterzen/round-calculated
Browse files Browse the repository at this point in the history
Round calculated values to 1 decimal
  • Loading branch information
peterzen authored Apr 11, 2023
2 parents 24a57c8 + 5eec6b5 commit a073dea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pwsmqttdispatcher/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
name: PWS to MQTT dispatcher addon
version: "0.1.20"
version: "0.1.21"
slug: pwsmqttdispatcher
description: Push weather station (PWS) data to MQTT
url: "https://github.com/peterzen/hass-pws-mqtt-addon/tree/main/pwsmqttdispatcher"
Expand Down
10 changes: 7 additions & 3 deletions pwsmqttdispatcher/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ func calculateDewPoint(tempCelsius, humidity float64) float64 {

func addCalculatedData(wd WeatherData) WeatherData {
heatIndex := calculateHeatIndex(wd.Temperature, wd.Humidity)
wd.HeatIndex = heatIndex
wd.HeatIndex = roundFloatTo1Decimal(heatIndex)

windDirCardinal := windDirToCardinal(int(wd.WindDir))
wd.WindDirCardinal = windDirCardinal

windChill := calculateWindChill(wd.WindSpeed, wd.Temperature)
wd.WindChill = windChill
wd.WindChill = roundFloatTo1Decimal(windChill)

dewPoint := calculateDewPoint(wd.Temperature, wd.Humidity)
wd.DewPoint = dewPoint
wd.DewPoint = roundFloatTo1Decimal(dewPoint)

recTs, err := dateToUnixTimestamp(wd.ReceiverTime)
if err == nil {
Expand All @@ -242,6 +242,10 @@ func addCalculatedData(wd WeatherData) WeatherData {
return wd
}

func roundFloatTo1Decimal(f float64) float64 {
return math.Round(f*10) / 10
}

func main() {

debugEnabled = false
Expand Down

0 comments on commit a073dea

Please sign in to comment.