Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vibration sensor is on only and should have been an event #100

Merged
merged 1 commit into from
Jul 24, 2024
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
5 changes: 2 additions & 3 deletions src/govee_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
76 changes: 69 additions & 7 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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={},
)


Expand Down
Loading