-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschedules.go
73 lines (60 loc) · 2.07 KB
/
schedules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package securityspy
import (
"encoding/xml"
"fmt"
"net/url"
"strconv"
)
/* There are no methods for updating or changing schedules through the API,
but you can assign already-existing schedules to cameras using a Camera
method. You can also assign hard coded Schedule Overrides to cameras using
a different method.
There is one "schedule" method for invoking a system-wide schedule preset.
*/
// CameraMode is a set of constants to deal with three specific camera modes.
type CameraMode rune
// CameraMode* are used by the Camera scheduling methods. Use these constants
// as inputs to a Camera's schedule methods.
const (
CameraModeAll CameraMode = 'X'
CameraModeMotion CameraMode = 'M'
CameraModeActions CameraMode = 'A'
CameraModeContinuous CameraMode = 'C'
)
// scheduleContainer allows unmarshalling of ScheduleOverrides and SchedulePresets into a map.
type ScheduleContainer map[int]string
// UnmarshalXML turns the XML schedule lists returned by SecuritySpy's API into a map[int]string.
func (m *ScheduleContainer) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error {
// Loop each list element.
for (*m) = make(ScheduleContainer); ; {
var schedule struct {
Name string `xml:"name"`
ID int `xml:"id"`
}
token, err := decoder.Token()
if err != nil {
return fmt.Errorf("bad XML token: %w", err)
}
switch xmlToken := token.(type) {
case xml.StartElement:
if err = decoder.DecodeElement(&schedule, &xmlToken); err != nil {
return fmt.Errorf("XML decode: %w", err)
}
(*m)[schedule.ID] = schedule.Name
case xml.EndElement:
if xmlToken == start.End() {
return nil
}
}
}
}
// SetSchedulePreset invokes a schedule preset. This [may/will] affect all camera arm modes.
// Find preset IDs you can pass into this method at server.Info.SchedulePresets.
func (s *Server) SetSchedulePreset(presetID int) error {
params := make(url.Values)
params.Set("id", strconv.Itoa(presetID))
if err := s.SimpleReq("++ssSetPreset", params, -1); err != nil {
return fmt.Errorf("http request: %w", err)
}
return nil
}