|
1 | 1 | import asyncio
|
| 2 | +from typing import List, Tuple, Optional, Union |
2 | 3 |
|
3 | 4 | from bacpypes3.app import Application
|
4 | 5 | from bacpypes3.npdu import RejectMessageToNetwork
|
|
8 | 9 |
|
9 | 10 | from ...core.utils.notes import note_and_log
|
10 | 11 |
|
| 12 | +ROUTER_TUPLE_TYPE = Union[ |
| 13 | + Tuple[Union[Address, str], Union[int, List[int]]], |
| 14 | + Tuple[Union[Address, str], Union[int, List[int]], Optional[int]], |
| 15 | +] |
| 16 | + |
11 | 17 |
|
12 | 18 | @note_and_log
|
13 | 19 | class Alias:
|
@@ -111,6 +117,36 @@ async def init_routing_table(self, address):
|
111 | 117 | _app: Application = _this_application.app
|
112 | 118 | await _app.nse.initialize_routing_table()
|
113 | 119 |
|
| 120 | + async def use_router( |
| 121 | + self, |
| 122 | + router_infos: Union[ |
| 123 | + Tuple[Union[Address, str], Union[int, List[int]]], |
| 124 | + Tuple[Union[Address, str], Union[int, List[int]], Optional[int]], |
| 125 | + ] = (None, None, None), |
| 126 | + ): |
| 127 | + address, dnets = router_infos[:2] |
| 128 | + try: |
| 129 | + snet = router_infos[2] |
| 130 | + except IndexError: |
| 131 | + snet = None |
| 132 | + _this_application: BAC0Application = self.this_application |
| 133 | + _app: Application = _this_application.app |
| 134 | + if not isinstance(address, Address): |
| 135 | + address = Address(address) |
| 136 | + if not isinstance(dnets, list): |
| 137 | + dnets = [dnets] |
| 138 | + response = await self.who_is(address=address) |
| 139 | + if response: |
| 140 | + self._log.info(f"Router found at {address}") |
| 141 | + self._log.info( |
| 142 | + f"Adding router reference -> Snet : {snet} Addr : {address} dnets : {dnets}" |
| 143 | + ) |
| 144 | + await _app.nsap.update_router_references( |
| 145 | + snet=snet, address=address, dnets=dnets |
| 146 | + ) |
| 147 | + else: |
| 148 | + self._log.warning(f"Router not found at {address}") |
| 149 | + |
114 | 150 | async def what_is_network_number(self, destination=None, timeout=3):
|
115 | 151 | """
|
116 | 152 | winn [ <addr> ]
|
|
0 commit comments