Browse Source

some more work.

pull/1/head
Gisle Aune 3 years ago
parent
commit
a3695a3ddd
  1. 19
      app/services/publisher/scene.go
  2. 4
      internal/drivers/lifx/bridge.go
  3. 1
      internal/drivers/lifx/state.go

19
app/services/publisher/scene.go

@ -17,10 +17,25 @@ type Scene struct {
due bool due bool
} }
// UpdateScene updates the scene data and re-seats all devices.
func (s *Scene) UpdateScene(data models.Scene) { func (s *Scene) UpdateScene(data models.Scene) {
devices := make([]models.Device, 0, 16)
for ri, list := range s.roleList {
for _, device := range list {
devices = append(devices, device)
s.roleMap[device.ID] = -1
}
}
s.roleList = map[int][]models.Device {-1: devices}
for _, device := range append(devices[:0:0], devices...) {
s.UpsertDevice(device)
}
} }
// UpsertDevice moves the device if neccesary and updates its state.
func (s *Scene) UpsertDevice(device models.Device) { func (s *Scene) UpsertDevice(device models.Device) {
if s.data == nil { if s.data == nil {
s.roleMap[device.ID] = -1 s.roleMap[device.ID] = -1
@ -56,6 +71,7 @@ func (s *Scene) UpsertDevice(device models.Device) {
s.data.Roles[newIndex].ApplyOrder(s.roleList[newIndex]) s.data.Roles[newIndex].ApplyOrder(s.roleList[newIndex])
} }
// RemoveDevice finds and remove a device. It's a noop if the device does not exist in this scene.
func (s *Scene) RemoveDevice(device models.Device) { func (s *Scene) RemoveDevice(device models.Device) {
roleIndex, hasRoleIndex := s.roleMap[device.ID] roleIndex, hasRoleIndex := s.roleMap[device.ID]
if !hasRoleIndex { if !hasRoleIndex {
@ -68,8 +84,11 @@ func (s *Scene) RemoveDevice(device models.Device) {
break break
} }
} }
delete(s.roleMap, device.ID)
} }
// Run runs the scene
func (s *Scene) Run() []models.Device { func (s *Scene) Run() []models.Device {
if s.data == nil { if s.data == nil {
return []models.Device{} return []models.Device{}

4
internal/drivers/lifx/bridge.go

@ -204,7 +204,9 @@ func (b *Bridge) Run(ctx context.Context, debug bool) error {
b.checkAndUpdateState(state) b.checkAndUpdateState(state)
} }
if time.Since(state.discoveredTime) > time.Second*10 {
if time.Since(state.discoveredTime) > time.Second*10 && time.Since(state.fwSpamTime) > time.Second * 30 {
state.fwSpamTime = time.Now()
if state.firmware == nil { if state.firmware == nil {
_, _ = client.Send(state.target, &GetHostFirmware{}) _, _ = client.Send(state.target, &GetHostFirmware{})
} }

1
internal/drivers/lifx/state.go

@ -18,6 +18,7 @@ type State struct {
lightStateTime time.Time lightStateTime time.Time
requestTime time.Time requestTime time.Time
updateTime time.Time updateTime time.Time
fwSpamTime time.Time
acksPending []uint8 acksPending []uint8
} }

Loading…
Cancel
Save