@@ -17,10 +17,25 @@ type Scene struct {
|
||||
due bool
|
||||
}
|
||||
|
||||
// UpdateScene updates the scene data and re-seats all devices.
|
||||
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) {
|
||||
if s.data == nil {
|
||||
s.roleMap[device.ID] = -1
|
||||
@@ -56,6 +71,7 @@ func (s *Scene) UpsertDevice(device models.Device) {
|
||||
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) {
|
||||
roleIndex, hasRoleIndex := s.roleMap[device.ID]
|
||||
if !hasRoleIndex {
|
||||
@@ -68,8 +84,11 @@ func (s *Scene) RemoveDevice(device models.Device) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
delete(s.roleMap, device.ID)
|
||||
}
|
||||
|
||||
// Run runs the scene
|
||||
func (s *Scene) Run() []models.Device {
|
||||
if s.data == nil {
|
||||
return []models.Device{}
|
||||
|
||||
@@ -204,7 +204,9 @@ func (b *Bridge) Run(ctx context.Context, debug bool) error {
|
||||
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 {
|
||||
_, _ = client.Send(state.target, &GetHostFirmware{})
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ type State struct {
|
||||
lightStateTime time.Time
|
||||
requestTime time.Time
|
||||
updateTime time.Time
|
||||
fwSpamTime time.Time
|
||||
acksPending []uint8
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user