-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor Ventura #12
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
base: main
Are you sure you want to change the base?
Refactor Ventura #12
Conversation
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.
Awesome work! I really like the dynamic loading of supported models and the idea of passing this info to the home-assistant integration.
src/pyairios/models/brdg_02r13.py
Outdated
return f"BRDG-02R13@{self.slave_id}" | ||
# node method doesn't work for Bridge module in CLI (contains the path too) | ||
|
||
async def load_models(self) -> int: |
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 is a "library" functionality not related bridge device. There are other bridge models like BRDG-02EM23 which is Ethernet instead of RS485. I would move supported models loading to class Airios
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.
From general structure I can follow that, but in particular the CLI has no way to access the Airios class. So collecting this info would cause quite a lot of code duplication.
When a second bridge model will be added, it seems better to add the models loading to a "bridge-base" module that all bridges are based on.
I did change the HA components access to the model info by calling the Airios api directly and added methods to get this info (from the bridge, for now).
If you can suggest a way to get the supported models to the CLI I will use that (the info is still in BridgeData and that should not be necessary)...
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.
Added bridge_base.py
, and by doing so the CLI can access the models info for print status report (only).
This is mainly a service to the user, as the CLI bind is done by entering the product_id by hand (it doesn't need the models info for that, but I was looking in a lot of places to collect that number, convert it to dec etc. Hence the printout. Common bridge info is also in the bridge_base, as is the whole glob.glob to collect models from disk). Looks better, isn't it?
src/pyairios/__init__.py
Outdated
prids = brdg_data["product_ids"] | ||
if prids is not None and brdg_data["models"] is not None: | ||
for _node in await self.bridge.nodes(): | ||
for key, _id in prids.items(): |
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 needs to be reversed. Instead of iterating the supported models first, iterate the bound nodes and then check if it is supported or not (iterating prids
). The reason is that you can have several physical machines bound, all of them with the same product id but with its own virtual modbus device on the bridge.
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.
If reversed, it means awaiting every loop. As is, we await just once, and fetch a matching model (might be the same as in previous loop): same result
src/pyairios/models/vmn_05lm02.py
Outdated
|
||
class VMN05LM02(AiriosDevice): | ||
"""Represents a VMN-05LM02 remote node.""" | ||
class NodeData(AiriosDeviceData): |
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.
class NodeData(AiriosDeviceData): | |
class VMN05LM02Data(AiriosDeviceData): |
The name NodeData kind of break the hierarchy:
Node --> Device --> VMN05LM02
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.
Changed it to DeviceData
to align.
This class is really just data for the Module called VMN_05LM02. Having to write (almost) the same string twice invites for hard to spot errors once we get 10+ models, was my reasoning.
return "Siber 4 button Remote" | ||
|
||
|
||
class Node(AiriosDevice): |
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 don't like having the same class name in different files. I guess it is to have a common entry point to instantiate without knowing the final class name.
I think we need to implement a factory pattern, E.g. https://medium.com/@amirm.lavasani/design-patterns-in-python-factory-method-1882d9a06cb4
Each supported model file could have a static variable "factory":
factory = VMN05LM02Factory()
And then in do_node()
do node_module = brdg_data["models"][key].factory.create_node()
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.
Good idea with implementation, thanks. Haven't built the (abstract_)factory
yet.
result = await self.client.get_register(regdesc, self.slave_id) | ||
return Result(VMDRequestedVentilationSpeed(result.value), result.status) | ||
|
||
async def fetch_vmn_data(self) -> VMN05LM02Data: # pylint: disable=duplicate-code |
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 would keep VMN05LM02Dta.
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.
See above. Even naming fetch_vmn_data()
vs fetch_vmd_data()
might become an unnecessary source of confusion/errors in the long run. Wouldn't fetch_device_data()
do the trick?
Pair-Programmed-With: Egbert Broerse <dcc2@ebroerse.nl> Signed-off-by: Samuel Cabrero <scabrero@orica.es>
Pair-Programmed-With: Egbert Broerse <dcc2@ebroerse.nl> Signed-off-by: Samuel Cabrero <scabrero@orica.es>
Pair-Programmed-With: Egbert Broerse <dcc2@ebroerse.nl> Signed-off-by: Samuel Cabrero <scabrero@orica.es>
Fixed call of supported models in |
Fresh PR on master, replaces #4
For dynamic model support:
fields to bridge_dataAdd const OffOnMode, U8Register, used in Ventura
For CLI to work:
Left out the Access Flag to IntEnum change