Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions usecases/api/cem_ohpcf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions usecases/cem/ohpcf/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions usecases/cem/ohpcf/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
},
}},
}},
Expand Down
7 changes: 3 additions & 4 deletions usecases/cem/ohpcf/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions usecases/cem/ohpcf/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func NewOHPCF(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEvent
UseCaseBase: usecase,
}

_ = localEntity.Device().Events().Subscribe(uc)

return uc
}

Expand Down
Loading