-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
entity_state.go
49 lines (39 loc) · 1017 Bytes
/
entity_state.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
package bus
import (
"time"
"github.com/e154/smart-home/common"
m "github.com/e154/smart-home/models"
)
// EntityState ...
type EntityState struct {
Name string `json:"name"`
Description string `json:"description"`
ImageUrl *string `json:"image_url"`
Icon *string `json:"icon"`
}
// EventEntityState ...
type EventEntityState struct {
EntityId common.EntityId `json:"entity_id"`
Value interface{} `json:"value"`
State *EntityState `json:"state"`
Attributes m.Attributes `json:"attributes"`
Settings m.Attributes `json:"settings"`
LastChanged *time.Time `json:"last_changed"`
LastUpdated *time.Time `json:"last_updated"`
}
// Compare ...
func (e1 EventEntityState) Compare(e2 EventEntityState) (ident bool) {
if e1.State == nil || e2.State == nil {
return
}
if e1.State.Name != e2.State.Name {
return
}
for k1, v1 := range e1.Attributes {
if !e2.Attributes[k1].Compare(v1) {
return false
}
}
ident = true
return
}