-
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
Open
silverailscolo
wants to merge
24
commits into
scabrero:main
Choose a base branch
from
silverailscolo:eb-ventura-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor Ventura #12
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c338f29
refactor models, init, BRDG, add VMD-base, const OffOnMode, U8Register
silverailscolo 94befdb
fix registers, no shadowing, CLI entry to int
silverailscolo d50d939
refactor CLI
silverailscolo 9249c0b
Ventura RegisterAccess like existing models
silverailscolo 7f64cf8
lint line too long
silverailscolo 8f65e39
assert mod not None
silverailscolo 3b95a08
productId is int
silverailscolo d15b99a
VMDPresetFansSpeeds field default
silverailscolo a5b9c73
unnec. comprehension
silverailscolo cbc4a76
BRDG None raises Ex
silverailscolo 924811d
more BRDG None checks
silverailscolo 1568da5
even more None checks
silverailscolo dbca4f2
fix supply_temp register
silverailscolo e518c3a
Add U8Register, clamp to UINT8 range
055aa1c
Clamp register value to datatype range on writes
c77655f
Add U8Register, clamp to UINT8 range
8f85f79
apply comments
silverailscolo 1ffa5e2
add 3 util methods
silverailscolo d932856
api access to airios_models etc
silverailscolo c1328d1
create brdg_base.py, move models function there from brdg_02r13 (must…
silverailscolo a24bb94
brdg_base print to cli
silverailscolo a8a09ec
init without brdg_data[models] etc
silverailscolo f58a0cc
remove brdg_data[models] etc, fix AiriosData
silverailscolo 0701045
tweak init.fetch AiriosData type
silverailscolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| """The Airios RF bridge API entrypoint.""" | ||
|
|
||
| import logging | ||
|
|
||
| from pyairios.models.brdg_02r13 import BRDG02R13 | ||
| from pyairios.models.brdg_02r13 import DEFAULT_SLAVE_ID as BRDG02R13_DEFAULT_SLAVE_ID | ||
| from pyairios.models.vmd_02rps78 import VMD02RPS78 | ||
| from pyairios.models.vmn_05lm02 import VMN05LM02 | ||
|
|
||
| from .client import ( | ||
| AiriosBaseTransport, | ||
|
|
@@ -13,11 +13,13 @@ | |
| AsyncAiriosModbusRtuClient, | ||
| AsyncAiriosModbusTcpClient, | ||
| ) | ||
| from .constants import BindingStatus, ProductId | ||
| from .constants import BindingStatus | ||
| from .data_model import AiriosBoundNodeInfo, AiriosData, AiriosNodeData | ||
| from .exceptions import AiriosException | ||
| from .node import AiriosNode | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Airios: | ||
| """The Airios RF bridge API.""" | ||
|
|
@@ -54,7 +56,7 @@ async def bind_status(self) -> BindingStatus: | |
| async def bind_controller( | ||
| self, | ||
| slave_id: int, | ||
| product_id: ProductId, | ||
| product_id: int, | ||
| product_serial: int | None = None, | ||
| ) -> bool: | ||
| """Bind a new controller to the bridge.""" | ||
|
|
@@ -64,7 +66,7 @@ async def bind_accessory( | |
| self, | ||
| controller_slave_id: int, | ||
| slave_id: int, | ||
| product_id: ProductId, | ||
| product_id: int, | ||
| ) -> bool: | ||
| """Bind a new accessory to the bridge.""" | ||
| return await self.bridge.bind_accessory(controller_slave_id, slave_id, product_id) | ||
|
|
@@ -77,21 +79,23 @@ async def fetch(self) -> AiriosData: | |
| """Get the data from all nodes at once.""" | ||
| data: dict[int, AiriosNodeData] = {} | ||
|
|
||
| brdg_data = await self.bridge.fetch_bridge() | ||
| if brdg_data["rf_address"] is None: | ||
| brdg_data = await self.bridge.fetch_bridge_data() | ||
| if brdg_data is None or brdg_data["rf_address"] is None: | ||
| raise AiriosException("Failed to fetch node RF address") | ||
| bridge_rf_address = brdg_data["rf_address"].value | ||
| data[self.bridge.slave_id] = brdg_data | ||
|
|
||
| for node in await self.bridge.nodes(): | ||
| if node.product_id == ProductId.VMD_02RPS78: | ||
| vmd = VMD02RPS78(node.slave_id, self.bridge.client) | ||
| vmd_data = await vmd.fetch_vmd_data() | ||
| data[node.slave_id] = vmd_data | ||
| if node.product_id == ProductId.VMN_05LM02: | ||
| vmn = VMN05LM02(node.slave_id, self.bridge.client) | ||
| vmn_data = await vmn.fetch_vmn_data() | ||
| data[node.slave_id] = vmn_data | ||
| 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(): | ||
| if _id == _node.product_id and brdg_data["models"][key] is not None: | ||
| LOGGER.debug("fetch_node_data for key: %s", key) | ||
| node_module = brdg_data["models"][key].Node( | ||
| _node.slave_id, self.bridge.client | ||
| ) | ||
| node_data = await node_module.fetch_node_data() | ||
| data[_node.slave_id] = node_data | ||
|
||
|
|
||
| return AiriosData(bridge_rf_address=bridge_rf_address, nodes=data) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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