-
Notifications
You must be signed in to change notification settings - Fork 6
/
discovery.go
85 lines (71 loc) · 2.58 KB
/
discovery.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
74
75
76
77
78
79
80
81
82
83
84
85
package smarthome
type DiscoverResponse struct {
DiscoveryEndpoints []DiscoveryEndpoint `json:"endpoints"`
}
type DiscoveryEndpoint struct {
EndpointID string `json:"endpointId"`
ManufacturerName string `json:"manufacturerName"`
FriendlyName string `json:"friendlyName"`
Description string `json:"description"`
DisplayCategories []string `json:"displayCategories,omitempty"`
Cookie Cookie `json:"cookie"`
Capabilities []Capability `json:"capabilities,omitempty"`
}
type Capability struct {
Type string `json:"type"`
Interface string `json:"interface"`
Version string `json:"version"`
Properties *Properties `json:"properties,omitempty"`
SupportsDeactivation *bool `json:"supportsDeactivation,omitempty"`
ProactivelyReported *bool `json:"proactivelyReported,omitempty"`
CameraStreamConfigurations []CameraStreamConfiguration `json:"cameraStreamConfigurations,omitempty"`
}
type CameraStreamConfiguration struct {
Protocols []string `json:"protocols"`
Resolutions []Resolution `json:"resolutions"`
AuthorizationTypes []string `json:"authorizationTypes"`
VideoCodecs []string `json:"videoCodecs"`
AudioCodecs []string `json:"audioCodecs"`
}
type Resolution struct {
Width int64 `json:"width"`
Height int64 `json:"height"`
}
type Properties struct {
Supported []Supported `json:"supported"`
ProactivelyReported bool `json:"proactivelyReported"`
Retrievable bool `json:"retrievable"`
}
type Supported struct {
Name string `json:"name"`
}
type Cookie struct {
Detail1 *string `json:"detail1,omitempty"`
Detail2 *string `json:"detail2,omitempty"`
}
type DiscoverRequest struct {
Scope Scope `json:"scope"`
}
type discovery struct {
sm *Smarthome
}
func (d *discovery) Discover(req DiscoverRequest) (interface{}, error) {
d.sm.Lock()
defer d.sm.Unlock()
res := DiscoverResponse{}
for _, device := range d.sm.devices {
res.DiscoveryEndpoints = append(
res.DiscoveryEndpoints,
DiscoveryEndpoint{
EndpointID: device.ID(),
Cookie: device.Cookie(),
Capabilities: device.Capabilities(),
ManufacturerName: device.ManufacturerName(),
FriendlyName: device.FriendlyName(),
Description: device.Description(),
DisplayCategories: device.DisplayCategories(),
},
)
}
return res, nil
}