@@ -157,6 +157,28 @@ async def read_features(
157157 _LOGGER .exception ("Failed reading machine features and settings." )
158158 raise
159159
160+ # Remove settings without ranges UUIDs
161+
162+ if MachineSettings .SPEED in settings :
163+ if cli .services .get_characteristic (SPEED_RANGE_UUID ) is None :
164+ settings &= ~ MachineSettings .SPEED
165+
166+ if MachineSettings .INCLINE in settings :
167+ if cli .services .get_characteristic (INCLINATION_RANGE_UUID ) is None :
168+ settings &= ~ MachineSettings .INCLINE
169+
170+ if MachineSettings .RESISTANCE in settings :
171+ if cli .services .get_characteristic (RESISTANCE_LEVEL_RANGE_UUID ) is None :
172+ settings &= ~ MachineSettings .RESISTANCE
173+
174+ if MachineSettings .POWER in settings :
175+ if cli .services .get_characteristic (POWER_RANGE_UUID ) is None :
176+ settings &= ~ MachineSettings .POWER
177+
178+ if MachineSettings .HEART_RATE in settings :
179+ if cli .services .get_characteristic (HEART_RATE_RANGE_UUID ) is None :
180+ settings &= ~ MachineSettings .HEART_RATE
181+
160182 # Remove untypical settings
161183
162184 if MachineType .TREADMILL in mt :
@@ -166,12 +188,10 @@ async def read_features(
166188 settings &= ~ (MachineSettings .SPEED | MachineSettings .INCLINE )
167189
168190 elif MachineType .INDOOR_BIKE in mt :
169- settings &= ~ (MachineSettings .INCLINE | MachineSettings .RESISTANCE )
191+ settings &= ~ (MachineSettings .SPEED | MachineSettings .INCLINE )
170192
171193 elif MachineType .ROWER in mt :
172- settings &= ~ (
173- MachineSettings .SPEED | MachineSettings .INCLINE | MachineSettings .RESISTANCE
174- )
194+ settings &= ~ (MachineSettings .SPEED | MachineSettings .INCLINE )
175195
176196 _LOGGER .debug ("Features: %s" , features )
177197 _LOGGER .debug ("Settings: %s" , settings )
@@ -187,42 +207,29 @@ async def read_supported_ranges(
187207
188208 _LOGGER .debug ("Reading settings value ranges..." )
189209
190- async def _range (uuid : str , num : str ) -> SettingRange | None :
191- if c := cli .services .get_characteristic (uuid ):
192- data = await cli .read_gatt_char (c )
193-
194- bio , serializer = io .BytesIO (data ), NumSerializer (num )
195- result = SettingRange (* (serializer .deserialize (bio ) or 0 for _ in range (3 )))
210+ async def _range (uuid : str , num : str ) -> SettingRange :
211+ data = await cli .read_gatt_char (uuid )
196212
197- assert not bio . read ( 1 )
198- return result
213+ bio , serializer = io . BytesIO ( data ), NumSerializer ( num )
214+ result = SettingRange ( * ( serializer . deserialize ( bio ) or 0 for _ in range ( 3 )))
199215
200- _LOGGER .debug ("Characteristic '%s' not found." , uuid )
216+ assert not bio .read (1 )
217+ return result
201218
202219 if MachineSettings .SPEED in settings :
203- _LOGGER .debug ("Reading speed range..." )
204- if x := await _range (SPEED_RANGE_UUID , "u2.01" ):
205- result [TARGET_SPEED ] = x
220+ result [TARGET_SPEED ] = await _range (SPEED_RANGE_UUID , "u2.01" )
206221
207222 if MachineSettings .INCLINE in settings :
208- _LOGGER .debug ("Reading incline range..." )
209- if x := await _range (INCLINATION_RANGE_UUID , "s2.1" ):
210- result [TARGET_INCLINATION ] = x
223+ result [TARGET_INCLINATION ] = await _range (INCLINATION_RANGE_UUID , "s2.1" )
211224
212225 if MachineSettings .RESISTANCE in settings :
213- _LOGGER .debug ("Reading resistance range..." )
214- if x := await _range (RESISTANCE_LEVEL_RANGE_UUID , "s2.1" ):
215- result [TARGET_RESISTANCE ] = x
226+ result [TARGET_RESISTANCE ] = await _range (RESISTANCE_LEVEL_RANGE_UUID , "s2.1" )
216227
217228 if MachineSettings .POWER in settings :
218- _LOGGER .debug ("Reading power range..." )
219- if x := await _range (POWER_RANGE_UUID , "s2" ):
220- result [TARGET_POWER ] = x
229+ result [TARGET_POWER ] = await _range (POWER_RANGE_UUID , "s2" )
221230
222231 if MachineSettings .HEART_RATE in settings :
223- _LOGGER .debug ("Reading heart rate range..." )
224- if x := await _range (HEART_RATE_RANGE_UUID , "u1" ):
225- result [TARGET_HEART_RATE ] = x
232+ result [TARGET_HEART_RATE ] = await _range (HEART_RATE_RANGE_UUID , "u1" )
226233
227234 _LOGGER .debug ("Settings ranges: %s" , result )
228235
0 commit comments