/
init.go
executable file
·49 lines (43 loc) · 1.28 KB
/
init.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
/*
Go Language Raspberry Pi Interface
(c) Copyright David Thorpe 2016-2018
All Rights Reserved
Documentation http://djthorpe.github.io/gopi/
For Licensing and Usage information, please see LICENSE.md
*/
package mihome
import (
// Frameworks
gopi "github.com/djthorpe/gopi"
sensors "github.com/djthorpe/sensors"
)
////////////////////////////////////////////////////////////////////////////////
// INIT
func init() {
// Register server
gopi.RegisterModule(gopi.Module{
Name: "rpc/mihome:service",
Type: gopi.MODULE_TYPE_SERVICE,
Requires: []string{"rpc/server", "sensors/mihome"},
New: func(app *gopi.AppInstance) (gopi.Driver, error) {
return gopi.Open(Service{
Server: app.ModuleInstance("rpc/server").(gopi.RPCServer),
MiHome: app.ModuleInstance("sensors/mihome").(sensors.MiHome),
}, app.Logger)
},
})
// Register client
gopi.RegisterModule(gopi.Module{
Name: "rpc/mihome:client",
Type: gopi.MODULE_TYPE_CLIENT,
Requires: []string{"rpc/clientpool"},
Run: func(app *gopi.AppInstance, _ gopi.Driver) error {
if clientpool := app.ModuleInstance("rpc/clientpool").(gopi.RPCClientPool); clientpool == nil {
return gopi.ErrAppError
} else {
clientpool.RegisterClient("mihome.MiHome", NewMiHomeClient)
return nil
}
},
})
}