66from uuid import UUID
77
88from bleak .backends .scanner import AdvertisementData
9- from bluetooth_numbers import company , service
10- from bluetooth_numbers .exceptions import UnknownCICError , UnknownUUIDError
9+ from bluetooth_numbers import company , oui , service
10+ from bluetooth_numbers .exceptions import (
11+ UnknownCICError ,
12+ UnknownOUIError ,
13+ UnknownUUIDError ,
14+ WrongOUIFormatError ,
15+ )
1116from rich ._palettes import EIGHT_BIT_PALETTE
1217from rich .style import Style
1318from rich .table import Table
@@ -50,7 +55,7 @@ def __rich__(self) -> Text:
5055
5156
5257class RichDeviceAddress :
53- """Rich renderable that shows a Bluetooth device address.
58+ """Rich renderable that shows a Bluetooth device address aand OUI description .
5459
5560 Every address is rendered in its own color.
5661 """
@@ -63,13 +68,28 @@ def __init__(self, address: str) -> None:
6368 """
6469 self .address = address
6570 self .style = Style (color = EIGHT_BIT_PALETTE [hash8 (self .address )].hex )
71+ try :
72+ self .oui = oui [self .address [:8 ]]
73+ except (UnknownOUIError , WrongOUIFormatError ):
74+ # This could be macOS that returns a UUID instead of Bluetooth address
75+ self .oui = ""
76+
77+ def height (self ) -> int :
78+ """Return the number of lines this Rich renderable uses."""
79+ height = 1
80+ if self .oui :
81+ height += 1
82+ return height # noqa: R504
6683
6784 def __rich__ (self ) -> Text :
6885 """Render the RichDeviceAddress object.
6986
7087 Returns:
7188 Text: The rendering of the RichDeviceAddress object.
7289 """
90+ if self .oui :
91+ return Text .assemble (Text (self .address , style = self .style ), f"\n { self .oui } " )
92+
7393 return Text (self .address , style = self .style )
7494
7595
0 commit comments