edgexfoundry / device-sdk-go

Owner: Device WG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicated function to set device operating state

ajcasagrande opened this issue · comments

// UpdateDeviceOperatingState updates the Device's OperatingState with given name
// in Core Metadata and device service cache.
func (s *deviceService) UpdateDeviceOperatingState(deviceName string, state string) error {
d, ok := cache.Devices().ForName(deviceName)
if !ok {
msg := fmt.Sprintf("failed to find Device %s in cache", deviceName)
s.lc.Error(msg)
return errors.NewCommonEdgeX(errors.KindEntityDoesNotExist, msg, nil)
}
s.lc.Debugf("Updating managed Device OperatingState %s", d.Name)
req := requests.UpdateDeviceRequest{
BaseRequest: commonDTO.NewBaseRequest(),
Device: dtos.UpdateDevice{
Name: &deviceName,
OperatingState: &state,
},
}
ctx := context.WithValue(context.Background(), common.CorrelationHeader, uuid.NewString()) // nolint:staticcheck
_, err := container.DeviceClientFrom(s.dic.Get).Update(ctx, []requests.UpdateDeviceRequest{req})
if err != nil {
s.lc.Errorf("failed to update Device %s OperatingState in Core Metadata: %v", d.Name, err)
}
return err
}
// SetDeviceOpState sets the operating state of device
func (s *deviceService) SetDeviceOpState(name string, state models.OperatingState) error {
d, err := s.GetDeviceByName(name)
if err != nil {
return err
}
d.OperatingState = state
return s.UpdateDevice(d)
}

Is there a reason for both? Should one of them be removed? Is one of them deprecated?

you are right. we should remove SetDeviceOpState