@@ -19,7 +19,7 @@ import (
1919 "github.com/BitBoxSwiss/bitbox02-api-go/util/errp"
2020)
2121
22- // nonAtomicQueryBluetooth is like query , but nested one level deeper for Bluetooth.
22+ // nonAtomicQueryBluetooth is like nonAtomicQuery , but nested one level deeper for Bluetooth.
2323func (device * Device ) nonAtomicQueryBluetooth (request * messages.BluetoothRequest ) (* messages.BluetoothResponse , error ) {
2424 if ! device .SupportsBluetooth () {
2525 return nil , errp .New ("this device does not support Bluetooth" )
@@ -39,6 +39,13 @@ func (device *Device) nonAtomicQueryBluetooth(request *messages.BluetoothRequest
3939 return bluetoothResponse .Bluetooth , nil
4040}
4141
42+ // queryBluetooth is like query, but nested one level deeper for Bluetooth.
43+ func (device * Device ) queryBluetooth (request * messages.BluetoothRequest ) (* messages.BluetoothResponse , error ) {
44+ return atomicQueriesValue (device , func () (* messages.BluetoothResponse , error ) {
45+ return device .nonAtomicQueryBluetooth (request )
46+ })
47+ }
48+
4249// BluetoothUpgrade attempts an upgrade of the Bluetooth firmware.
4350func (device * Device ) BluetoothUpgrade (firmware []byte ) error {
4451 return device .atomicQueries (func () error {
@@ -80,3 +87,20 @@ func (device *Device) BluetoothUpgrade(firmware []byte) error {
8087 }
8188 })
8289}
90+
91+ // BluetoothToggleEnabled enables/disables Bluetooth.
92+ func (device * Device ) BluetoothToggleEnabled () error {
93+ response , err := device .queryBluetooth (& messages.BluetoothRequest {
94+ Request : & messages.BluetoothRequest_ToggleEnabled {
95+ ToggleEnabled : & messages.BluetoothToggleEnabledRequest {},
96+ },
97+ })
98+ if err != nil {
99+ return err
100+ }
101+ _ , ok := response .Response .(* messages.BluetoothResponse_Success )
102+ if ! ok {
103+ return errp .New ("unexpected response" )
104+ }
105+ return nil
106+ }
0 commit comments