Gisle Aune
2 years ago
12 changed files with 357 additions and 59 deletions
-
65bus.go
-
8cmd/lucifer4-server/main.go
-
8commands/state.go
-
38events/button.go
-
8events/device.go
-
86events/sensors.go
-
4internal/color/color.go
-
3services/httpapiv1/service.go
-
146services/hue/bridge.go
-
14services/uistate/data.go
-
26services/uistate/patch.go
-
10services/uistate/service.go
@ -1,38 +0,0 @@ |
|||||
package events |
|
||||
|
|
||||
import "fmt" |
|
||||
|
|
||||
type ButtonPressed struct { |
|
||||
ID string `json:"id"` |
|
||||
SwipedID string `json:"swipedId,omitempty"` |
|
||||
Name string `json:"name"` |
|
||||
} |
|
||||
|
|
||||
func (e ButtonPressed) EventDescription() string { |
|
||||
if e.SwipedID != "" { |
|
||||
return fmt.Sprintf("ButtonPressed(name:%s, swipe:%s->%s)", e.Name, e.SwipedID, e.ID) |
|
||||
} else { |
|
||||
return fmt.Sprintf("ButtonPressed(name:%s, id:%s)", e.Name, e.ID) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func (e ButtonPressed) TriggerKind() string { |
|
||||
return "ButtonPressed:" + e.Name |
|
||||
} |
|
||||
|
|
||||
func (e ButtonPressed) TriggerValue(key string) (string, bool) { |
|
||||
switch key { |
|
||||
case "name": |
|
||||
return e.Name, true |
|
||||
case "id": |
|
||||
return e.ID, true |
|
||||
case "swipedFromId", "swipedId": |
|
||||
if e.SwipedID != "" { |
|
||||
return e.SwipedID, true |
|
||||
} else { |
|
||||
return "", false |
|
||||
} |
|
||||
default: |
|
||||
return "", false |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,86 @@ |
|||||
|
package events |
||||
|
|
||||
|
import "fmt" |
||||
|
|
||||
|
type TemperatureChanged struct { |
||||
|
ID string |
||||
|
Temperature float64 |
||||
|
} |
||||
|
|
||||
|
func (e TemperatureChanged) TriggerKind() string { |
||||
|
return "TemperatureChanged" |
||||
|
} |
||||
|
|
||||
|
func (e TemperatureChanged) TriggerValue(key string) (string, bool) { |
||||
|
switch key { |
||||
|
case "temperature": |
||||
|
return fmt.Sprintf("%.2f", e.Temperature), true |
||||
|
case "id": |
||||
|
return e.ID, true |
||||
|
default: |
||||
|
return "", false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (e TemperatureChanged) EventDescription() string { |
||||
|
return fmt.Sprintf("TemperatureChanged(id=%s, temperature=%.2f)", e.ID, e.Temperature) |
||||
|
} |
||||
|
|
||||
|
type MotionSensed struct { |
||||
|
ID string |
||||
|
SecondsSince float64 |
||||
|
} |
||||
|
|
||||
|
func (e MotionSensed) TriggerKind() string { |
||||
|
return "MotionSensed" |
||||
|
} |
||||
|
|
||||
|
func (e MotionSensed) TriggerValue(key string) (string, bool) { |
||||
|
switch key { |
||||
|
case "secondsSince": |
||||
|
return fmt.Sprintf("%.1f", e.SecondsSince), true |
||||
|
case "id": |
||||
|
return e.ID, true |
||||
|
default: |
||||
|
return "", false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (e MotionSensed) EventDescription() string { |
||||
|
return fmt.Sprintf("MotionSensed(id=%s, secondsSince=%.2f)", e.ID, e.SecondsSince) |
||||
|
} |
||||
|
|
||||
|
type ButtonPressed struct { |
||||
|
ID string `json:"id"` |
||||
|
SwipedID string `json:"swipedId,omitempty"` |
||||
|
Name string `json:"name"` |
||||
|
} |
||||
|
|
||||
|
func (e ButtonPressed) EventDescription() string { |
||||
|
if e.SwipedID != "" { |
||||
|
return fmt.Sprintf("ButtonPressed(name=%s, swipe=%s->%s)", e.Name, e.SwipedID, e.ID) |
||||
|
} else { |
||||
|
return fmt.Sprintf("ButtonPressed(name=%s, id=%s)", e.Name, e.ID) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (e ButtonPressed) TriggerKind() string { |
||||
|
return "ButtonPressed:" + e.Name |
||||
|
} |
||||
|
|
||||
|
func (e ButtonPressed) TriggerValue(key string) (string, bool) { |
||||
|
switch key { |
||||
|
case "name": |
||||
|
return e.Name, true |
||||
|
case "id": |
||||
|
return e.ID, true |
||||
|
case "swipedFromId", "swipedId": |
||||
|
if e.SwipedID != "" { |
||||
|
return e.SwipedID, true |
||||
|
} else { |
||||
|
return "", false |
||||
|
} |
||||
|
default: |
||||
|
return "", false |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue