Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5cf30ea4b | ||
|
|
582bf3f46b | ||
|
|
c72a7c3f43 |
@@ -55,6 +55,7 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
|
||||
|
||||
absences := make(map[int]time.Time)
|
||||
lastPress := make(map[string]time.Time)
|
||||
lastUpdate := time.Now()
|
||||
needFull := false
|
||||
|
||||
for {
|
||||
@@ -62,6 +63,10 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-lightRefreshTimer.C:
|
||||
if time.Since(lastUpdate) < time.Second*2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if needFull {
|
||||
err := b.RefreshAll(ctx)
|
||||
if err != nil {
|
||||
@@ -79,9 +84,16 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
|
||||
return err
|
||||
}
|
||||
if updated > 0 {
|
||||
// Force this to cool for 30 seconds unless a manual update occurs.
|
||||
if updated > 10 {
|
||||
lastUpdate = time.Now().Add(time.Second * 15)
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("[Bridge %d]", b.externalID), "Updated", updated, "hue services (regular check)")
|
||||
}
|
||||
case <-b.needsUpdate:
|
||||
lastUpdate = time.Now()
|
||||
|
||||
updated, err := b.MakeCongruent(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -125,9 +137,11 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
|
||||
continue
|
||||
}
|
||||
|
||||
b.mu.Lock()
|
||||
if b.resources[patch.Owner.ID] == nil {
|
||||
needFull = true
|
||||
}
|
||||
b.mu.Unlock()
|
||||
|
||||
device, deviceOK := b.devices[patch.Owner.ID]
|
||||
if !deviceOK || device.ID == 0 {
|
||||
@@ -141,7 +155,7 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
|
||||
} else if patch.Button.LastEvent == "long_release" {
|
||||
valid = false
|
||||
} else {
|
||||
valid = lastPress[patch.ID].Unix() != data.CreationTime.Unix()
|
||||
valid = data.CreationTime.Sub(lastPress[patch.ID]) >= time.Second*2
|
||||
}
|
||||
|
||||
if valid {
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ func hsToXY(hue, sat float64) ColorXY {
|
||||
green := float64(green255) / 255.0
|
||||
blue := float64(blue255) / 255.0
|
||||
|
||||
return screenRGBToXY(red, green, blue)
|
||||
return rgbToXY(red, green, blue)
|
||||
}
|
||||
|
||||
func rgbToXY(red float64, green float64, blue float64) ColorXY {
|
||||
|
||||
Reference in New Issue
Block a user