Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ the dependencies are installed as well.
```
pip install bleak bleak-retry-connector
```

## Adding support for new devices

See the `Generic` class inside `SolixBLE.py` for guidance on how to add support for new devices.
30 changes: 28 additions & 2 deletions SolixBLE.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,23 @@ def _parse_telemetry(self, data: bytearray) -> None:
:param data: Bytes from status update message.
"""

# If the size is wrong then it is not a telemetry message
if len(data) != self._EXPECTED_TELEMETRY_LENGTH:
# If we are expecting a particular size and the data is not that size then the
# data we received is not the telemetry data we want
if (
self._EXPECTED_TELEMETRY_LENGTH != 0
and len(data) != self._EXPECTED_TELEMETRY_LENGTH
):
_LOGGER.debug(
f"Data is not telemetry data. The size is wrong ({len(data)} != {self._EXPECTED_TELEMETRY_LENGTH}). Data: '{data}'"
)
return

if len(data) < 100:
_LOGGER.debug(
f"Data is not telemetry data. It is too small. We expect > 100 but got '{len(data)}'. Data: '{data}'"
)
return

# If debugging and we have a previous status update to compare against
if _LOGGER.isEnabledFor(logging.DEBUG) and self._data is not None:
if data == self._data:
Expand Down Expand Up @@ -858,3 +868,19 @@ def battery_percentage(self) -> int:
:returns: Percentage charge of battery or default int value.
"""
return self._data[169] if self._data is not None else DEFAULT_METADATA_INT


class Generic(SolixBLEDevice):
"""
Generic to be used for adding support for an unsupported device.

Add support for a device like this:

1. Copy this subclass to a new class with a name of the device.
2. Initialise the new class inside example.py and connect to it.
3. Change values (e.g turn things on and off) to cause changes in the device state.
4. Observe which values change in the log and add properties to your subclass that parse them (see C300, C1000, etc for examples).
5. Profit???
"""

_EXPECTED_TELEMETRY_LENGTH: int = 0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "SolixBLE"
version = "2.0.0"
version = "2.1.0"
dependencies = [
"bleak>=0.19.0",
"bleak-retry-connector"
Expand Down
Loading