Add write approval callbacks for Failsafe values of CS-LPC usecase#150
Add write approval callbacks for Failsafe values of CS-LPC usecase#150sthelen-enqs wants to merge 11 commits intodevfrom
Conversation
|
Thanks for starting the work on this. I do now think that the write approval callback API should be used for all writes on any server feature. |
cdd7418 to
7be66c0
Compare
|
I was waiting for some final qualification tests to ensure that a "spec-compliant" implementation can be achieved for LPC/LPP with this PR. The final test is still outstanding due to delays with the qualification, but I'm reasonably confident that no further changes are necessary to this PR to fully pass the qualification. |
7be66c0 to
dc13778
Compare
|
@sthelen-enqs I analyzed the PR with Claude and iterated a bit over it. Here is its summary: Based on my analysis, the PR implementation is well-designed and follows the established patterns correctly. Here are my recommendations:
In deviceConfigurationWriteCB, fix the format string:
Add a comment in the interface or README explaining the approval pattern: // WriteApprovalRequired event is fired when any server feature receives a write request
For better developer experience, consider adding helper methods to check if specific configurations are pending:
Ensure tests cover:
Summary The PR implementation is functionally complete and well-designed. It correctly:
The only required change is the logging fix. The other suggestions are optional improvements for developer experience and documentation. |
c62b1bf to
07809b9
Compare
|
DerAndereAndi
left a comment
There was a problem hiding this comment.
In addition to my comments, we are missing tests for the new code.
Additionally WriteApprovalRequired message is now used for limit write approvals and failsafe and the application doesn't know which and both could also happen around the same time. In this case I would propose introduce a new message so the application can handle it more easily.
The newmethods in usecase.go and public.go are nearly identical. We could move that code into shared functions in the internal package.
usecases/cs/lpc/usecase.go
Outdated
| } | ||
|
|
||
| // Only ask for write approval if at least one of the configurations we care about is trying to be set | ||
| if _, exists := configsToApprove[*description.KeyName]; exists { |
There was a problem hiding this comment.
Doesn't this panic when KeyName is nil?
usecases/cs/lpp/usecase.go
Outdated
| } | ||
|
|
||
| // Only ask for write approval if at least one of the configurations we care about is trying to be set | ||
| if _, exists := configsToApprove[*description.KeyName]; exists { |
There was a problem hiding this comment.
Doesn't this panic when KeyName is nil?
examples/hems/main.go
Outdated
| for msgCounter, configs := range pendingDeviceConfigWrites { | ||
| fmt.Printf("Approving LPC device config write with msgCounter %d for features: ", msgCounter) | ||
| for _, config := range configs { | ||
| fmt.Printf("%s ", *config.Description.KeyName) |
There was a problem hiding this comment.
What if Description or Keyname are nil?
usecases/cs/lpp/public.go
Outdated
| return dc.UpdateKeyValueDataForFilter(data, nil, filter) | ||
| } | ||
|
|
||
| // return the currently pending incoming failsafe consumption limit writes |
There was a problem hiding this comment.
consumption -> production
usecases/cs/lpc/usecase.go
Outdated
|
|
||
| data := msg.Cmd.DeviceConfigurationKeyValueListData | ||
|
|
||
| if data == nil || data.DeviceConfigurationKeyValueData == nil || len(data.DeviceConfigurationKeyValueData) == 0 { |
There was a problem hiding this comment.
data can't be nil as it is assigned to msg.Cmd.DeviceConfigurationKeyValueListData which in line 201 is checked not to be nil. So not wrong, but will never be the case anyway
usecases/api/types.go
Outdated
| type PendingDeviceConfiguration struct { | ||
| Description *model.DeviceConfigurationKeyValueDescriptionDataType `json:"description,omitempty"` | ||
| Value *model.DeviceConfigurationKeyValueValueType `json:"value,omitempty"` | ||
| IsValueChangeable *bool `json:"isValueChangeable,omitempty" eebus:"writecheck"` |
There was a problem hiding this comment.
Why did you add the writecheck tag attribute here?
… feature. Made implementation of approval mechansim more general towards the device configuration feature.
This allows to more easily check for what a new value is trying to be set and what kind of value is being set (i.e. a duration, a bool, string etc.)
…nd LPP use into shared internal functions. Also added tests.
07809b9 to
39856fd
Compare
39856fd to
c04b7fc
Compare
This is a work-in-progress proposal for adding write approval callbacks for the failsafe values of the CS-LPC usecase.
Code changes should be functional, but are not yet final. Cleanup and thorough testing may still be required.
Fixes/updates from our side should come when I can find the time to do so. If someone wants to use/update this in the meantime, feel free.
Comments/fixes etc are welcome.