-
Notifications
You must be signed in to change notification settings - Fork 48
Implement cem/ohpcf #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sthelen-enqs
wants to merge
13
commits into
dev
Choose a base branch
from
implement-cem-ohpcf
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Implement cem/ohpcf #223
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
523bd38
Initial
nils-prommersberger a6189fb
additional event handling for abortion (stop-event) and better error …
nils-prommersberger 38a1871
Resolve Changes
nils-prommersberger 143285b
Namensänderungen
nils-prommersberger a7814af
bugfixes:
nils-prommersberger d78f3d0
Ensure CEM OHPCF creates binding upon connection with remote device.
TomLucaRoth 03fd8d0
Send sequenceId when requesting state changes (mandatory per spec)
TomLucaRoth cbb65df
send correct state when pausing consumption process
TomLucaRoth b8fc974
fixed error return
TomLucaRoth 46a86e6
Added OptionalPowerConsumption method to interface of CEM OHPCF
TomLucaRoth b4b5b4f
Merge branch 'dev' into implement-cem-ohpcf
nils-prommersberger 00c54db
fix merge and implement tests
nils-prommersberger abdcf86
remove break in events.go
nils-prommersberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "github.com/enbility/eebus-go/api" | ||
| spineapi "github.com/enbility/spine-go/api" | ||
| "github.com/enbility/spine-go/model" | ||
| "time" | ||
| ) | ||
|
|
||
| type CemOHPCFInterface interface { | ||
| api.UseCaseInterface | ||
|
|
||
| // Scenario 1 | ||
|
|
||
| // Get all relevant info for an available power consumption | ||
| // | ||
| // return OptionalPowerConsumptionInfo struct with all available info if an optional power consumption has been announced | ||
| OptionalPowerConsumption(entity spineapi.EntityRemoteInterface) (*OptionalPowerConsumptionInfo, error) | ||
|
|
||
| // The availability of an optional consumption of power [OHPCF-011/1]. | ||
| // | ||
| // return true if the optional consumption of power is possible | ||
| OptionalPowerConsumptionAvailable(entity spineapi.EntityRemoteInterface) (bool, error) | ||
|
|
||
| // The requested power estimate value [OHPCF-011/2/1]. | ||
| // | ||
| // return the requested power estimate value | ||
| RequestedPowerEstimate(entity spineapi.EntityRemoteInterface) (float64, error) | ||
|
|
||
| // The maximal value for the requested power estimate [OHPCF-011/2/1]. | ||
| // | ||
| // return the maximal value for the requested power estimate | ||
| RequestedPowerMax(entity spineapi.EntityRemoteInterface) (float64, error) | ||
|
|
||
| // Indication whether the consumption may be stopped by the CEM [OHPCF-011/5]. | ||
| // | ||
| // return true if the consumption may be stopped | ||
| ConsumptionIsStoppable(entity spineapi.EntityRemoteInterface) (bool, error) | ||
|
|
||
| // Indication whether the consumption may be paused and resumed by the CEM [OHPCF-011/6] | ||
| // | ||
| // return true if the consumption may be paused | ||
| ConsumptionIsPausable(entity spineapi.EntityRemoteInterface) (bool, error) | ||
|
|
||
| // The start time of the process [OHPCF-012/1]. | ||
| // | ||
| // return the start time of the process | ||
| PowerConsumptionProcessStartTime(entity spineapi.EntityRemoteInterface) (time.Time, error) | ||
|
|
||
| // The current state of this power consumption process [OHPCF-012/2]. | ||
| // | ||
| // return the current state of this power consumption process | ||
| PowerConsumptionProcessState(entity spineapi.EntityRemoteInterface) (CompressorPowerConsumptionStateType, error) | ||
|
|
||
| // The minimal time a consumption process must last [OHPCF-008]. | ||
| // | ||
| // return the minimal time a consumption process must last | ||
| PowerConsumptionMinimalRunDuration(entity spineapi.EntityRemoteInterface) (time.Duration, error) | ||
|
|
||
| // The minimal time a pause of a consumption process must last [OHPCF-009]. | ||
| // | ||
| // return the minimal time a pause of a consumption process must last | ||
| PowerConsumptionMinimalPauseDuration(entity spineapi.EntityRemoteInterface) (time.Duration, error) | ||
|
|
||
| // Scenario 2 | ||
|
|
||
| // Schedule an optional power consumption process [OHPCF-004]. | ||
| // | ||
| // note: | ||
| // Rescheduling an already scheduled power consumption process is possible as long as the | ||
| // 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) | ||
|
|
||
| // stop (abort) the process [OHPCF-022/1]. | ||
| AbortPowerConsumptionProcess(entity spineapi.EntityRemoteInterface, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) | ||
|
|
||
| // pause the process [OHPCF-022/2]. | ||
| PausePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) | ||
|
|
||
| // resume the process [OHPCF-022/3]. | ||
| ResumePowerConsumptionProcess(entity spineapi.EntityRemoteInterface, resultCB func(result model.ResultDataType)) (*model.MsgCounterType, error) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package ohpcf | ||
|
|
||
| import ( | ||
| "github.com/enbility/eebus-go/features/client" | ||
| "github.com/enbility/eebus-go/usecases/internal" | ||
| "github.com/enbility/ship-go/logging" | ||
| spineapi "github.com/enbility/spine-go/api" | ||
| "github.com/enbility/spine-go/model" | ||
| ) | ||
|
|
||
| // handle SPINE events | ||
| func (o *OHPCF) HandleEvent(payload spineapi.EventPayload) { | ||
| // only about events from an EV entity or device changes for this remote device | ||
|
|
||
| if !o.IsCompatibleEntityType(payload.Entity) { | ||
| return | ||
| } | ||
|
|
||
| if internal.IsEntityAdded(payload) { | ||
| o.connected(payload.Entity) | ||
| } | ||
|
|
||
| if payload.Data == nil { | ||
| return | ||
| } | ||
|
|
||
| switch payload.Data.(type) { | ||
| case *model.SmartEnergyManagementPsDataType: | ||
| o.loadSmartEnergyManagementPsDataType(payload) | ||
| } | ||
| } | ||
|
|
||
| func (o *OHPCF) connected(entity spineapi.EntityRemoteInterface) { | ||
| if semp, err := client.NewSmartEnergyManagementPs(o.LocalEntity, entity); err == nil { | ||
| if !semp.HasSubscription() { | ||
| if _, err := semp.Subscribe(); err != nil { | ||
| logging.Log().Debug(err) | ||
| } | ||
| } | ||
|
|
||
| if !semp.HasBinding() { | ||
| if _, err := semp.Bind(); err != nil { | ||
| logging.Log().Debug(err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (o *OHPCF) loadSmartEnergyManagementPsDataType(payload spineapi.EventPayload) { | ||
| data := payload.Data.(*model.SmartEnergyManagementPsDataType) | ||
|
|
||
| if o.EventCB == nil { | ||
| return | ||
| } | ||
|
|
||
| if len(data.Alternatives) == 1 { | ||
| alternative := data.Alternatives[0] | ||
|
|
||
| if len(alternative.PowerSequence) != 1 { | ||
| return | ||
| } | ||
|
|
||
| request := alternative.PowerSequence[0] | ||
|
|
||
| if len(request.PowerTimeSlot) == 1 && | ||
| request.PowerTimeSlot[0].ValueList != nil && | ||
| len(request.PowerTimeSlot[0].ValueList.Value) > 0 { | ||
| for _, value := range request.PowerTimeSlot[0].ValueList.Value { | ||
| if value.Value != nil && | ||
| value.ValueType != nil { | ||
| if *value.ValueType == model.PowerTimeSlotValueTypeTypePower { | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateRequestedPowerEstimate) | ||
| } else if *value.ValueType == model.PowerTimeSlotValueTypeTypePowerMax { | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateRequestedPowerMax) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if request.OperatingConstraintsInterrupt != nil { | ||
| if request.OperatingConstraintsInterrupt.IsStoppable != nil { | ||
| // [OHPCF-011/5] | ||
| // [OHPCF-012/3] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateConsumptionIsStoppable) | ||
| } | ||
|
|
||
| if request.OperatingConstraintsInterrupt.IsPausable != nil { | ||
| // [OHPCF-011/6] | ||
| // [OHPCF-012/3] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateConsumptionIsPausable) | ||
| } | ||
| } | ||
|
|
||
| if request.Schedule != nil && | ||
| request.Schedule.StartTime != nil { | ||
| // [OHPCF-012/1] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateConsumptionStartTime) | ||
| } | ||
|
|
||
| if request.State != nil && | ||
| request.State.State != nil { | ||
| // [OHPCF-006], [OHPCF-011/1], [OHPCF-012/2], [OHPCF-022] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateConsumptionState) | ||
| } | ||
|
|
||
| if request.OperatingConstraintsDuration != nil { | ||
| if request.OperatingConstraintsDuration.ActiveDurationMin != nil { | ||
| // [OHPCF-008] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateMinimalRunDuration) | ||
| } | ||
| if request.OperatingConstraintsDuration.PauseDurationMin != nil { | ||
| // [OHPCF-009] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateMinimalPauseDuration) | ||
| } | ||
| } | ||
|
|
||
| } else if len(data.Alternatives) == 0 { | ||
| // [OHPCF-003], [OHPCF-006/2] | ||
| o.EventCB(payload.Ski, payload.Device, payload.Entity, DataUpdateConsumptionState) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hard-codes
SchedulePowerConsumptionProcessto usingmodel.NewAbsoluteOrRelativeTimeTypeFromTime(start)which doesn't work on Vaillant which only accepts durations. From the AbsoluteOrRelativeTimeType — EEBus_SPINE_TS_CommonDataTypes.xsd, lines 51–53:I'd be happy to provide a PR. Options:
WithTimevsWithDuration)Which one would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems passing the start time as
*model.AbsoluteOrRelativeTimeTypeis the absolute easiest way of doing this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took another look:
Rest of the library is using duration. This is the only place where actual time seems to be used. So the idiomatic fix- without adding additional flexibility would be changing
startintostartInastime.Duration.wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should settle it: