wip motion detection
This commit is contained in:
parent
551716051f
commit
24bac70957
@ -158,7 +158,9 @@ func (b *Basestation) IsConnected() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Basestation) Subscribe(ctx context.Context) error {
|
func (b *Basestation) Subscribe(ctx context.Context) error {
|
||||||
b.eventStream = newEventStream(BaseUrl+fmt.Sprintf(NotifyResponsesPushServiceUri, b.arlo.Account.Token), &http.Client{Jar: b.arlo.client.GetClient().Jar})
|
b.eventStream = newEventStream(
|
||||||
|
BaseUrl+fmt.Sprintf(NotifyResponsesPushServiceUri, b.arlo.Account.Token),
|
||||||
|
&http.Client{Jar: b.arlo.client.GetClient().Jar})
|
||||||
|
|
||||||
connectedChan, err := b.eventStream.listen(ctx)
|
connectedChan, err := b.eventStream.listen(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
25
camera.go
25
camera.go
@ -2,7 +2,10 @@ package arlo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Camera is a Device of type "camera".
|
// A Camera is a Device of type "camera".
|
||||||
@ -268,3 +271,25 @@ func (c *Camera) SetAlertNotificationMethods(ctx context.Context, action string,
|
|||||||
}
|
}
|
||||||
return b.makeEventStreamRequest(ctx, payload)
|
return b.makeEventStreamRequest(ctx, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Camera) SubscribeToMotionDetection(ctx context.Context) (chan bool, error) {
|
||||||
|
b := c.arlo.Basestations.Find(c.ParentId)
|
||||||
|
if b == nil {
|
||||||
|
return nil, fmt.Errorf("basestation (%s) not found for camera (%s)", c.ParentId, c.DeviceId)
|
||||||
|
}
|
||||||
|
out := make(chan bool)
|
||||||
|
respChan := b.eventStream.subscribeResource(fmt.Sprintf("cameras/%s", c.DeviceId))
|
||||||
|
go func() {
|
||||||
|
for msg := range respChan {
|
||||||
|
var state CameraState
|
||||||
|
err := json.Unmarshal(msg.RawProperties, &state)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unmarshalling properties: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out <- state.MotionDetected
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
14
cmd/main.go
14
cmd/main.go
@ -17,10 +17,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, device := range a.Cameras {
|
for _, device := range a.Cameras {
|
||||||
log.Infof("%s", device.DeviceName)
|
if device.DeviceName == "Salon" {
|
||||||
err := device.EnableMotionAlerts(ctx, 70, nil)
|
motionChan, err := device.SubscribeToMotionDetection(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("setting camera %s on: %v", device.DeviceName, err)
|
log.Errorf("subscribing to motion: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for b := range motionChan {
|
||||||
|
log.Infof("motion salon %t", b)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user