Browse Source

ßþ→ªn €® €n ßþœ®, ßþœ® ßœππ

pull/1/head
Gisle Aune 4 years ago
parent
commit
8f648de929
  1. 12
      app/services/events.go
  2. 3
      models/bridge.go
  3. 19
      models/device.go
  4. 11
      models/driver.go

12
app/services/events.go

@ -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 {

3
models/bridge.go

@ -4,7 +4,8 @@ type Bridge struct {
ID int
Name string
Driver DriverType
ConnectionString string
Address string
Token string
}
type DriverType string

19
models/device.go

@ -8,10 +8,13 @@ import (
type Device struct {
ID int `json:"id"`
BridgeID int `json:"bridgeID"`
InternalID string `json:"internalId"`
Icon string `json:"icon"`
Name string `json:"name"`
Capabilities []DeviceCapability `json:"capabilities"`
Properties map[string]string `json:"properties"`
ButtonNames []string `json:"buttonNames"`
DriverProperties map[string]string `json:"driverProperties"`
UserProperties map[string]string `json:"userProperties"`
State DeviceState `json:"state"`
Tags []string `json:"tags"`
}
@ -48,12 +51,7 @@ 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"
DCButtons DeviceCapability = "Buttons"
DCIntensity DeviceCapability = "Intensity"
DCTemperature DeviceCapability = "Temperature"
)
@ -62,12 +60,7 @@ var Capabilities = []DeviceCapability{
DCPower,
DCColorHS,
DCColorKelvin,
DCButtonDefault,
DCButtonOn,
DCButtonOff,
DCButtonPlus,
DCButtonMinus,
DCButtonToggle,
DCButtons,
DCIntensity,
DCTemperature,
}

11
models/driver.go

@ -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)
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, device Device) error
Publish(ctx context.Context, bridge Bridge, devices []Device) error
}
Loading…
Cancel
Save