-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.go
103 lines (87 loc) · 1.53 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package messages
import (
"encoding/json"
"math"
"time"
)
type GrillTemp struct {
Temp Temp
Time time.Time
Location Location
}
type FoodTemp struct {
Temp Temp
Time time.Time
Location Location
}
type GrillTarget struct {
Temp Temp
Time time.Time
}
type FoodTarget struct {
Temp Temp
Time time.Time
}
type FanStatus struct {
FanOn int `json:"fan_on"`
Time time.Time
}
// Temp is a temperature in Celcius
type Temp int
// custom json marshal to F
func (t Temp) MarshalJSON() ([]byte, error) {
return json.Marshal(t.F())
}
// C returns the temperature in Celcius
func (t *Temp) C() int {
return int(*t)
}
// F returns the temperature in Fahrenheit
func (t *Temp) F() int {
temp := math.Floor(float64(*t)*9/5) + 32
if temp < 0 {
return int(temp - 1.0)
}
return int(temp)
}
// TempFromF returns Temp from a fahrenheit value
func TempFromF(f int) Temp {
c := math.Floor(float64((f - 32)) / 1.8)
return Temp(c)
}
// Location of where something is
type Location int
// TODO: Need other location constants, think more here
const (
Food1 Location = iota
Food2
Food3
Food4
Food5
Food6
Top
Bottom
Outside
Inside
Right
Left
)
// LocationMap returns string values for
// Locations
var LocationMap = map[Location]string{
Food1: "FOOD1",
Food2: "FOOD2",
Food3: "FOOD3",
Food4: "FOOD4",
Food5: "FOOD5",
Food6: "FOOD6",
Top: "TOP",
Bottom: "BOTTOM",
Outside: "OUTSIDE",
Inside: "INSIDE",
Right: "RIGHT",
Left: "LEFT,",
}
func (l Location) String() string {
return LocationMap[l]
}