Skip to content

Commit

Permalink
change status endpoint. convert avg to float, if it is a string. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-stauffer authored Jul 11, 2023
1 parent 20fa297 commit a408c04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
30 changes: 24 additions & 6 deletions eliona/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ package eliona

import (
"context"
api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2"
"github.com/eliona-smart-building-assistant/go-eliona/asset"
"github.com/eliona-smart-building-assistant/go-utils/common"
"github.com/eliona-smart-building-assistant/go-utils/log"
"hailo/apiserver"
"hailo/conf"
"hailo/hailo"
"math"
"strconv"
"time"

api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2"
"github.com/eliona-smart-building-assistant/go-eliona/asset"
"github.com/eliona-smart-building-assistant/go-utils/common"
"github.com/eliona-smart-building-assistant/go-utils/log"
)

func UpsertDataForDevices(config apiserver.Configuration, spec hailo.Spec) error {
Expand Down Expand Up @@ -110,10 +112,10 @@ func UpsertDataForStation(config apiserver.Configuration, status hailo.Status) e
parseTime(status.Generic.LastContact),
*assetId,
stationDataPayload{
int(status.DeviceTypeSpecific.AverageBatteryLevel * 100),
int(interfaceToFloat(status.DeviceTypeSpecific.AverageBatteryLevel) * 100),
lastContact,
status.DeviceTypeSpecific.TotalInputsCount,
int(status.DeviceTypeSpecific.AverageFillingLevel * 100),
int(interfaceToFloat(status.DeviceTypeSpecific.AverageFillingLevel) * 100),
CheckActivity(config, lastContact),
},
)
Expand All @@ -125,6 +127,22 @@ func UpsertDataForStation(config apiserver.Configuration, status hailo.Status) e
return nil
}

func interfaceToFloat(value interface{}) float64 {
var fValue float64 = -1

switch v := value.(type) {
case string:
fValue, _ = strconv.ParseFloat(v, 32)
case int:
fValue = (float64)(v)
case float32:
fValue = (float64)(v)
case float64:
fValue = v
}
return fValue
}

func CheckActivity(connection apiserver.Configuration, lastContact float64) bool {
return lastContact < (float64)(connection.InactiveTimeout/3600)
}
Expand Down
17 changes: 9 additions & 8 deletions hailo/fds.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ package hailo
import (
"encoding/base64"
"encoding/json"
"github.com/eliona-smart-building-assistant/go-utils/http"
"github.com/eliona-smart-building-assistant/go-utils/log"
"github.com/volatiletech/null/v8"
"hailo/apiserver"
"strings"
"sync"
"time"

"github.com/eliona-smart-building-assistant/go-utils/http"
"github.com/eliona-smart-building-assistant/go-utils/log"
"github.com/volatiletech/null/v8"
)

const (
AuthApiPath = "/beta/v1/authentication"
FdsSpecificationPath = "/specifications"
FdsStatusPath = "/status"
FdsStatusPath = "/statuses"
FdsDiagnosticsPath = "/diagnostics"
FdsIdParam = "/?ids="
)
Expand Down Expand Up @@ -84,10 +85,10 @@ type Status struct {
LastEmptyCount int `json:"last_empty_count"`
BinAlarm bool `json:"bin_alarm"`
// Station
AverageBatteryLevel float32 `json:"average_battery_level"`
AverageFillingLevel float32 `json:"average_filling_level"`
TotalInputsCount int `json:"total_inputs_count"`
CompStatuses []Status `json:"component_statuses"`
AverageBatteryLevel interface{} `json:"average_battery_level"`
AverageFillingLevel interface{} `json:"average_filling_level"`
TotalInputsCount int `json:"total_inputs_count"`
CompStatuses []Status `json:"component_statuses"`
// Both
FillingLevel []struct {
Level float32 `json:"level"`
Expand Down

0 comments on commit a408c04

Please sign in to comment.