This repository has been archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
discovery.go
88 lines (75 loc) · 2 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
86
87
88
package fluxwifi
import (
"github.com/go-home-iot/connection-pool"
fluxwifiExt "github.com/go-home-iot/fluxwifi"
"github.com/markdaws/gohome/pkg/gohome"
"github.com/markdaws/gohome/pkg/feature"
)
var infos = []gohome.DiscovererInfo{gohome.DiscovererInfo{
ID: "fluxwifi.bulbs",
Name: "FluxWIFI Bulbs",
Description: "Discover FluxWIFI bulbs",
}}
type discovery struct {
//TODO: Needed?
System *gohome.System
}
func (d *discovery) Discoverers() []gohome.DiscovererInfo {
// Here we return all of the discoverers we support. There may be multiple types
// of hardware we can import, for each type, or even one piece of hardware with
// different software versions, which may need different plumbing, we return a
// discovery info, the Name/Description fields will be displayed to the user, then
// the ID is then passed back to the DiscovererFromID function, where we can then
// return the appropriate discoverer instance
return infos
}
func (d *discovery) DiscovererFromID(ID string) gohome.Discoverer {
switch ID {
case "fluxwifi.bulbs":
return &discoverer{infos[0]}
default:
return nil
}
}
type discoverer struct {
info gohome.DiscovererInfo
}
func (d *discoverer) Info() gohome.DiscovererInfo {
return d.info
}
func (d *discoverer) ScanDevices(sys *gohome.System, uiFields map[string]string) (*gohome.DiscoveryResults, error) {
infos, err := fluxwifiExt.Scan(5)
if err != nil {
return nil, err
}
devices := make([]*gohome.Device, len(infos))
for i, info := range infos {
name := info.ID + ": " + info.Model
modelNumber := "fluxwifi"
dev := gohome.NewDevice(
sys.NewID(),
name,
"",
modelNumber,
"",
"",
info.IP,
nil,
nil,
pool.NewPool(pool.Config{
Name: name,
Size: 2,
}),
nil,
)
light := feature.NewLightZone(sys.NewID(), feature.LightZoneModeHSL)
light.Name = dev.Name
light.Address = "1"
light.DeviceID = dev.ID
dev.AddFeature(light)
devices[i] = dev
}
return &gohome.DiscoveryResults{
Devices: devices,
}, nil
}