Skip to content

Conversation

silverailscolo
Copy link
Contributor

@silverailscolo silverailscolo commented Sep 24, 2025

Fresh PR on master, replaces #4

For dynamic model support:

  • Refactor existing models, init, node
  • In BRDG add 3 methods te get models() info fields to bridge_data
  • Add VMD-base, vmd_07rps13 (Ventura)
  • Remove const ProductId enum, replaced by per model product_id()

Add const OffOnMode, U8Register, used in Ventura

For CLI to work:

  • move model print_status() to model files, VMD-base
  • parse entered values from str to int (example: "do_set_co2 800")

Left out the Access Flag to IntEnum change

@silverailscolo silverailscolo mentioned this pull request Sep 24, 2025
12 tasks
Copy link
Owner

@scabrero scabrero left a 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.

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:
Copy link
Owner

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

Copy link
Contributor Author

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)...

Copy link
Contributor Author

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?

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():
Copy link
Owner

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.

Copy link
Contributor Author

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


class VMN05LM02(AiriosDevice):
"""Represents a VMN-05LM02 remote node."""
class NodeData(AiriosDeviceData):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class NodeData(AiriosDeviceData):
class VMN05LM02Data(AiriosDeviceData):

The name NodeData kind of break the hierarchy:

Node --> Device --> VMN05LM02

Copy link
Contributor Author

@silverailscolo silverailscolo Oct 1, 2025

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):
Copy link
Owner

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()

Copy link
Contributor Author

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep VMN05LM02Dta.

Copy link
Contributor Author

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?

silverailscolo and others added 7 commits September 30, 2025 22:08
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>
@silverailscolo
Copy link
Contributor Author

Fixed call of supported models in __init__ for HA integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants