-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_line_modem.go
48 lines (40 loc) · 1.39 KB
/
power_line_modem.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
package insteon
import (
"context"
"fmt"
"net/url"
)
// PowerLineModem represnts a powerline modem.
type PowerLineModem interface {
GetIMInfo(ctx context.Context) (imInfo *IMInfo, err error)
GetAllLinkDB(ctx context.Context) (records AllLinkRecordSlice, err error)
GetDeviceState(ctx context.Context, identity ID) (state *LightState, err error)
SetDeviceState(ctx context.Context, identity ID, state LightState) (err error)
GetDeviceInfo(ctx context.Context, identity ID) (deviceInfo *DeviceInfo, err error)
SetDeviceInfo(ctx context.Context, identity ID, deviceInfo DeviceInfo) error
Beep(ctx context.Context, identity ID) (err error)
Monitor(ctx context.Context, events chan<- DeviceEvent) error
}
// DefaultPowerLineModem is the default PowerLine Modem instance.
var DefaultPowerLineModem = func() PowerLineModem {
plm, err := NewPowerLineModem(PowerLineModemDevice)
if err != nil {
panic(fmt.Errorf("instanciating default PowerLine Modem: %s", err))
}
return plm
}()
// NewPowerLineModem instantiates a new PowerLine Modem.
func NewPowerLineModem(device string) (PowerLineModem, error) {
url, err := url.Parse(device)
if err != nil {
return nil, fmt.Errorf("parsing device: %s", err)
}
switch url.Scheme {
case "http", "https":
return NewHTTPPowerLineModem(url.String())
case "tcp":
return NewRemotePowerLineModem(url.Host)
default:
return NewLocalPowerLineModem(url.String())
}
}