1717"""
1818
1919from enum import IntEnum
20+ from struct import unpack
21+ from typing import Literal , Tuple
2022
2123import semver
2224
@@ -34,7 +36,7 @@ def _pybricks_uuid(short: int) -> str:
3436.. availability:: Since Pybricks protocol v1.0.0.
3537"""
3638
37- PYBRICKS_PROTOCOL_VERSION = semver .VersionInfo (1 )
39+ PYBRICKS_PROTOCOL_VERSION = semver .VersionInfo (1 , 1 , 0 )
3840"""The minimum required Pybricks protocol version supported by this library."""
3941
4042# The Pybricks protocol is defined at:
@@ -118,6 +120,12 @@ class Status(IntEnum):
118120 .. availability:: Since Pybricks protocol v1.0.0.
119121 """
120122
123+ SHUTDOWN = 7
124+ """Hub shutdown was requested.
125+
126+ .. availability:: Since Pybricks protocol v1.1.0.
127+ """
128+
121129 @property
122130 def flag (self ) -> int :
123131 """Gets the value of the enum as a bit flag."""
@@ -162,3 +170,29 @@ def _standard_uuid(short: int) -> str:
162170
163171.. availability:: Since Pybricks protocol v1.0.0.
164172"""
173+
174+ PNP_ID_UUID = _standard_uuid (0x2A50 )
175+ """Standard PnP ID UUID
176+
177+ Vendor ID is :data:`pybricks.ble.lwp3.LEGO_CID`. Product ID is one of
178+ :class:`pybricks.ble.lwp3.bytecodes.HubKind`. Revision is ``0`` for most
179+ hubs or ``1`` for MINDSTORMS Robot Inventor Hub.
180+
181+ .. availability:: Since Pybricks protocol v1.1.0.
182+ """
183+
184+
185+ def unpack_pnp_id (data : bytes ) -> Tuple [Literal ["BT" , "USB" ], int , int , int ]:
186+ """
187+ Unpacks raw data from the PnP ID characteristic.
188+
189+ Args:
190+ data: The raw data
191+
192+ Returns:
193+ Tuple containing the vendor ID type (``'BT'`` or ``'USB'``), the vendor
194+ ID, the product ID and the product revision.
195+ """
196+ vid_type , vid , pid , rev = unpack ("<BHHH" , data )
197+ vid_type = "BT" if vid_type else "USB"
198+ return vid_type , vid , pid , rev
0 commit comments