diff --git a/listener.go b/listener.go index 87545e4..7f16ab3 100644 --- a/listener.go +++ b/listener.go @@ -12,6 +12,7 @@ type SyncHandler struct { devices map[string]*_device mutex *sync.Mutex chanForSync map[string]chan map[string]interface{} + states map[string]map[string]interface{} } func compareMap(src map[string]interface{}, dst map[string]interface{}) bool { @@ -69,6 +70,7 @@ func (sh *SyncHandler) Handle(e Event) { origin[key] = value } + sh.states[device.UUID] = origin // props := []string{"fan", "light", "servo"} err := encoder.Encode(origin) @@ -90,7 +92,7 @@ func (sh *SyncHandler) Handle(e Event) { sh.mutex.Unlock() for state := range chanForSync { - if compareMap(origin, state) { + if compareMap(sh.states[device.UUID], state) { sh.mutex.Lock() close(sh.chanForSync[device.IfaceName]) delete(sh.chanForSync, device.IfaceName) @@ -98,8 +100,8 @@ func (sh *SyncHandler) Handle(e Event) { return } log.Println("wrong: ", state) - log.Println("resend: ", origin) - err := encoder.Encode(origin) + log.Println("resend: ", sh.states[device.UUID]) + err := encoder.Encode(sh.states[device.UUID]) if err != nil { return }