* -------------------- Exported Functions -------------------- */ Add takes a chunk of raw text and attempts to parse it as managed device data and create an attribute map from it. * A typical chunk will look like: "LowBatteryNotificationPercentage" = 2 "BatteryFaultNotificationType" = "T
(chunk string)
| 92 | } |
| 93 | */ |
| 94 | func (manDev *ManagedDevice) Add(chunk string) { |
| 95 | scanner := bufio.NewScanner(strings.NewReader(chunk)) |
| 96 | |
| 97 | for scanner.Scan() { |
| 98 | line := strings.ReplaceAll(scanner.Text(), "\"", "") |
| 99 | |
| 100 | pieces := strings.Split(line, "=") |
| 101 | if len(pieces) == 2 { |
| 102 | left := strings.TrimSpace(pieces[0]) |
| 103 | right := strings.TrimSpace(pieces[1]) |
| 104 | |
| 105 | manDev.Attributes[left] = right |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // Dump writes out all the device attributes as a single string |
| 111 | func (manDev *ManagedDevice) Dump() string { |
no outgoing calls