|
16 | 16 | version can be used to determine the capabilities of the device. |
17 | 17 | """ |
18 | 18 |
|
19 | | -from enum import IntEnum |
| 19 | +from enum import IntEnum, IntFlag |
20 | 20 | from struct import unpack |
21 | 21 | from typing import Literal, Tuple |
22 | 22 |
|
@@ -72,65 +72,57 @@ class Event(IntEnum): |
72 | 72 | """ |
73 | 73 |
|
74 | 74 |
|
75 | | -class Status(IntEnum): |
76 | | - """Hub status indicators. |
| 75 | +class StatusFlag(IntFlag): |
| 76 | + """Hub status indicators.""" |
77 | 77 |
|
78 | | - Use the :attr:`flag` property to get the value as a bit flag. |
79 | | - """ |
80 | | - |
81 | | - BATTERY_LOW_VOLTAGE_WARNING = 0 |
| 78 | + BATTERY_LOW_VOLTAGE_WARNING = 1 << 0 |
82 | 79 | """Battery voltage is low. |
83 | 80 |
|
84 | 81 | .. availability:: Since Pybricks protocol v1.0.0. |
85 | 82 | """ |
86 | 83 |
|
87 | | - BATTERY_LOW_VOLTAGE_SHUTDOWN = 1 |
| 84 | + BATTERY_LOW_VOLTAGE_SHUTDOWN = 1 << 1 |
88 | 85 | """Battery voltage is critically low. |
89 | 86 |
|
90 | 87 | .. availability:: Since Pybricks protocol v1.0.0. |
91 | 88 | """ |
92 | 89 |
|
93 | | - BATTERY_HIGH_CURRENT = 2 |
| 90 | + BATTERY_HIGH_CURRENT = 1 << 2 |
94 | 91 | """Battery current is too high. |
95 | 92 |
|
96 | 93 | .. availability:: Since Pybricks protocol v1.0.0. |
97 | 94 | """ |
98 | 95 |
|
99 | | - BLE_ADVERTISING = 3 |
| 96 | + BLE_ADVERTISING = 1 << 3 |
100 | 97 | """Bluetooth Low Energy is advertising/discoverable. |
101 | 98 |
|
102 | 99 | .. availability:: Since Pybricks protocol v1.0.0. |
103 | 100 | """ |
104 | 101 |
|
105 | | - BLE_LOW_SIGNAL = 4 |
| 102 | + BLE_LOW_SIGNAL = 1 << 4 |
106 | 103 | """Bluetooth Low Energy has low signal. |
107 | 104 |
|
108 | 105 | .. availability:: Since Pybricks protocol v1.0.0. |
109 | 106 | """ |
110 | 107 |
|
111 | | - POWER_BUTTON_PRESSED = 5 |
| 108 | + POWER_BUTTON_PRESSED = 1 << 5 |
112 | 109 | """Power button is currently pressed. |
113 | 110 |
|
114 | 111 | .. availability:: Since Pybricks protocol v1.0.0. |
115 | 112 | """ |
116 | 113 |
|
117 | | - USER_PROGRAM_RUNNING = 6 |
| 114 | + USER_PROGRAM_RUNNING = 1 << 6 |
118 | 115 | """User program is currently running. |
119 | 116 |
|
120 | 117 | .. availability:: Since Pybricks protocol v1.0.0. |
121 | 118 | """ |
122 | 119 |
|
123 | | - SHUTDOWN = 7 |
| 120 | + SHUTDOWN = 1 << 7 |
124 | 121 | """Hub shutdown was requested. |
125 | 122 |
|
126 | 123 | .. availability:: Since Pybricks protocol v1.1.0. |
127 | 124 | """ |
128 | 125 |
|
129 | | - @property |
130 | | - def flag(self) -> int: |
131 | | - """Gets the value of the enum as a bit flag.""" |
132 | | - return 1 << self.value |
133 | | - |
134 | 126 |
|
135 | 127 | # The Pybricks Protocol version also implies certain other services and |
136 | 128 | # and characteristics are present. |
|
0 commit comments