diff --git a/usecases/api/cem_ohpcf.go b/usecases/api/cem_ohpcf.go index 2dbde8e0..1fd930ea 100644 --- a/usecases/api/cem_ohpcf.go +++ b/usecases/api/cem_ohpcf.go @@ -71,8 +71,8 @@ type CemOHPCFInterface interface { // scheduled process has not startet yet. // // parameters: - // - start: The start time of the power consumption - SchedulePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, start time.Time, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) + // - startIn: Delay from now until the power consumption starts (0 = start immediately) + SchedulePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, startIn time.Duration, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) // stop (abort) the process [OHPCF-022/1]. AbortPowerConsumptionProcess(entity spineapi.EntityRemoteInterface, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) diff --git a/usecases/cem/ohpcf/events.go b/usecases/cem/ohpcf/events.go index ebc1656e..23a4ccf6 100644 --- a/usecases/cem/ohpcf/events.go +++ b/usecases/cem/ohpcf/events.go @@ -43,6 +43,11 @@ func (o *OHPCF) connected(entity spineapi.EntityRemoteInterface) { logging.Log().Debug(err) } } + + // read the current data as a subscription only delivers future updates + if _, err := semp.RequestData(); err != nil { + logging.Log().Debug(err) + } } } diff --git a/usecases/cem/ohpcf/public.go b/usecases/cem/ohpcf/public.go index 781fcd40..88f8e4df 100644 --- a/usecases/cem/ohpcf/public.go +++ b/usecases/cem/ohpcf/public.go @@ -291,8 +291,8 @@ func (o *OHPCF) PowerConsumptionMinimalPauseDuration(entity spineapi.EntityRemot // scheduled process did not start. // // parameters: -// - start: The start time of the power consumption -func (o *OHPCF) SchedulePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, start time.Time, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) { +// - startIn: Delay from now until the power consumption starts (0 = start immediately) +func (o *OHPCF) SchedulePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, startIn time.Duration, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) { info, err := o.OptionalPowerConsumption(entity) if err != nil { return nil, err @@ -305,7 +305,9 @@ func (o *OHPCF) SchedulePowerConsumptionProcess(entity spineapi.EntityRemoteInte SequenceId: &info.PowerSequenceId, }, Schedule: &model.PowerSequenceScheduleDataType{ - StartTime: model.NewAbsoluteOrRelativeTimeTypeFromTime(start), + // relative start time (ISO 8601 duration); heat pumps advertise their + // scheduling constraints relative as well, so keep the schedule relative + StartTime: model.NewAbsoluteOrRelativeTimeTypeFromDuration(startIn), }, }}, }}, diff --git a/usecases/cem/ohpcf/public_test.go b/usecases/cem/ohpcf/public_test.go index 2f988a9f..2ebef37f 100644 --- a/usecases/cem/ohpcf/public_test.go +++ b/usecases/cem/ohpcf/public_test.go @@ -265,11 +265,11 @@ func (s *CemOhPCFSuite) Test_PowerConsumptionMinimalPauseDuration() { // Scenario 2 func (s *CemOhPCFSuite) Test_SchedulePowerConsumptionProcess() { - _, err := s.sut.SchedulePowerConsumptionProcess(s.mockRemoteEntity, time.Now(), nil) + _, err := s.sut.SchedulePowerConsumptionProcess(s.mockRemoteEntity, 0, nil) assert.NotNil(s.T(), err) // Without valid data, the call should fail - _, err = s.sut.SchedulePowerConsumptionProcess(s.monitoredEntity, time.Now(), nil) + _, err = s.sut.SchedulePowerConsumptionProcess(s.monitoredEntity, 0, nil) assert.NotNil(s.T(), err) // Set up valid SmartEnergyManagementPs data @@ -302,8 +302,7 @@ func (s *CemOhPCFSuite) Test_SchedulePowerConsumptionProcess() { _, fErr := rFeature.UpdateData(true, model.FunctionTypeSmartEnergyManagementPsData, data, nil, nil) assert.Nil(s.T(), fErr) - startTime := time.Now().Add(time.Hour) - msgCounter, err := s.sut.SchedulePowerConsumptionProcess(s.monitoredEntity, startTime, nil) + msgCounter, err := s.sut.SchedulePowerConsumptionProcess(s.monitoredEntity, time.Hour, nil) assert.NotNil(s.T(), msgCounter) assert.Nil(s.T(), err) } diff --git a/usecases/cem/ohpcf/usecase.go b/usecases/cem/ohpcf/usecase.go index c40284b2..2a81ed56 100644 --- a/usecases/cem/ohpcf/usecase.go +++ b/usecases/cem/ohpcf/usecase.go @@ -49,6 +49,8 @@ func NewOHPCF(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEvent UseCaseBase: usecase, } + _ = localEntity.Device().Events().Subscribe(uc) + return uc }