Skip to content

Commit ad6f02d

Browse files
committed
bacnet updates
1 parent d4f4762 commit ad6f02d

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

buildingmotif/ingresses/bacnet.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,45 @@ async def _collect_objects(
7979
):
8080
device_kwargs.setdefault("poll", 0)
8181

82+
logger.error(f"starting with {ip=} {ping=}")
8283
async with BAC0.start(ip=ip, ping=ping) as bacnet:
84+
await asyncio.sleep(2)
8385
await bacnet._discover(**discover_kwargs)
86+
await asyncio.sleep(2)
8487

8588
discovered = getattr(bacnet, "discoveredDevices", None)
8689
if not discovered:
8790
warnings.warn("BACnet ingress could not find any BACnet devices")
8891
return
8992

90-
for (address, device_id) in discovered:
93+
discovered_entries: List[Tuple[Any, Any, Dict[str, Any]]] = []
94+
if isinstance(discovered, dict):
95+
for info in discovered.values():
96+
address = info.get("address")
97+
obj_instance = info.get("object_instance")
98+
device_id = None
99+
if isinstance(obj_instance, tuple) and len(obj_instance) >= 2:
100+
device_id = obj_instance[1]
101+
else:
102+
device_id = info.get("device_id")
103+
104+
if address is None or device_id is None:
105+
logger.warning(
106+
"Skipping discovered device with missing address/device_id: %s",
107+
info,
108+
)
109+
continue
110+
111+
if hasattr(address, "addr"):
112+
address = address.addr
113+
address = str(address)
114+
discovered_entries.append((address, device_id, info))
115+
116+
if not discovered_entries:
117+
warnings.warn("BACnet ingress could not find any BACnet devices")
118+
return
119+
120+
for (address, device_id, _) in discovered_entries:
91121
device = await BAC0.device(address, device_id, bacnet, **device_kwargs)
92122
objects: List[Dict[str, Any]] = []
93123

tests/integration/fixtures/bacnet/BACpypes.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[BACpypes]
22
objectName: VirtualBACnet
3-
#address: 172.17.0.1/24
3+
#address: 172.17.0.30/32
44
objectIdentifier: 599
55
maxApduLengthAccepted: 1024
66
segmentationSupported: segmentedBoth

tests/integration/fixtures/bacnet/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ services:
55
dockerfile: Dockerfile
66
networks:
77
bacnet:
8-
ipv4_address: 172.24.0.3
8+
ipv4_address: 172.24.0.30
99
command: "python3 virtual_bacnet.py"
1010
buildingmotif:
1111
build:
1212
context: ../../../../
1313
dockerfile: tests/integration/fixtures/buildingmotif/Dockerfile
1414
networks:
1515
bacnet:
16-
ipv4_address: 172.24.0.2
16+
ipv4_address: 172.24.0.20
1717
networks:
1818
bacnet:
1919
ipam:

tests/integration/test_bacnet_ingress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_bacnet_ingress(bm):
1414
BLDG = Namespace("urn:building/")
1515
m = Model.create(BLDG, "test building for bacnet scan")
16-
bacnet = BACnetNetwork("172.24.0.2/24")
16+
bacnet = BACnetNetwork("172.24.0.20/16")
1717
tobrick = BACnetToBrickIngress(bm, bacnet)
1818
m.add_graph(tobrick.graph(BLDG))
1919

@@ -35,7 +35,7 @@ def test_bacnet_scan_cli(bm, tmp_path):
3535
d.mkdir()
3636
output_file = d / "output.json"
3737
subprocess.run(
38-
shlex.split(f'buildingmotif scan -o "{str(output_file)}" -ip 172.24.0.2/24')
38+
shlex.split(f'buildingmotif scan -o "{str(output_file)}" -ip 172.24.0.20/16')
3939
)
4040
assert output_file.exists()
4141
bacnet = BACnetNetwork.load(output_file)

0 commit comments

Comments
 (0)