Skip to content

Commit

Permalink
coovers empty list of discovered devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Sep 10, 2024
1 parent 62e0175 commit 58f3d52
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions BAC0/scripts/Lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,56 +367,60 @@ async def _devices(
For that, some requests will be sent over the network to look for name,
manufacturer, etc and in big network, this could be a long process.
"""

lst = []
for k, v in self.discoveredDevices.items():
objid, device_address, network_number, vendor_id, vendor_name = (
v["object_instance"],
v["address"],
v["network_number"],
v["vendor_id"],
v["vendor_name"],
)
devId = objid[1]
try:
deviceName, vendorName = await self.readMultiple(
f"{device_address} device {devId} objectName vendorName"
)
except (UnrecognizedService, ValueError):
self._log.warning(
f"Unrecognized service for {devId} | {device_address}"
if self.discoveredDevices is not None:
for k, v in self.discoveredDevices.items():
objid, device_address, network_number, vendor_id, vendor_name = (
v["object_instance"],
v["address"],
v["network_number"],
v["vendor_id"],
v["vendor_name"],
)
devId = objid[1]
try:
deviceName = await self.read(
f"{device_address} device {devId} objectName"
deviceName, vendorName = await self.readMultiple(
f"{device_address} device {devId} objectName vendorName"
)
vendorName = await self.read(
f"{device_address} device {devId} vendorName"
except (UnrecognizedService, ValueError):
self._log.warning(
f"Unrecognized service for {devId} | {device_address}"
)
except NoResponseFromController:
try:
deviceName = await self.read(
f"{device_address} device {devId} objectName"
)
vendorName = await self.read(
f"{device_address} device {devId} vendorName"
)
except NoResponseFromController:
self.log(f"No response from {k}", level="warning")
continue
except (NoResponseFromController, Timeout):
self.log(f"No response from {k}", level="warning")
continue
except (NoResponseFromController, Timeout):
self.log(f"No response from {k}", level="warning")
continue
lst.append((deviceName, vendorName, devId, device_address, network_number))
if RICH:
console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Network_number")
table.add_column("Device Name")
table.add_column("Address")
table.add_column("Device Instance")
table.add_column("Vendor Name")
for each in lst:
deviceName, vendorName, devId, device_address, network_number = each
table.add_row(
f"{network_number}",
f"{deviceName}",
f"{device_address}",
f"{devId}",
f"{vendorName}",
lst.append(
(deviceName, vendorName, devId, device_address, network_number)
)
console.print(table)
if RICH:
console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Network_number")
table.add_column("Device Name")
table.add_column("Address")
table.add_column("Device Instance")
table.add_column("Vendor Name")
for each in lst:
deviceName, vendorName, devId, device_address, network_number = each
table.add_row(
f"{network_number}",
f"{deviceName}",
f"{device_address}",
f"{devId}",
f"{vendorName}",
)
console.print(table)
if _return_list:
return lst # type: ignore[return-value]

Expand Down

0 comments on commit 58f3d52

Please sign in to comment.