[refactor] Move mode in generic types module
This commit is contained in:
		@@ -2,7 +2,7 @@ package mqttdevice
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/cyrilix/robocar-base/mode"
 | 
			
		||||
	"github.com/cyrilix/robocar-base/types"
 | 
			
		||||
	MQTT "github.com/eclipse/paho.mqtt.golang"
 | 
			
		||||
	"io"
 | 
			
		||||
	"log"
 | 
			
		||||
@@ -128,12 +128,12 @@ func (m *MqttValue) Float64Value() (float64, error) {
 | 
			
		||||
func (m *MqttValue) StringValue() (string, error) {
 | 
			
		||||
	return string(*m), nil
 | 
			
		||||
}
 | 
			
		||||
func (m *MqttValue) DriveModeValue() (mode.DriveMode, error) {
 | 
			
		||||
func (m *MqttValue) DriveModeValue() (types.DriveMode, error) {
 | 
			
		||||
	val, err := m.IntValue()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return mode.DriveModeInvalid, err
 | 
			
		||||
		return types.DriveModeInvalid, err
 | 
			
		||||
	}
 | 
			
		||||
	return mode.DriveMode(val), nil
 | 
			
		||||
	return types.DriveMode(val), nil
 | 
			
		||||
}
 | 
			
		||||
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
 | 
			
		||||
	return *m, nil
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package mqttdevice
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/cyrilix/robocar-base/mode"
 | 
			
		||||
	"github.com/cyrilix/robocar-base/types"
 | 
			
		||||
	"github.com/cyrilix/robocar-base/testtools/docker"
 | 
			
		||||
	mqtt "github.com/eclipse/paho.mqtt.golang"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -192,11 +192,11 @@ func TestMqttValue_StringValue(t *testing.T) {
 | 
			
		||||
func TestMqttValue_DriveModeValue(t *testing.T) {
 | 
			
		||||
	cases := []struct {
 | 
			
		||||
		value    MqttValue
 | 
			
		||||
		expected mode.DriveMode
 | 
			
		||||
		expected types.DriveMode
 | 
			
		||||
	}{
 | 
			
		||||
		{NewMqttValue(mode.DriveModeUser), mode.DriveModeUser},
 | 
			
		||||
		{NewMqttValue(mode.DriveModePilot), mode.DriveModePilot},
 | 
			
		||||
		{NewMqttValue(mode.DriveModeInvalid), mode.DriveModeInvalid},
 | 
			
		||||
		{NewMqttValue(types.DriveModeUser), types.DriveModeUser},
 | 
			
		||||
		{NewMqttValue(types.DriveModePilot), types.DriveModePilot},
 | 
			
		||||
		{NewMqttValue(types.DriveModeInvalid), types.DriveModeInvalid},
 | 
			
		||||
	}
 | 
			
		||||
	for _, c := range cases {
 | 
			
		||||
		val, err := c.value.DriveModeValue()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user