-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1380 from zt8989/master
Add initial support for Senssun scale
- Loading branch information
Showing
9 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Parser for Senssun Scale BLE advertisements""" | ||
|
||
import logging | ||
from struct import unpack | ||
|
||
from .helpers import to_mac, to_unformatted_mac | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def read_stable(ctr1): | ||
"""Parse Stable""" | ||
return int((ctr1 & 0xA0) == 0xA0) | ||
|
||
def parse_senssun(self, data: bytes, mac: str): | ||
"""Parser for Senssun Scales.""" | ||
xvalue = data[13:19] | ||
|
||
(division, weight, impedance, ctr1) = unpack(">bhhb", xvalue) | ||
result = { | ||
"type": "Senssun Smart Scale", | ||
"firmware": "Senssun", | ||
"mac": to_unformatted_mac(mac), | ||
"data": True, | ||
"impedance": impedance, | ||
"weight": weight / 100.0, | ||
"stabilized": read_stable(ctr1), | ||
} | ||
|
||
# Check for duplicate messages | ||
packet_id = xvalue.hex() | ||
try: | ||
prev_packet = self.lpacket_ids[mac] | ||
except KeyError: | ||
# start with empty first packet | ||
prev_packet = None | ||
if prev_packet == packet_id: | ||
# only process new messages | ||
if self.filter_duplicates is True: | ||
return None | ||
self.lpacket_ids[mac] = packet_id | ||
if prev_packet is None: | ||
if self.filter_duplicates is True: | ||
# ignore first message after a restart | ||
return None | ||
|
||
result.update({ | ||
"packet": packet_id, | ||
}) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""The tests for the Senssun ble_parser.""" | ||
|
||
import datetime | ||
|
||
from ble_monitor.ble_parser import BleParser | ||
|
||
|
||
class TestSenssun: | ||
"""Tests for the Senssun parser""" | ||
|
||
def test_Senssun_IF_B7(self): | ||
"""Test Senssun parser for IF_B7.""" | ||
data_string = "043E2B0201030033B3C1937A181F020106060949465F423714FF0001020311187A93C1B333021A4500B4A1AB61C5" | ||
data = bytes(bytearray.fromhex(data_string)) | ||
|
||
# pylint: disable=unused-variable | ||
ble_parser = BleParser() | ||
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) | ||
|
||
assert sensor_msg["firmware"] == "Senssun" | ||
assert sensor_msg["type"] == "Senssun Smart Scale" | ||
assert sensor_msg["mac"] == "187A93C1B333" | ||
assert sensor_msg["packet"] == "021a4500b4a1" | ||
assert sensor_msg["data"] | ||
assert sensor_msg["weight"] == 67.25 | ||
assert sensor_msg["stabilized"] == 1 | ||
assert sensor_msg["impedance"] == 180 | ||
assert sensor_msg["rssi"] == -59 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
manufacturer: Senssun | ||
name: Senssun Smart Scale | ||
model: IF_B7 | ||
image: IF_B7.jpg | ||
physical_description: | ||
broadcasted_properties: | ||
- weight | ||
- impedance | ||
- rssi | ||
broadcasted_property_notes: | ||
broadcast_rate: | ||
active_scan: | ||
encryption_key: | ||
custom_firmware: | ||
notes: | ||
--- |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters