github.com/tommi2day/gomodules@v1.13.2-0.20240423190010-b7d55d252a27/hmlib/rssi.go (about) 1 package hmlib 2 3 import ( 4 "encoding/xml" 5 "fmt" 6 7 log "github.com/sirupsen/logrus" 8 ) 9 10 // RssiEndpoint is the endpoint for the device list 11 const RssiEndpoint = "/addons/xmlapi/rssilist.cgi" 12 13 // RssiListResponse is a list of devices returned by API 14 type RssiListResponse struct { 15 XMLName xml.Name `xml:"rssiList"` 16 RssiDevices []RssiDevice `xml:"rssi"` 17 } 18 19 // RssiDevice returns Rssi values for a single device 20 type RssiDevice struct { 21 XMLName xml.Name `xml:"rssi"` 22 Device string `xml:"device,attr"` 23 Rx string `xml:"rx,attr"` 24 Tx string `xml:"tx,attr"` 25 } 26 27 // RssiDeviceMap is a list of rssi devices by name 28 var RssiDeviceMap = make(map[string]RssiDevice) 29 30 // GetRssiList returns the rssi list of hm devices 31 func GetRssiList() (result RssiListResponse, err error) { 32 log.Debug("getrssi called") 33 err = QueryAPI(RssiEndpoint, &result, nil) 34 for _, v := range result.RssiDevices { 35 RssiDeviceMap[v.Device] = v 36 } 37 log.Debugf("getRSSI returned %d entries", len(result.RssiDevices)) 38 return 39 } 40 41 // String returns a string representation of the device list 42 func (e RssiListResponse) String() string { 43 var s string 44 for _, v := range e.RssiDevices { 45 s += fmt.Sprintf("%s\n", v) 46 } 47 return s 48 } 49 50 // String returns a string representation of the device list 51 func (e RssiDevice) String() string { 52 return fmt.Sprintf("Address:%s rx:%s tx: %s", e.Device, e.Rx, e.Tx) 53 }