fix: sensor typ to static sensor model

This commit is contained in:
2019-02-28 19:48:25 +01:00
parent 1a3a31c5f2
commit 14ce354b32
11 changed files with 129 additions and 99 deletions

12
pkg/types/device.go Normal file
View File

@ -0,0 +1,12 @@
package types
import "time"
// Device ...
type Device struct {
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
DeviceLocation *string `json:"device_location"`
DeviceLastContact time.Time `json:"device_last_contact"`
CreationDate time.Time `json:"creation_date"`
}

12
pkg/types/humidity.go Normal file
View File

@ -0,0 +1,12 @@
package types
import "time"
// Humidity ...
type Humidity struct {
HumidityID string `json:"humidity_id"`
HumidityValue float64 `json:"humidity_value,string"`
HumidityDate time.Time `json:"humidity_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}

View File

@ -1,21 +1,22 @@
package types
import (
"fmt"
"time"
)
// Sensor ...
type Sensor struct {
SensorID string `json:"sensor_id"`
SensorName string `json:"sensor_name"`
SensorLocation string `json:"sensor_location"`
WireID *string `json:"wire_id"`
GPIONumber *string `json:"gpio_number"`
SensorType string `json:"sensor_type"`
SensorEnabled bool `json:"sensor_enabled"`
SensorLastContact time.Time `json:"sensor_last_contact"`
DeviceID string `json:"device_id"`
CreationDate time.Time `json:"creation_date"`
SensorID string `json:"sensor_id"`
SensorName string `json:"sensor_name"`
SensorLocation string `json:"sensor_location"`
WireID *string `json:"wire_id"`
GPIONumber *string `json:"gpio_number"`
SensorModel SensorModel `json:"sensor_model"`
SensorEnabled bool `json:"sensor_enabled"`
SensorLastContact time.Time `json:"sensor_last_contact"`
DeviceID string `json:"device_id"`
CreationDate time.Time `json:"creation_date"`
}
func (s *Sensor) Name() string {
@ -24,6 +25,27 @@ func (s *Sensor) Name() string {
} else if *s.WireID != "" {
return *s.WireID
}
return s.SensorID
}
type SensorModel string
const (
DHT11 SensorModel = "DHT11"
DHT22 = "DHT22"
DS18B20 = "DS18B20"
)
// SelectSensorModel converts a string into a constant
func SelectSensorModel(model string) (SensorModel, error) {
switch model {
case "DHT11":
return DHT11, nil
case "DHT22":
return DHT22, nil
case "DS18B20":
return DS18B20, nil
default:
return "", fmt.Errorf("Sensor Model %v currently not supported", model)
}
}

12
pkg/types/temperature.go Normal file
View File

@ -0,0 +1,12 @@
package types
import "time"
// Temperature ...
type Temperature struct {
TemperatureID string `json:"temperature_id"`
TemperatureValue float64 `json:"temperature_value,string"`
TemperatureDate time.Time `json:"temperature_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}

View File

@ -1,32 +0,0 @@
package types
import (
"time"
)
// Device ...
type Device struct {
DeviceID string `json:"device_id"`
DeviceName *string `json:"device_name"`
DeviceLocation *string `json:"device_location"`
DeviceLastContact time.Time `json:"device_last_contact"`
CreationDate time.Time `json:"creation_date"`
}
// Humidity ...
type Humidity struct {
HumidityID string `json:"humidity_id"`
HumidityValue float64 `json:"humidity_value,string"`
HumidityDate time.Time `json:"humidity_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}
// Temperature ...
type Temperature struct {
TemperatureID string `json:"temperature_id"`
TemperatureValue float64 `json:"temperature_value,string"`
TemperatureDate time.Time `json:"temperature_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}