|
23 | 23 | TARGET_RESISTANCE, |
24 | 24 | TARGET_SPEED, |
25 | 25 | ) |
| 26 | +from ..errors import CharacteristicNotFound |
26 | 27 | from .machine_type import MachineType |
27 | 28 |
|
28 | 29 | _LOGGER = logging.getLogger(__name__) |
@@ -139,45 +140,62 @@ class SettingRange(NamedTuple): |
139 | 140 |
|
140 | 141 |
|
141 | 142 | async def read_features( |
142 | | - cli: BleakClient, mt: MachineType |
| 143 | + cli: BleakClient, |
| 144 | + mt: MachineType, |
143 | 145 | ) -> tuple[MachineFeatures, MachineSettings]: |
144 | 146 | _LOGGER.debug("Reading features and settings...") |
145 | 147 |
|
146 | | - try: |
147 | | - data = await cli.read_gatt_char(FEATURE_UUID) |
148 | | - |
149 | | - assert len(data) == 8 |
| 148 | + if (c := cli.services.get_characteristic(FEATURE_UUID)) is None: |
| 149 | + raise CharacteristicNotFound("Machine Feature") |
150 | 150 |
|
151 | | - bio, u4 = io.BytesIO(data), NumSerializer("u4") |
| 151 | + assert len(data := await cli.read_gatt_char(c)) == 8 |
152 | 152 |
|
153 | | - features = MachineFeatures(u4.deserialize(bio)) |
154 | | - settings = MachineSettings(u4.deserialize(bio)) |
| 153 | + bio, u4 = io.BytesIO(data), NumSerializer("u4") |
155 | 154 |
|
156 | | - except Exception: |
157 | | - _LOGGER.exception("Failed reading machine features and settings.") |
158 | | - raise |
| 155 | + features = MachineFeatures(u4.deserialize(bio)) |
| 156 | + settings = MachineSettings(u4.deserialize(bio)) |
159 | 157 |
|
160 | 158 | # Remove settings without ranges UUIDs |
161 | 159 |
|
162 | 160 | if MachineSettings.SPEED in settings: |
163 | 161 | if cli.services.get_characteristic(SPEED_RANGE_UUID) is None: |
164 | 162 | settings &= ~MachineSettings.SPEED |
| 163 | + _LOGGER.debug( |
| 164 | + "Speed setting has been removed. " |
| 165 | + "Characteristic with a range of acceptable values not found." |
| 166 | + ) |
165 | 167 |
|
166 | 168 | if MachineSettings.INCLINE in settings: |
167 | 169 | if cli.services.get_characteristic(INCLINATION_RANGE_UUID) is None: |
168 | 170 | settings &= ~MachineSettings.INCLINE |
| 171 | + _LOGGER.debug( |
| 172 | + "Inclination setting has been removed. " |
| 173 | + "Characteristic with a range of acceptable values not found." |
| 174 | + ) |
169 | 175 |
|
170 | 176 | if MachineSettings.RESISTANCE in settings: |
171 | 177 | if cli.services.get_characteristic(RESISTANCE_LEVEL_RANGE_UUID) is None: |
172 | 178 | settings &= ~MachineSettings.RESISTANCE |
| 179 | + _LOGGER.debug( |
| 180 | + "Resistance setting has been removed. " |
| 181 | + "Characteristic with a range of acceptable values not found." |
| 182 | + ) |
173 | 183 |
|
174 | 184 | if MachineSettings.POWER in settings: |
175 | 185 | if cli.services.get_characteristic(POWER_RANGE_UUID) is None: |
176 | 186 | settings &= ~MachineSettings.POWER |
| 187 | + _LOGGER.debug( |
| 188 | + "Power setting has been removed. " |
| 189 | + "Characteristic with a range of acceptable values not found." |
| 190 | + ) |
177 | 191 |
|
178 | 192 | if MachineSettings.HEART_RATE in settings: |
179 | 193 | if cli.services.get_characteristic(HEART_RATE_RANGE_UUID) is None: |
180 | 194 | settings &= ~MachineSettings.HEART_RATE |
| 195 | + _LOGGER.debug( |
| 196 | + "Heart Rate setting has been removed. " |
| 197 | + "Characteristic with a range of acceptable values not found." |
| 198 | + ) |
181 | 199 |
|
182 | 200 | # Remove untypical settings |
183 | 201 |
|
|
0 commit comments