blob: 172d3709cc4d81c52fee5c3387c9fa72f1e80fda (
plain)
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
|
package main
import (
"log"
"os"
"encoding/xml"
"net/http"
"io/ioutil"
)
func main() {
log.Println("Test")
}
type Bridge struct {
IPAddress string
Username string
Info BridgeInfo
}
type BridgeInfo struct {
DeviceType string
FriendlyName string
ManufacturerURL string
ModelDescription string
ModelName string
ModelNumber string
ModelURL string
SerialNumber string
UDN string
}
func NewBridge(ip string) *Bridge {
// TODO: if yaml file exists then return
bridge := Bridge {
IPAddress: ip,
// TODO: other defaults here
}
bridge.Info = GetBridgeInfo("192.168.1.128") // TODO: IP var
return &bridge
}
// Go to http://<bridge_ip>/description.xml and parse the info
func GetBridgeInfo(ip string) BridgeInfo {
response, error := http.Get(ip + "/description.xml")
if response.StatusCode != 200 {
log.Println("Bridge status error: %d", response.StatusCode)
os.Exit(1)
}
body, error := ioutil.ReadAll(response.Body)
if error != nil {
log.Println("Error parsing bridge description XML")
os.Exit(1)
}
data := make(map[string]string)
error = xml.Unmarshal(body, data)
if error != nil {
log.Println("GetBridgeInfo error. Cannot parse data from description.")
}
log.Println(data["FriendlyName"])
return BridgeInfo{} // TODO: fill in
}
|