NRGKick-Bluetooth: handle missing BT device (#975)

This commit is contained in:
Markus Thierolf 2021-05-08 13:19:38 +02:00 • committed by GitHub
parent e3dd38f6d5
commit 2bc01d1f08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

2
go.mod
View file

@ -48,7 +48,7 @@ require (
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33
github.com/muka/go-bluetooth v0.0.0-20210508070623-03c23c62f181
github.com/mxschmitt/golang-combinations v1.1.0
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da
github.com/olekukonko/tablewriter v0.0.5

4
go.sum
View file

@ -506,8 +506,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/muka/go-bluetooth v0.0.0-20200619025933-f6113f7141c5/go.mod h1:yV39+EVOWdnoTe75NyKdo9iuyI3Slyh4t7eQvElUbWE=
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 h1:p3srutpE8TpQmOUQ5Qw94jYFUdoG2jBbILeYLroQNoI=
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
github.com/muka/go-bluetooth v0.0.0-20210508070623-03c23c62f181 h1:2WJZHTfZO2VOzRuVeEXI8Vjy+UAIvugGa+bVhni576I=
github.com/muka/go-bluetooth v0.0.0-20210508070623-03c23c62f181/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxschmitt/golang-combinations v1.1.0 h1:WlIZCnDm+Xlb2pRPf+R/qPKlGOU1w8lpN69/uy5z+Zg=

View file

@ -16,6 +16,7 @@ func TestChargers(t *testing.T) {
"invalid charger type: nrgkick-bluetooth",
"NRGKick bluetooth is only supported on linux",
"invalid pin:",
"hciconfig provided no response",
"connect: no route to host",
"connect: connection refused",
"error connecting: Network Error",

View file

@ -60,14 +60,19 @@ func NewNRGKickBLEFromConfig(other map[string]interface{}) (api.Charger, error)
func NewNRGKickBLE(device, mac string, pin int) (*NRGKickBLE, error) {
logger := util.NewLogger("nrg-bt")
ainfo, err := hw.GetAdapter(device)
if err != nil {
return nil, err
}
// set LE mode
btmgmt := hw.NewBtMgmt(device)
btmgmt := hw.NewBtMgmt(ainfo.AdapterID)
if len(os.Getenv("DOCKER")) > 0 {
btmgmt.BinPath = "./docker-btmgmt"
}
err := btmgmt.SetPowered(false)
err = btmgmt.SetPowered(false)
if err == nil {
err = btmgmt.SetLe(true)
if err == nil {
@ -82,7 +87,7 @@ func NewNRGKickBLE(device, mac string, pin int) (*NRGKickBLE, error) {
return nil, err
}
adapt, err := adapter.NewAdapter1FromAdapterID(device)
adapt, err := adapter.NewAdapter1FromAdapterID(ainfo.AdapterID)
if err != nil {
return nil, err
}
@ -105,7 +110,7 @@ func NewNRGKickBLE(device, mac string, pin int) (*NRGKickBLE, error) {
nrg := &NRGKickBLE{
log: logger,
timer: time.NewTimer(1),
device: device,
device: ainfo.AdapterID,
mac: mac,
pin: pin,
adapter: adapt,