Skip to content

Commit

Permalink
linux: check adapter powered state before connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenart12 authored and deadprogram committed Feb 25, 2025
1 parent 6a081be commit 5424550
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err
a.bus.AddMatchSignal(propertiesChangedMatchOptions...)
defer a.bus.RemoveMatchSignal(propertiesChangedMatchOptions...)

powered, err := a.adapter.GetProperty("org.bluez.Adapter1.Powered")
if err != nil {
return Device{}, err
}
if !powered.Value().(bool) {
return Device{}, errAdaptorNotPowered
}

// Read whether this device is already connected.
connected, err := device.device.GetProperty("org.bluez.Device1.Connected")
if err != nil {
Expand Down

0 comments on commit 5424550

Please sign in to comment.