1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-13 19:29:10 +08:00
hybridgroup.gobot/drivers/ble/battery_driver_test.go

34 lines
683 B
Go
Raw Normal View History

package ble
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/ble/testutil"
)
var _ gobot.Driver = (*BatteryDriver)(nil)
func TestNewBatteryDriver(t *testing.T) {
d := NewBatteryDriver(testutil.NewBleTestAdaptor())
assert.True(t, strings.HasPrefix(d.Name(), "Battery"))
assert.NotNil(t, d.Eventer)
}
func TestBatteryDriverRead(t *testing.T) {
a := testutil.NewBleTestAdaptor()
d := NewBatteryDriver(a)
a.SetReadCharacteristicTestFunc(func(cUUID string) ([]byte, error) {
if cUUID == "2a19" {
return []byte{20}, nil
}
return nil, nil
})
assert.Equal(t, uint8(20), d.GetBatteryLevel())
}