From a6ac514fd67f96cf7c6e7afde7a575e36def32d4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 24 Jul 2024 16:17:41 -0500 Subject: [PATCH] fix: vibration sensor is on only and should have been an event --- src/govee_ble/parser.py | 5 ++- tests/test_parser.py | 76 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/govee_ble/parser.py b/src/govee_ble/parser.py index 6bd13c1..19532d9 100644 --- a/src/govee_ble/parser.py +++ b/src/govee_ble/parser.py @@ -302,9 +302,8 @@ def _process_mfr_data( ) elif sensor_type is SensorType.VIBRATION: # H5124 is a vibration sensor - self.update_predefined_binary_sensor( - BinarySensorDeviceClass.VIBRATION, button_number_pressed == 1 - ) + if button_number_pressed == 1: + self.fire_event("vibration", "vibration") elif sensor_type is SensorType.MOTION: if button_number_pressed == 1: self.fire_event("motion", "motion") diff --git a/tests/test_parser.py b/tests/test_parser.py index 6a5e351..b241b8b 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -698,6 +698,18 @@ source="local", ) +GVH5124_2_SERVICE_INFO = BluetoothServiceInfo( + name="GV51242F68", + address="D3:32:39:37:2F:68", + rssi=-67, + manufacturer_data={ + 61320: b"\x08\xa2\x00\x13^Sso\xaeC\x9aU\xcf\xd8\x02\x1b\xdf\xd5\xded;+\xd6\x13" + }, + service_data={}, + service_uuids=[], + source="local", +) + def test_can_create(): GoveeBluetoothDeviceData() @@ -2105,20 +2117,70 @@ def test_gvh5124_vibrating(): native_value=-67, ), }, - binary_entity_descriptions={ - DeviceKey(key="vibration", device_id=None): BinarySensorDescription( + binary_entity_descriptions={}, + binary_entity_values={}, + events={ + DeviceKey(key="vibration", device_id=None): Event( device_key=DeviceKey(key="vibration", device_id=None), - device_class=BinarySensorDeviceClass.VIBRATION, + name="Vibration", + event_type="vibration", + event_properties=None, ) }, - binary_entity_values={ - DeviceKey(key="vibration", device_id=None): BinarySensorValue( + ) + + +def test_gvh5124_vibrating_2(): + parser = GoveeBluetoothDeviceData() + service_info = GVH5124_2_SERVICE_INFO + result = parser.update(service_info) + assert parser.sensor_type is SensorType.VIBRATION + + assert result == SensorUpdate( + title=None, + devices={ + None: SensorDeviceInfo( + name="51242F68", + model="H5124", + manufacturer="Govee", + sw_version=None, + hw_version=None, + ) + }, + entity_descriptions={ + DeviceKey(key="battery", device_id=None): SensorDescription( + device_key=DeviceKey(key="battery", device_id=None), + device_class=SensorDeviceClass.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=SensorDeviceClass.SIGNAL_STRENGTH, + native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + ), + }, + entity_values={ + 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=-67, + ), + }, + binary_entity_descriptions={}, + binary_entity_values={}, + events={ + DeviceKey(key="vibration", device_id=None): Event( device_key=DeviceKey(key="vibration", device_id=None), name="Vibration", - native_value=True, + event_type="vibration", + event_properties=None, ) }, - events={}, )