Skip to content

Commit

Permalink
fix: h5179 is little endian and not big endian like the rest (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 30, 2022
1 parent b020ab5 commit 24a0e92
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/govee_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

_LOGGER = logging.getLogger(__name__)

PACKED_hHB_LITTLE = struct.Struct("<hHB")
PACKED_hHB = struct.Struct(">hHB")
PACKED_hh = struct.Struct(">hh")
PACKED_hhbhh = struct.Struct(">hhbhh")
Expand Down Expand Up @@ -167,7 +168,7 @@ def _process_mfr_data(

if msg_length == 9 and mgr_id == 0x8801:
self.set_device_type("H5179")
(temp, humi, batt) = PACKED_hHB.unpack(data[4:9])
temp, humi, batt = PACKED_hHB_LITTLE.unpack(data[4:9])
self.update_predefined_sensor(
SensorLibrary.TEMPERATURE__CELSIUS, temp / 100
)
Expand Down
76 changes: 76 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
service_data={},
source="local",
)
GVH5179_SERVICE_INFO = BluetoothServiceInfo(
name="Govee_H5179_3CD5",
address="10F1A254-16A5-9F35-BE40-7034507A6967",
rssi=-50,
manufacturer_data={34817: b"\xec\x00\x01\x01\n\n\xa4\x06d"},
service_data={},
service_uuids=[
"0000180a-0000-1000-8000-00805f9b34fb",
"0000fef5-0000-1000-8000-00805f9b34fb",
"0000ec88-0000-1000-8000-00805f9b34fb",
],
source="local",
)


def test_can_create():
Expand Down Expand Up @@ -469,3 +482,66 @@ def test_gvh5182():
),
},
)


def test_gvh5179():
parser = GoveeBluetoothDeviceData()
service_info = GVH5179_SERVICE_INFO
result = parser.update(service_info)
print(result)
assert result == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name=None,
model="H5179",
manufacturer="Govee",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
DeviceKey(key="temperature", device_id=None): SensorDescription(
device_key=DeviceKey(key="temperature", device_id=None),
device_class=DeviceClass.TEMPERATURE,
native_unit_of_measurement=Units.TEMP_CELSIUS,
),
DeviceKey(key="humidity", device_id=None): SensorDescription(
device_key=DeviceKey(key="humidity", device_id=None),
device_class=DeviceClass.HUMIDITY,
native_unit_of_measurement=Units.PERCENTAGE,
),
DeviceKey(key="battery", device_id=None): SensorDescription(
device_key=DeviceKey(key="battery", device_id=None),
device_class=DeviceClass.BATTERY,
native_unit_of_measurement=Units.PERCENTAGE,
),
DeviceKey(key="signal_strength", device_id=None): SensorDescription(
device_key=DeviceKey(key="signal_strength", device_id=None),
device_class=DeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
},
entity_values={
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=25.7,
),
DeviceKey(key="humidity", device_id=None): SensorValue(
device_key=DeviceKey(key="humidity", device_id=None),
name="Humidity",
native_value=17.0,
),
DeviceKey(key="battery", device_id=None): SensorValue(
device_key=DeviceKey(key="battery", device_id=None),
name="Battery",
native_value=100,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal Strength",
native_value=-50,
),
},
)

0 comments on commit 24a0e92

Please sign in to comment.