diff --git a/BAC0/core/functions/Alias.py b/BAC0/core/functions/Alias.py index 33f7c56..99b99f4 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.pdu import Address, GlobalBroadcast @@ -7,6 +8,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: @@ -110,6 +116,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/scripts/Base.py b/BAC0/scripts/Base.py index 2ae1fc6..29efcef 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,