func (batGroup *batteryGroup) setDeviceLsit() { batGroup.changeLock.Lock() defer batGroup.changeLock.Unlock() devs, err := upower.EnumerateDevices() if err != nil { logger.Error("Can't EnumerateDevices", err) return } var tmpList []*batteryDevice for _, path := range devs { dev, err := libupower.NewDevice(UPOWER_BUS_NAME, path) if err != nil { logger.Warning("New Device Object Failed:", err) continue } if dev.Type.Get() != DeviceTypeBattery { logger.Debug("Not battery device:", path) continue } tmpList = append(tmpList, newBatteryDevice(dev, batGroup.propChangedHandler)) } batGroup.BatList = tmpList }
func (batGroup *batteryGroup) AddBatteryDevice(path dbus.ObjectPath) { batGroup.changeLock.Lock() defer batGroup.changeLock.Unlock() if batGroup.isBatteryPathExist(path) { return } dev, err := libupower.NewDevice(UPOWER_BUS_NAME, dbus.ObjectPath(path)) if err != nil { logger.Warning("New Device Failed:", err) return } if dev.Type.Get() != DeviceTypeBattery { return } batGroup.BatList = append(batGroup.BatList, newBatteryDevice(dev, batGroup.propChangedHandler)) }