-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.go
More file actions
41 lines (33 loc) · 769 Bytes
/
device.go
File metadata and controls
41 lines (33 loc) · 769 Bytes
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
package dmc
import (
"fmt"
"net"
"time"
)
type Device struct {
Name string
IP net.IP
Model string
}
func (d *Device) String() string {
return fmt.Sprintf("%s [%s]: %s", d.Name, d.IP.String(), d.Model)
}
func (d *Device) Match(model Model) bool {
return model.MatchString(d.Model)
}
func (d *Device) Identify(model Model, orig string, timeout time.Duration, retries int) (*State, error) {
return model.Identify(orig, d.IP, timeout, retries)
}
func (d *Device) Discover(model Model, orig string, timeout time.Duration, retries int) *State {
for _, g := range model.Groups() {
for _, m := range ModelList {
if !m.Group(g) {
continue
}
if s, _ := d.Identify(m, orig, timeout, retries); s != nil {
return s
}
}
}
return nil
}