Skip to content

Commit 483284d

Browse files
committed
v0.4.8
1 parent e537cd7 commit 483284d

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

pyftms/client/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ class FtmsError(Exception):
66
"""Base FTMS error"""
77

88

9+
class CharacteristicNotFound(FtmsError):
10+
def __init__(self, name: str) -> None:
11+
super().__init__(f"Mandatory characteristic '{name}' not found.")
12+
13+
914
class NotFitnessMachineError(FtmsError):
1015
"""
1116
An exception if the FTMS service is not supported by the Bluetooth device.

pyftms/client/properties/features.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
TARGET_RESISTANCE,
2424
TARGET_SPEED,
2525
)
26+
from ..errors import CharacteristicNotFound
2627
from .machine_type import MachineType
2728

2829
_LOGGER = logging.getLogger(__name__)
@@ -139,45 +140,62 @@ class SettingRange(NamedTuple):
139140

140141

141142
async def read_features(
142-
cli: BleakClient, mt: MachineType
143+
cli: BleakClient,
144+
mt: MachineType,
143145
) -> tuple[MachineFeatures, MachineSettings]:
144146
_LOGGER.debug("Reading features and settings...")
145147

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")
150150

151-
bio, u4 = io.BytesIO(data), NumSerializer("u4")
151+
assert len(data := await cli.read_gatt_char(c)) == 8
152152

153-
features = MachineFeatures(u4.deserialize(bio))
154-
settings = MachineSettings(u4.deserialize(bio))
153+
bio, u4 = io.BytesIO(data), NumSerializer("u4")
155154

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))
159157

160158
# Remove settings without ranges UUIDs
161159

162160
if MachineSettings.SPEED in settings:
163161
if cli.services.get_characteristic(SPEED_RANGE_UUID) is None:
164162
settings &= ~MachineSettings.SPEED
163+
_LOGGER.debug(
164+
"Speed setting has been removed. "
165+
"Characteristic with a range of acceptable values not found."
166+
)
165167

166168
if MachineSettings.INCLINE in settings:
167169
if cli.services.get_characteristic(INCLINATION_RANGE_UUID) is None:
168170
settings &= ~MachineSettings.INCLINE
171+
_LOGGER.debug(
172+
"Inclination setting has been removed. "
173+
"Characteristic with a range of acceptable values not found."
174+
)
169175

170176
if MachineSettings.RESISTANCE in settings:
171177
if cli.services.get_characteristic(RESISTANCE_LEVEL_RANGE_UUID) is None:
172178
settings &= ~MachineSettings.RESISTANCE
179+
_LOGGER.debug(
180+
"Resistance setting has been removed. "
181+
"Characteristic with a range of acceptable values not found."
182+
)
173183

174184
if MachineSettings.POWER in settings:
175185
if cli.services.get_characteristic(POWER_RANGE_UUID) is None:
176186
settings &= ~MachineSettings.POWER
187+
_LOGGER.debug(
188+
"Power setting has been removed. "
189+
"Characteristic with a range of acceptable values not found."
190+
)
177191

178192
if MachineSettings.HEART_RATE in settings:
179193
if cli.services.get_characteristic(HEART_RATE_RANGE_UUID) is None:
180194
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+
)
181199

182200
# Remove untypical settings
183201

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyftms"
3-
version = "0.4.7"
3+
version = "0.4.8"
44
description = "Python Fitness Machine Service client library."
55
authors = ["Sergey V. DUDANOV <sergey.dudanov@gmail.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)