Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRGKick-BT charger: handle missing BT device #975

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
handle missing BT device
  • Loading branch information
BuildTools committed May 8, 2021
commit a8b45c14758a9fc42366f0a498fdbf1fce28adb9
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
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=
Expand Down
1 change: 1 addition & 0 deletions internal/charger/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 9 additions & 4 deletions internal/charger/nrgble_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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,
Expand Down