add dat base

This commit is contained in:
2022-12-31 17:17:10 +01:00
parent 6fb82df153
commit 4ff22d7d63
27 changed files with 1337 additions and 36 deletions
+12 -9
View File
@@ -196,10 +196,12 @@ func (b *Bridge) ApplyPatches(resources []ResourceData) (events []lucifer3.Event
func (b *Bridge) SetStates(patch map[string]device.State) {
b.mu.Lock()
newStates := gentools.CopyMap(b.desiredStates)
desiredStates := b.desiredStates
resources := b.resources
b.mu.Unlock()
desiredStates = gentools.CopyMap(desiredStates)
prefix := "hue:" + b.host + ":"
for id, state := range patch {
if !strings.HasPrefix(id, prefix) {
@@ -213,14 +215,14 @@ func (b *Bridge) SetStates(patch map[string]device.State) {
}
if !state.Empty() {
newStates[id] = resource.FixState(state, resources)
desiredStates[id] = resource.FixState(state, resources)
} else {
delete(newStates, id)
delete(desiredStates, id)
}
}
b.mu.Lock()
b.desiredStates = newStates
b.desiredStates = desiredStates
b.mu.Unlock()
b.triggerCongruenceCheck()
@@ -289,8 +291,8 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
break
}
// Make sure this loop takes half a second
rateLimit := time.After(time.Second / 2)
// Make sure this loop doesn't spam too hard
rateLimit := time.After(time.Second / 10)
// Take states
b.mu.Lock()
@@ -305,6 +307,7 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
updates := make(map[string]ResourceUpdate)
for id, desired := range desiredStates {
active, activeOK := activeStates[id]
lightID := resources[id].ServiceID("light")
if !reachable[id] || !activeOK || lightID == nil {
@@ -423,10 +426,10 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
b.mu.Unlock()
cancel()
}
// Wait the remaining time for the rate limit
<-rateLimit
// Wait the remaining time for the rate limit
<-rateLimit
}
}
}