ßþ→ªn €® €n ßþœ®, ßþœ® ßœππ
This commit is contained in:
@@ -19,12 +19,11 @@ func StartEventHandler() {
|
||||
|
||||
// Dispatch an HourChanged event at every hour
|
||||
go func() {
|
||||
for {
|
||||
now := time.Now()
|
||||
nextHour := now.Add(time.Hour).Truncate(time.Hour)
|
||||
time.Sleep(nextHour.Sub(now))
|
||||
drift := time.Now().Add(time.Minute).Truncate(time.Minute).Sub(time.Now())
|
||||
time.Sleep(drift + time.Millisecond * 5)
|
||||
|
||||
config.EventChannel <- models.Event{Name: "HourChanged"}
|
||||
for range time.NewTicker(time.Minute).C {
|
||||
config.EventChannel <- models.Event{Name: "TimeChanged"}
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -36,6 +35,9 @@ func handleEvent(event models.Event) {
|
||||
if !event.HasPayload("hour") {
|
||||
event.AddPayload("hour", time.Now().In(loc).Format("15"))
|
||||
}
|
||||
if !event.HasPayload("minute") {
|
||||
event.AddPayload("minute", time.Now().In(loc).Format("04"))
|
||||
}
|
||||
|
||||
handlers, err := config.EventHandlerRepository().FetchAll(ctx)
|
||||
if err != nil {
|
||||
|
||||
+5
-4
@@ -1,10 +1,11 @@
|
||||
package models
|
||||
|
||||
type Bridge struct {
|
||||
ID int
|
||||
Name string
|
||||
Driver DriverType
|
||||
ConnectionString string
|
||||
ID int
|
||||
Name string
|
||||
Driver DriverType
|
||||
Address string
|
||||
Token string
|
||||
}
|
||||
|
||||
type DriverType string
|
||||
|
||||
+18
-25
@@ -6,14 +6,17 @@ import (
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
ID int `json:"id"`
|
||||
BridgeID int `json:"bridgeID"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name"`
|
||||
Capabilities []DeviceCapability `json:"capabilities"`
|
||||
Properties map[string]string `json:"properties"`
|
||||
State DeviceState `json:"state"`
|
||||
Tags []string `json:"tags"`
|
||||
ID int `json:"id"`
|
||||
BridgeID int `json:"bridgeID"`
|
||||
InternalID string `json:"internalId"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name"`
|
||||
Capabilities []DeviceCapability `json:"capabilities"`
|
||||
ButtonNames []string `json:"buttonNames"`
|
||||
DriverProperties map[string]string `json:"driverProperties"`
|
||||
UserProperties map[string]string `json:"userProperties"`
|
||||
State DeviceState `json:"state"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
// DeviceState contains optional state values that
|
||||
@@ -45,29 +48,19 @@ type DeviceRepository interface {
|
||||
}
|
||||
|
||||
var (
|
||||
DCPower DeviceCapability = "Power"
|
||||
DCColorHS DeviceCapability = "ColorHS"
|
||||
DCColorKelvin DeviceCapability = "ColorKelvin"
|
||||
DCButtonDefault DeviceCapability = "ButtonDefault"
|
||||
DCButtonOn DeviceCapability = "ButtonOn"
|
||||
DCButtonOff DeviceCapability = "ButtonOff"
|
||||
DCButtonPlus DeviceCapability = "ButtonPlus"
|
||||
DCButtonMinus DeviceCapability = "ButtonMinus"
|
||||
DCButtonToggle DeviceCapability = "ButtonToggle"
|
||||
DCIntensity DeviceCapability = "Intensity"
|
||||
DCTemperature DeviceCapability = "Temperature"
|
||||
DCPower DeviceCapability = "Power"
|
||||
DCColorHS DeviceCapability = "ColorHS"
|
||||
DCColorKelvin DeviceCapability = "ColorKelvin"
|
||||
DCButtons DeviceCapability = "Buttons"
|
||||
DCIntensity DeviceCapability = "Intensity"
|
||||
DCTemperature DeviceCapability = "Temperature"
|
||||
)
|
||||
|
||||
var Capabilities = []DeviceCapability{
|
||||
DCPower,
|
||||
DCColorHS,
|
||||
DCColorKelvin,
|
||||
DCButtonDefault,
|
||||
DCButtonOn,
|
||||
DCButtonOff,
|
||||
DCButtonPlus,
|
||||
DCButtonMinus,
|
||||
DCButtonToggle,
|
||||
DCButtons,
|
||||
DCIntensity,
|
||||
DCTemperature,
|
||||
}
|
||||
|
||||
+8
-5
@@ -1,14 +1,17 @@
|
||||
package models
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DriverResolver interface {
|
||||
ResolveFor(bridge Bridge) (Driver, error)
|
||||
}
|
||||
|
||||
type Driver interface {
|
||||
SearchBridge(ctx context.Context, address string) (Bridge, error)
|
||||
SearchDevices(ctx context.Context, bridge Bridge) ([]Device, error)
|
||||
Consume(ctx context.Context, bridge Bridge, devices []Device, ch chan Event) (chan <-struct{}, error)
|
||||
Publish(ctx context.Context, bridge Bridge, device Device) error
|
||||
SearchBridge(ctx context.Context, address string, dryRun bool) ([]Bridge, error)
|
||||
SearchDevices(ctx context.Context, bridge Bridge, timeout time.Duration) ([]Device, error)
|
||||
Consume(ctx context.Context, bridge Bridge, devices []Device, ch chan Event) (chan<- struct{}, error)
|
||||
Publish(ctx context.Context, bridge Bridge, devices []Device) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user