diff --git a/BAC0/core/functions/Alias.py b/BAC0/core/functions/Alias.py index 6cb050dc..81bc3e31 100644 --- a/BAC0/core/functions/Alias.py +++ b/BAC0/core/functions/Alias.py @@ -1,4 +1,5 @@ import asyncio +from typing import List, Tuple, Optional, Union from bacpypes3.app import Application from bacpypes3.npdu import RejectMessageToNetwork @@ -8,6 +9,11 @@ from ...core.utils.notes import note_and_log +ROUTER_TUPLE_TYPE = Union[ + Tuple[Union[Address, str], Union[int, List[int]]], + Tuple[Union[Address, str], Union[int, List[int]], Optional[int]], +] + @note_and_log class Alias: @@ -111,6 +117,36 @@ async def init_routing_table(self, address): _app: Application = _this_application.app await _app.nse.initialize_routing_table() + async def use_router( + self, + router_infos: Union[ + Tuple[Union[Address, str], Union[int, List[int]]], + Tuple[Union[Address, str], Union[int, List[int]], Optional[int]], + ] = (None, None, None), + ): + address, dnets = router_infos[:2] + try: + snet = router_infos[2] + except IndexError: + snet = None + _this_application: BAC0Application = self.this_application + _app: Application = _this_application.app + if not isinstance(address, Address): + address = Address(address) + if not isinstance(dnets, list): + dnets = [dnets] + response = await self.who_is(address=address) + if response: + self._log.info(f"Router found at {address}") + self._log.info( + f"Adding router reference -> Snet : {snet} Addr : {address} dnets : {dnets}" + ) + await _app.nsap.update_router_references( + snet=snet, address=address, dnets=dnets + ) + else: + self._log.warning(f"Router not found at {address}") + async def what_is_network_number(self, destination=None, timeout=3): """ winn [ ] diff --git a/BAC0/infos.py b/BAC0/infos.py index cd9fe0f7..df0fe274 100644 --- a/BAC0/infos.py +++ b/BAC0/infos.py @@ -12,5 +12,5 @@ __email__ = "christian.tremblay@servisys.com" __url__ = "https://github.com/ChristianTremblay/BAC0" __download_url__ = "https://github.com/ChristianTremblay/BAC0/archive/master.zip" -__version__ = "2024.09.08" +__version__ = "2024.09.10" __license__ = "LGPLv3" diff --git a/BAC0/scripts/Base.py b/BAC0/scripts/Base.py index 2ae1fc63..29efcef2 100644 --- a/BAC0/scripts/Base.py +++ b/BAC0/scripts/Base.py @@ -78,7 +78,7 @@ class Base: def __init__( self, - localIPAddr: str = "127.0.0.1", + localIPAddr: Address = Address("127.0.0.1/24"), networkNumber: int = None, localObjName: str = "BAC0", deviceId: int = None, diff --git a/pyproject.toml b/pyproject.toml index 209d7490..caeeecbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "BAC0" -version = "2024.09.13dev" +version = "2024.09.15dev" description = "BACnet Scripting Framework for testing DDC Controls" authors = [{name = "Christian Tremblay", email = "christian.tremblay@servisys.com"}] readme = "README.md"