1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-14 19:29:32 +08:00
hybridgroup.gobot/drivers/ble/battery_driver_test.go
2024-02-04 18:50:43 +01:00

34 lines
683 B
Go

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())
}