-
Notifications
You must be signed in to change notification settings - Fork 55
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
refactor: Simplify SmartREST publish topics #3292
base: main
Are you sure you want to change the base?
refactor: Simplify SmartREST publish topics #3292
Conversation
64e559d
to
aa48c0c
Compare
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
Robot Results
|
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.
Approved - with 2 suggestions.
// Skipping the last ancestor as it is the main device represented by the root topic itself | ||
target_topic.push('/'); | ||
target_topic.push_str(ancestor.as_ref()); | ||
pub fn publish_topic_from_parent(parent: Option<&str>, prefix: &TopicPrefix) -> Topic { |
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.
A doc comment would be helpful, at least some examples.
pub fn publish_topic_from_parent(parent: Option<&str>, prefix: &TopicPrefix) -> Topic { | |
/// (None, prefix) -> ??? | |
/// (Some(parent), prefix) -> ??? | |
pub fn publish_topic_from_parent(parent: Option<&str>, prefix: &TopicPrefix) -> Topic { |
Ok(topic) | ||
} | ||
|
||
pub fn parent_xid_if_not_main_device( |
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.
A function name doesn't have to tell the whole story. The signature is enough to understand that this will return None for a device with no parent.
pub fn parent_xid_if_not_main_device( | |
pub fn parent_xid( |
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.
Oh yeah, I was kinda expecting some comment on this API, as I really struggled to name it properly. By bad, for not adding the rustdocs for it and hoping that a longer/detailed name would convey it properly.
So, I didn't name it just parent_xid
because what's returned is not quite the parent_xid
in all cases. For any child devices at level 2 and beyond, this function returns Some(<parent-xid>)
as expected. But for the immediate child devices of the main device, where the parent xid is the device id of the main device, this function must return None
instead of returning Some(<main-device-id>)
. We're returning None
in that case, because all the existing SmartREST APIs like child_device_creation_message
, service_creation_message_payload
etc expects None
when the message must be published to s/us
directly and Some(<parent-xid>)
when the message must be published to s/us/<parent-xid>
. That's the reason why this function impl has this additional filtering step: filter(|tid| *tid != &self.device_topic_id)
to switch it to None
when the parent is the main device.
The alternatives were the following:
- Implement a simple
parent_xid
function as suggested and call the additional filtering at the places where the SmartREST APIs are used. - Update those SmartREST APIs to take the main device xid as an additional parameter and do the filtering there
I implemented it this way it is now, to just have all that logic at one place and reuse it everywhere. But, if that API looks weird, then I can implement one of the above approaches.
PS: Writing so much to explain the API contract, I kinda feel that it was the wrong choice. Option. 2 above may have been a better choice.
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.
I got it.
Option 2 sounds the correct choice (because moving away the c8y details under c8y_api).
However, it would be better to first stabilize the main PR and add such improvements only in a second step.
For now, simply add this note as a doc comment.
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.
Resolved by 21c694f
While publishing to a nested child device, publish directly to the SmartREST topic of that device (`c8y/s/us/<xid>`), without specifying all of all its ancestors.
21c694f
to
3c37347
Compare
Proposed changes
While publishing to a nested child device, publish directly to the SmartREST topic
of that device (
c8y/s/us/<xid>
), without specifying all of all its ancestors.Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments