code.pfad.fr/gohmekit@v0.2.1/hapip/characteristic/programmable_switch_event.go (about) 1 package characteristic 2 3 import ( 4 "context" 5 "sync" 6 7 "code.pfad.fr/gohmekit/hapip" 8 ) 9 10 type programmableSwitchEventForIP struct { 11 Metadata[uint8] 12 mu sync.Mutex 13 notify func(ctx context.Context, val, old interface{}) 14 } 15 16 func (u *programmableSwitchEventForIP) Read(ctx context.Context) (interface{}, error) { 17 var empty interface{} // to force json omitempty give a "value": null 18 return &empty, nil 19 } 20 func (u *programmableSwitchEventForIP) Notify(cb func(ctx context.Context, val, old interface{})) { 21 u.mu.Lock() 22 defer u.mu.Unlock() 23 u.notify = cb 24 } 25 func (u *programmableSwitchEventForIP) update(val ProgrammableSwitchEvent_Type) { 26 u.mu.Lock() 27 cb := u.notify 28 u.mu.Unlock() 29 30 if cb != nil { 31 cb(context.Background(), val, nil) 32 } 33 } 34 35 // ProgrammableSwitchEvent represents a Programmable Switch Event characteristic (73) 36 // For IP accessories, the accessory must set the value of Paired Read to null(i.e. ”value”: null) in the attribute database. 37 // A read of this characteristic must always return a null value for IP accessories 38 // 39 // UUID: 00000073-0000-1000-8000-0026BB765291. 40 func ProgrammableSwitchEventForIP() (char hapip.CharacteristicNotifier, localWrite func(v ProgrammableSwitchEvent_Type)) { 41 c := &programmableSwitchEventForIP{ 42 Metadata: ProgrammableSwitchEvent_Meta, 43 } 44 return c, c.update 45 }