You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enforce overwriting of parent methods, dynamic creation of API nodes #141
Component level methods should define, in an abstract way, everything exposed by inheriting child.
The child, in some cases, might only be capable of some methods, and not all as @cynthiabour pointed out for sensor.
It would be best to only expose the methods it is capable off.
My suggestion would be (without changing the current Inheritance):
This allows for required and optional child methods
Then, a dedicated function could inspect the parent and child for it's methods
def get_routes(instance):
ownclass = instance.__class__.__name__
parent_class = instance.__base__.name__
#parent class needs some looping probably, to get the actual parent
methods_in_common = list(set(get_methods(ownclass)) & set(get_methods(parent_class)))
for method in methods_in_common:
# this needs some expansion to allow for PUT GET etc definition
add_api_route(method)
def get_methods(instance)
...
return methods
The parent methods would be the possible methods, narrowed down by the actual methods (the ones overwritten by the child)
This would avoid having to explicitly define api_routes, since those could be created based on need and capability.
Also it would enforce certain devices top expose certain methods
It would also limit the creation of routes to one layer
Most importantly, it would allow to deduce actually available methods directly from the webserver
To accomplish this idea, the following steps are necessary:
All methods accessible in the API must be included in the component_class (where the methods are overridden). For example:
classDevice(FlowchemDevice):
...
definitialized(self):
...
self.components.append(DeviceComponent("component", self))
classDeviceComponent(FlowchemComponent): ## All methods accessible in the API must be here!def__init__(self):
print("Sensor.__init__()")
self.insertAPI(Sensor, self)
The difference between PUT and GET methods must be made clearer.
If @JB-Wolf and @cynthiabour agree, I can modify these details and implement this auto API route.
In addition, we may need to consider whether all the functionality at component level should be made available to the user. Otherwise, the current approach is not ideal.
we can specify that by public and private functions.
It is not really necessary, but
a) makes maintenances much easier
b) provides better code structure and separation
How it works:
Find all common methods between an interface class (the abstract class) and all child classes (the implementations).
Decide for GET/PUT route depending on the number of arguments in the signature of the method.
I create a branch to solve this:
This works perfectly 👯 . I want to schedule a meeting with the team to see if merging is viable!
If you see the advantage of this new feature, adding one line of code in every component in flowchem will be necessary!
The discussion about the difference between GET and PUT remains. If it is to be implemented, the names of some methods in the API server will be the same as those in the class.
Yes
It's the reason I want to discuss with you all.
1-It is necessary to have a straightforward way to differentiate between PUTS and GETS. If the number of arguments is reasonable. (Comment on the point 2)
2-What this function does is basically mirror what is in the class in the API, which means that the name of the API routes will be exactly the same as the class. In this sense, if we have this issue:
'put flowrate' and 'get flowrate', the API address will mirror the same methods endpoint name, which is in the component class get_flowrate or put_flowrate...
3-This is done by inspecting the overwrite methods and the option if the user wants to expose the parent methods too. 👯
Activity
JB-Wolf commentedon Jul 24, 2024
@mehlert suggests this:
samuelvitorsaraiva commentedon Aug 1, 2024
To accomplish this idea, the following steps are necessary:
component_class(where the methods are overridden). For example:If @JB-Wolf and @cynthiabour agree, I can modify these details and implement this auto API route.
cynthiabour commentedon Aug 1, 2024
sorry I don't get how it works. and why this is necessary.
cynthiabour commentedon Aug 1, 2024
In addition, we may need to consider whether all the functionality at component level should be made available to the user. Otherwise, the current approach is not ideal.
JB-Wolf commentedon Aug 1, 2024
we can specify that by public and private functions.
It is not really necessary, but
a) makes maintenances much easier
b) provides better code structure and separation
mehlert commentedon Aug 1, 2024
How it works:
Find all common methods between an interface class (the abstract class) and all child classes (the implementations).
Decide for GET/PUT route depending on the number of arguments in the signature of the method.
samuelvitorsaraiva commentedon Aug 27, 2024
I create a branch to solve this:
This works perfectly 👯 . I want to schedule a meeting with the team to see if merging is viable!
If you see the advantage of this new feature, adding one line of code in every component in flowchem will be necessary!
The discussion about the difference between GET and PUT remains. If it is to be implemented, the names of some methods in the API server will be the same as those in the class.
cynthiabour commentedon Sep 11, 2024
I have found that some parts of the current code are missing.
@samuelvitorsaraiva Please read through the code and find out if it is possible to fix all the above issues.
samuelvitorsaraiva commentedon Sep 11, 2024
Yes
It's the reason I want to discuss with you all.
1-It is necessary to have a straightforward way to differentiate between PUTS and GETS. If the number of arguments is reasonable. (Comment on the point 2)
2-What this function does is basically mirror what is in the class in the API, which means that the name of the API routes will be exactly the same as the class. In this sense, if we have this issue:
'put flowrate' and 'get flowrate', the API address will mirror the same methods endpoint name, which is in the component class get_flowrate or put_flowrate...
3-This is done by inspecting the overwrite methods and the option if the user wants to expose the parent methods too. 👯