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