From e8d33b64177d845a251f1d3a58469a9d18c7cbc5 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Wed, 6 Nov 2024 13:51:48 +0100 Subject: [PATCH] Move and update api.ManufacturerData - move api.ManufacturerData to usecases/api - fix serialization not to use SPINE schema --- api/usecases.go | 15 --------------- usecases/api/cem_evcc.go | 2 +- usecases/api/cem_evsecc.go | 2 +- usecases/api/types.go | 16 ++++++++++++++++ usecases/cem/evcc/public.go | 4 ++-- usecases/cem/evsecc/public.go | 5 +++-- usecases/internal/manufacturerdata.go | 10 +++++----- usecases/mocks/CemEVCCInterface.go | 16 ++++++++-------- usecases/mocks/CemEVSECCInterface.go | 18 ++++++++++-------- 9 files changed, 46 insertions(+), 42 deletions(-) diff --git a/api/usecases.go b/api/usecases.go index c3af4366..bb120ee7 100644 --- a/api/usecases.go +++ b/api/usecases.go @@ -59,18 +59,3 @@ type UseCaseInterface interface { // add the features AddFeatures() } - -type ManufacturerData struct { - DeviceName string `json:"deviceName,omitempty"` - DeviceCode string `json:"deviceCode,omitempty"` - SerialNumber string `json:"serialNumber,omitempty"` - SoftwareRevision string `json:"softwareRevision,omitempty"` - HardwareRevision string `json:"hardwareRevision,omitempty"` - VendorName string `json:"vendorName,omitempty"` - VendorCode string `json:"vendorCode,omitempty"` - BrandName string `json:"brandName,omitempty"` - PowerSource string `json:"powerSource,omitempty"` - ManufacturerNodeIdentification string `json:"manufacturerNodeIdentification,omitempty"` - ManufacturerLabel string `json:"manufacturerLabel,omitempty"` - ManufacturerDescription string `json:"manufacturerDescription,omitempty"` -} diff --git a/usecases/api/cem_evcc.go b/usecases/api/cem_evcc.go index f8b3fdb0..6dc89f46 100644 --- a/usecases/api/cem_evcc.go +++ b/usecases/api/cem_evcc.go @@ -57,7 +57,7 @@ type CemEVCCInterface interface { // // parameters: // - entity: the entity of the EV - ManufacturerData(entity spineapi.EntityRemoteInterface) (api.ManufacturerData, error) + ManufacturerData(entity spineapi.EntityRemoteInterface) (ManufacturerData, error) // Scenario 6 diff --git a/usecases/api/cem_evsecc.go b/usecases/api/cem_evsecc.go index 1d7aaf3d..fc08dd1b 100644 --- a/usecases/api/cem_evsecc.go +++ b/usecases/api/cem_evsecc.go @@ -17,7 +17,7 @@ type CemEVSECCInterface interface { // - entity: the entity of the EV // // returns deviceName, serialNumber, error - ManufacturerData(entity spineapi.EntityRemoteInterface) (api.ManufacturerData, error) + ManufacturerData(entity spineapi.EntityRemoteInterface) (ManufacturerData, error) // the operating state data of an EVSE // diff --git a/usecases/api/types.go b/usecases/api/types.go index a5661b76..52a7f54e 100644 --- a/usecases/api/types.go +++ b/usecases/api/types.go @@ -17,6 +17,22 @@ const ( EVChargeStateTypeFinished EVChargeStateType = "finished" ) +// manufacturer data type +type ManufacturerData struct { + DeviceName string + DeviceCode string + SerialNumber string + SoftwareRevision string + HardwareRevision string + VendorName string + VendorCode string + BrandName string + PowerSource string + ManufacturerNodeIdentification string + ManufacturerLabel string + ManufacturerDescription string +} + // Defines a phase specific limit data set type LoadLimitsPhase struct { Phase model.ElectricalConnectionPhaseNameType // the phase diff --git a/usecases/cem/evcc/public.go b/usecases/cem/evcc/public.go index bee47fcd..a194e8d8 100644 --- a/usecases/cem/evcc/public.go +++ b/usecases/cem/evcc/public.go @@ -193,11 +193,11 @@ func (e *EVCC) Identifications(entity spineapi.EntityRemoteInterface) ([]ucapi.I func (e *EVCC) ManufacturerData( entity spineapi.EntityRemoteInterface, ) ( - api.ManufacturerData, + ucapi.ManufacturerData, error, ) { if !e.IsCompatibleEntityType(entity) { - return api.ManufacturerData{}, api.ErrNoCompatibleEntity + return ucapi.ManufacturerData{}, api.ErrNoCompatibleEntity } return internal.ManufacturerData(e.LocalEntity, entity) diff --git a/usecases/cem/evsecc/public.go b/usecases/cem/evsecc/public.go index 1a76c6a1..070a7d10 100644 --- a/usecases/cem/evsecc/public.go +++ b/usecases/cem/evsecc/public.go @@ -3,6 +3,7 @@ package evsecc import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/client" + ucapi "github.com/enbility/eebus-go/usecases/api" "github.com/enbility/eebus-go/usecases/internal" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" @@ -13,11 +14,11 @@ import ( func (e *EVSECC) ManufacturerData( entity spineapi.EntityRemoteInterface, ) ( - api.ManufacturerData, + ucapi.ManufacturerData, error, ) { if !e.IsCompatibleEntityType(entity) { - return api.ManufacturerData{}, api.ErrNoCompatibleEntity + return ucapi.ManufacturerData{}, api.ErrNoCompatibleEntity } return internal.ManufacturerData(e.LocalEntity, entity) diff --git a/usecases/internal/manufacturerdata.go b/usecases/internal/manufacturerdata.go index d44f380d..97535090 100644 --- a/usecases/internal/manufacturerdata.go +++ b/usecases/internal/manufacturerdata.go @@ -1,8 +1,8 @@ package internal import ( - "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/client" + ucapi "github.com/enbility/eebus-go/usecases/api" spineapi "github.com/enbility/spine-go/api" ) @@ -11,18 +11,18 @@ import ( // possible errors: // - ErrNoCompatibleEntity if entity is not compatible // - and others -func ManufacturerData(localEntity spineapi.EntityLocalInterface, entity spineapi.EntityRemoteInterface) (api.ManufacturerData, error) { +func ManufacturerData(localEntity spineapi.EntityLocalInterface, entity spineapi.EntityRemoteInterface) (ucapi.ManufacturerData, error) { deviceClassification, err := client.NewDeviceClassification(localEntity, entity) if err != nil { - return api.ManufacturerData{}, err + return ucapi.ManufacturerData{}, err } data, err := deviceClassification.GetManufacturerDetails() if err != nil { - return api.ManufacturerData{}, err + return ucapi.ManufacturerData{}, err } - ret := api.ManufacturerData{ + ret := ucapi.ManufacturerData{ DeviceName: Deref((*string)(data.DeviceName)), DeviceCode: Deref((*string)(data.DeviceCode)), SerialNumber: Deref((*string)(data.SerialNumber)), diff --git a/usecases/mocks/CemEVCCInterface.go b/usecases/mocks/CemEVCCInterface.go index 3bf596f9..4ba5ea83 100644 --- a/usecases/mocks/CemEVCCInterface.go +++ b/usecases/mocks/CemEVCCInterface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -630,22 +630,22 @@ func (_c *CemEVCCInterface_IsScenarioAvailableAtEntity_Call) RunAndReturn(run fu } // ManufacturerData provides a mock function with given fields: entity -func (_m *CemEVCCInterface) ManufacturerData(entity spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error) { +func (_m *CemEVCCInterface) ManufacturerData(entity spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error) { ret := _m.Called(entity) if len(ret) == 0 { panic("no return value specified for ManufacturerData") } - var r0 eebus_goapi.ManufacturerData + var r0 api.ManufacturerData var r1 error - if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error)); ok { + if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error)); ok { return rf(entity) } - if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) eebus_goapi.ManufacturerData); ok { + if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) api.ManufacturerData); ok { r0 = rf(entity) } else { - r0 = ret.Get(0).(eebus_goapi.ManufacturerData) + r0 = ret.Get(0).(api.ManufacturerData) } if rf, ok := ret.Get(1).(func(spine_goapi.EntityRemoteInterface) error); ok { @@ -675,12 +675,12 @@ func (_c *CemEVCCInterface_ManufacturerData_Call) Run(run func(entity spine_goap return _c } -func (_c *CemEVCCInterface_ManufacturerData_Call) Return(_a0 eebus_goapi.ManufacturerData, _a1 error) *CemEVCCInterface_ManufacturerData_Call { +func (_c *CemEVCCInterface_ManufacturerData_Call) Return(_a0 api.ManufacturerData, _a1 error) *CemEVCCInterface_ManufacturerData_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *CemEVCCInterface_ManufacturerData_Call) RunAndReturn(run func(spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error)) *CemEVCCInterface_ManufacturerData_Call { +func (_c *CemEVCCInterface_ManufacturerData_Call) RunAndReturn(run func(spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error)) *CemEVCCInterface_ManufacturerData_Call { _c.Call.Return(run) return _c } diff --git a/usecases/mocks/CemEVSECCInterface.go b/usecases/mocks/CemEVSECCInterface.go index 5b577631..6650e628 100644 --- a/usecases/mocks/CemEVSECCInterface.go +++ b/usecases/mocks/CemEVSECCInterface.go @@ -1,9 +1,11 @@ -// Code generated by mockery v2.43.2. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks import ( eebus_goapi "github.com/enbility/eebus-go/api" + api "github.com/enbility/eebus-go/usecases/api" + mock "github.com/stretchr/testify/mock" model "github.com/enbility/spine-go/model" @@ -230,22 +232,22 @@ func (_c *CemEVSECCInterface_IsScenarioAvailableAtEntity_Call) RunAndReturn(run } // ManufacturerData provides a mock function with given fields: entity -func (_m *CemEVSECCInterface) ManufacturerData(entity spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error) { +func (_m *CemEVSECCInterface) ManufacturerData(entity spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error) { ret := _m.Called(entity) if len(ret) == 0 { panic("no return value specified for ManufacturerData") } - var r0 eebus_goapi.ManufacturerData + var r0 api.ManufacturerData var r1 error - if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error)); ok { + if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error)); ok { return rf(entity) } - if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) eebus_goapi.ManufacturerData); ok { + if rf, ok := ret.Get(0).(func(spine_goapi.EntityRemoteInterface) api.ManufacturerData); ok { r0 = rf(entity) } else { - r0 = ret.Get(0).(eebus_goapi.ManufacturerData) + r0 = ret.Get(0).(api.ManufacturerData) } if rf, ok := ret.Get(1).(func(spine_goapi.EntityRemoteInterface) error); ok { @@ -275,12 +277,12 @@ func (_c *CemEVSECCInterface_ManufacturerData_Call) Run(run func(entity spine_go return _c } -func (_c *CemEVSECCInterface_ManufacturerData_Call) Return(_a0 eebus_goapi.ManufacturerData, _a1 error) *CemEVSECCInterface_ManufacturerData_Call { +func (_c *CemEVSECCInterface_ManufacturerData_Call) Return(_a0 api.ManufacturerData, _a1 error) *CemEVSECCInterface_ManufacturerData_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *CemEVSECCInterface_ManufacturerData_Call) RunAndReturn(run func(spine_goapi.EntityRemoteInterface) (eebus_goapi.ManufacturerData, error)) *CemEVSECCInterface_ManufacturerData_Call { +func (_c *CemEVSECCInterface_ManufacturerData_Call) RunAndReturn(run func(spine_goapi.EntityRemoteInterface) (api.ManufacturerData, error)) *CemEVSECCInterface_ManufacturerData_Call { _c.Call.Return(run) return _c }