-
-
Notifications
You must be signed in to change notification settings - Fork 250
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 #1275 from custom-components/grundfos
Add Grundfos ALPHA Reader MI401
- Loading branch information
Showing
11 changed files
with
180 additions
and
8 deletions.
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,66 @@ | ||
"""Parser for Grundfos BLE advertisements""" | ||
import logging | ||
from struct import unpack | ||
|
||
from .helpers import to_mac, to_unformatted_mac | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
PUMP_MODE_DICT = { | ||
0: "Constant speed level 3", | ||
1: "Constant speed level 2", | ||
2: "Constant speed level 1", | ||
3: "Autoadapt", | ||
4: "Proportional pressure level 1", | ||
5: "Proportional pressure level 2", | ||
6: "Proportional pressure level 3", | ||
7: "Constant differential pressure level 1", | ||
8: "Constant differential pressure level 2", | ||
9: "Constant differential pressure level 1", | ||
} | ||
|
||
|
||
def parse_grundfos(self, data, source_mac, rssi): | ||
"""Grundfos parser""" | ||
device_type = "MI401" | ||
firmware = "Grundfos" | ||
grundfos_mac = source_mac | ||
|
||
xvalue = data[6:17] | ||
(packet, bat_status, pump_id, flow, press, pump_mode, temp) = unpack( | ||
"<BBHHhxBB", xvalue | ||
) | ||
pump_mode = PUMP_MODE_DICT[pump_mode] | ||
|
||
result = { | ||
"packet": packet, | ||
"flow": round(flow / 6.5534, 1), | ||
"water pressure": round(press / 32767, 3), | ||
"temperature": temp, | ||
"pump mode": pump_mode, | ||
"pump id": pump_id, | ||
"battery status": bat_status, | ||
} | ||
|
||
if self.report_unknown == "Grundfos": | ||
_LOGGER.info( | ||
"BLE ADV from UNKNOWN Grundfos DEVICE: RSSI: %s, MAC: %s, ADV: %s", | ||
rssi, | ||
to_mac(grundfos_mac), | ||
data.hex() | ||
) | ||
|
||
# check for MAC presence in sensor whitelist, if needed | ||
if self.discovery is False and grundfos_mac not in self.sensor_whitelist: | ||
_LOGGER.debug("Discovery is disabled. MAC: %s is not whitelisted!", to_mac(grundfos_mac)) | ||
return None | ||
|
||
result.update({ | ||
"rssi": rssi, | ||
"mac": to_unformatted_mac(grundfos_mac), | ||
"type": device_type, | ||
"firmware": firmware, | ||
"data": True | ||
}) | ||
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 |
---|---|---|
|
@@ -14,5 +14,5 @@ | |
"btsocket>=0.2.0", | ||
"pyric>=0.1.6.3" | ||
], | ||
"version": "12.7.0" | ||
"version": "12.7.1" | ||
} |
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,26 @@ | ||
"""The tests for the Grundfos ble_parser.""" | ||
from ble_monitor.ble_parser import BleParser | ||
|
||
|
||
class TestGrundfos: | ||
"""Tests for the Grundfos parser""" | ||
def test_grundfos_MI401(self): | ||
"""Test Grundfos parser for ALPHA reader MI401.""" | ||
data_string = "043E2A020103009565F1164DAC1E06084D4934303116FF14F230017A03059884103E0F19070D0114FFFFFFFFC0" | ||
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"] == "Grundfos" | ||
assert sensor_msg["type"] == "MI401" | ||
assert sensor_msg["mac"] == "AC4D16F16595" | ||
assert sensor_msg["packet"] == 122 | ||
assert sensor_msg["data"] | ||
assert sensor_msg["temperature"] == 13 | ||
assert sensor_msg["flow"] == 645.2 | ||
assert sensor_msg["water pressure"] == 0.119 | ||
assert sensor_msg["pump mode"] == "Constant differential pressure level 1" | ||
assert sensor_msg["pump id"] == 38917 | ||
assert sensor_msg["battery status"] == 3 | ||
assert sensor_msg["rssi"] == -64 |
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,29 @@ | ||
--- | ||
manufacturer: Grundfos | ||
name: ALPHA Reader MI401 | ||
model: MI401 | ||
image: Grundfos_MI401.png | ||
physical_description: Rounded stick | ||
broadcasted_properties: | ||
- flow | ||
- water pressure | ||
- temperature | ||
- battery state | ||
- pump mode | ||
- pump id | ||
- rssi | ||
broadcasted_property_notes: | ||
- property: battery state | ||
note: Battery state is an attribute of the pump mode sensor. The meaning of the state is unknown. If you have more information about the | ||
meaning of the different states, let us know | ||
- property: pump id | ||
note: The pum id is an attribute of the pump mode sensor. The reader can send data of multiple pumps, each with its own id. In the current | ||
implementation, we have assumed that only one pump is connected, which means that data of multiple pumps gets mixed in the sensor output. | ||
If you have multipel pumps, modifications to the code will have to be made. Please open a new issue if you want to request multiple pump support. | ||
broadcast_rate: | ||
active_scan: true | ||
encryption_key: | ||
custom_firmware: | ||
notes: | ||
- actve scan needs to be enabled in the BLE Monitor settings for this sensor to work. | ||
--- |
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