thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
219 stars 54 forks source link

Simplify c8y_api::smartrest::topic module avoiding all redundant code to create topics #2316

Open albinsuresh opened 11 months ago

albinsuresh commented 11 months ago

Is your refactoring request related to a problem? Please describe.

The c8y_api::smartrest::topic has various mechanisms to generate SmartREST topics for the main device, immediate child device, nested child devices and services. The recently introduced publish_topic_from_ancestors API already covers most of these cases and the rest are just redundant, especially the ones like C8yTopic::ChildSmartRestResponse, dedicated for immediate child devices only.

Describe the solution you'd like

Refactor the c8y_api::smartrest::topic module with a smaller set of helper functions to create topics for all kinds of targets: the main device, immediate child device, nested child devices and services.

Bravo555 commented 1 month ago

There also seems to be an important difference in behaviour between publish_topic_from_ancestors and C8yTopic::to_topic for ChildSmartRestResponse(String) variant:

C8yTopic::to_topic is used by the availability actor, so is it possible it may not work correctly for nested child devices?

EDIT: There seem to be some checks specifically for nested child devices (58b1ebb), in which case perhaps there's no problems but it's still a bit confusing why using a "wrong" smartrest publish topic is fine.