2024-02-13 22:20:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/probakowski/go-satel"
|
|
|
|
)
|
|
|
|
|
|
|
|
func FilterByType(ev <-chan satel.Event, allowedTypes []satel.ChangeType) <-chan satel.Event {
|
|
|
|
returnChan := make(chan satel.Event)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for e := range ev {
|
|
|
|
for _, allowedType := range allowedTypes {
|
|
|
|
if allowedType == e.Type {
|
|
|
|
returnChan <- e
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(returnChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return returnChan
|
|
|
|
}
|
2024-02-14 20:34:16 +00:00
|
|
|
|
|
|
|
type EventKey struct {
|
|
|
|
ChangeType satel.ChangeType
|
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
|
|
|
func FilterByLastSeen(ev <-chan satel.Event) <-chan satel.Event {
|
|
|
|
returnChan := make(chan satel.Event)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
lastSeen := make(map[EventKey]bool) // key: ChangeType/Index; value: Value
|
|
|
|
for e := range ev {
|
|
|
|
val, ok := lastSeen[EventKey{e.Type, e.Index}]
|
|
|
|
if !ok || val != e.Value {
|
|
|
|
lastSeen[EventKey{e.Type, e.Index}] = e.Value
|
|
|
|
returnChan <- e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(returnChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return returnChan
|
|
|
|
}
|