1
0
mirror of https://github.com/cmur2/miflorad.git synced 2024-12-22 12:54:25 +01:00

munin-miflora: enrich underlying library errors with current operation using wrapping

This commit is contained in:
cn 2018-12-14 16:22:27 +01:00
parent c96878c22c
commit 4c348f2044
4 changed files with 9 additions and 12 deletions

View File

@ -16,7 +16,6 @@ import (
) )
const discoveryTimeout = 4 * time.Second const discoveryTimeout = 4 * time.Second
const connectionTimeout = 4 * time.Second
func readData(client ble.Client, profile *ble.Profile) { func readData(client ble.Client, profile *ble.Profile) {
prefix := flag.Args()[0] prefix := flag.Args()[0]

View File

@ -1,11 +1,10 @@
package ble package ble
import ( import (
"errors"
"miflorad/common" "miflorad/common"
"github.com/go-ble/ble" "github.com/go-ble/ble"
"github.com/pkg/errors"
) )
func FindServiceByUUID(services []*ble.Service, u ble.UUID) *ble.Service { func FindServiceByUUID(services []*ble.Service, u ble.UUID) *ble.Service {
@ -39,7 +38,7 @@ func RequestVersionBattery(client ble.Client, profile *ble.Profile) (common.Vers
bytes, err := client.ReadCharacteristic(mifloraVersionBatteryChar) bytes, err := client.ReadCharacteristic(mifloraVersionBatteryChar)
if err != nil { if err != nil {
return common.VersionBatteryResponse{}, err return common.VersionBatteryResponse{}, errors.Wrap(err, "can't read version battery")
} }
return common.ParseVersionBattery(bytes), nil return common.ParseVersionBattery(bytes), nil
@ -58,7 +57,7 @@ func RequestModeChange(client ble.Client, profile *ble.Profile) error {
err := client.WriteCharacteristic(mifloraModeChangeChar, common.MifloraGetModeChangeData(), false) err := client.WriteCharacteristic(mifloraModeChangeChar, common.MifloraGetModeChangeData(), false)
if err != nil { if err != nil {
return err return errors.Wrap(err, "can't change mode")
} }
return nil return nil
@ -77,7 +76,7 @@ func RequestSensorData(client ble.Client, profile *ble.Profile) (common.SensorDa
bytes, err := client.ReadCharacteristic(mifloraSensorDataChar) bytes, err := client.ReadCharacteristic(mifloraSensorDataChar)
if err != nil { if err != nil {
return common.SensorDataResponse{}, err return common.SensorDataResponse{}, errors.Wrap(err, "can't read sensor data")
} }
return common.ParseSensorData(bytes), nil return common.ParseSensorData(bytes), nil

View File

@ -1,11 +1,10 @@
package gatt package gatt
import ( import (
"errors"
"miflorad/common" "miflorad/common"
"github.com/currantlabs/gatt" "github.com/currantlabs/gatt"
"github.com/pkg/errors"
) )
var MifloraCharVersionBatteryUUID = gatt.MustParseUUID("00001a02-0000-1000-8000-00805f9b34fb") var MifloraCharVersionBatteryUUID = gatt.MustParseUUID("00001a02-0000-1000-8000-00805f9b34fb")
@ -41,7 +40,7 @@ func MifloraRequestVersionBattery(p gatt.Peripheral) (common.VersionBatteryRespo
bytes, err := p.ReadCharacteristic(mifloraVersionBatteryChar) bytes, err := p.ReadCharacteristic(mifloraVersionBatteryChar)
if err != nil { if err != nil {
return common.VersionBatteryResponse{}, err return common.VersionBatteryResponse{}, errors.Wrap(err, "can't read version battery")
} }
return common.ParseVersionBattery(bytes), nil return common.ParseVersionBattery(bytes), nil
@ -60,7 +59,7 @@ func MifloraRequestModeChange(p gatt.Peripheral) error {
err := p.WriteCharacteristic(mifloraModeChangeChar, common.MifloraGetModeChangeData(), false) err := p.WriteCharacteristic(mifloraModeChangeChar, common.MifloraGetModeChangeData(), false)
if err != nil { if err != nil {
return err return errors.Wrap(err, "can't change mode")
} }
return nil return nil
@ -79,7 +78,7 @@ func MifloraRequstSensorData(p gatt.Peripheral) (common.SensorDataResponse, erro
bytes, err := p.ReadCharacteristic(mifloraSensorDataChar) bytes, err := p.ReadCharacteristic(mifloraSensorDataChar)
if err != nil { if err != nil {
return common.SensorDataResponse{}, err return common.SensorDataResponse{}, errors.Wrap(err, "can't read sensor data")
} }
return common.ParseSensorData(bytes), nil return common.ParseSensorData(bytes), nil

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect
github.com/muka/ble v0.0.0-20180314094923-5613a57406d1 // indirect github.com/muka/ble v0.0.0-20180314094923-5613a57406d1 // indirect
github.com/muka/go-bluetooth v0.0.0-20181012115104-31d8f53bf9a1 github.com/muka/go-bluetooth v0.0.0-20181012115104-31d8f53bf9a1
github.com/pkg/errors v0.8.0 // indirect github.com/pkg/errors v0.8.0
github.com/sirupsen/logrus v1.2.0 // indirect github.com/sirupsen/logrus v1.2.0 // indirect
github.com/stretchr/testify v1.2.2 github.com/stretchr/testify v1.2.2
) )