From a94e9d472bb990abba58a841d50b73bf817777c8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 25 Jul 2024 05:29:52 -0500 Subject: [PATCH] Add support for govee H5124 vibration sensors (#122562) --- homeassistant/components/govee_ble/event.py | 7 ++++ homeassistant/components/govee_ble/icons.json | 9 +++++ .../components/govee_ble/manifest.json | 4 +++ .../components/govee_ble/strings.json | 10 ++++++ homeassistant/generated/bluetooth.py | 5 +++ tests/components/govee_ble/__init__.py | 25 ++++++++++++++ tests/components/govee_ble/test_event.py | 33 +++++++++++++++++++ 7 files changed, 93 insertions(+) create mode 100644 homeassistant/components/govee_ble/icons.json diff --git a/homeassistant/components/govee_ble/event.py b/homeassistant/components/govee_ble/event.py index 67e0b0b86fb..55275477164 100644 --- a/homeassistant/components/govee_ble/event.py +++ b/homeassistant/components/govee_ble/event.py @@ -35,6 +35,11 @@ MOTION_DESCRIPTION = EventEntityDescription( event_types=["motion"], device_class=EventDeviceClass.MOTION, ) +VIBRATION_DESCRIPTION = EventEntityDescription( + key="vibration", + event_types=["vibration"], + translation_key="vibration", +) class GoveeBluetoothEventEntity(EventEntity): @@ -95,6 +100,8 @@ async def async_setup_entry( sensor_type = model_info.sensor_type if sensor_type is SensorType.MOTION: descriptions = [MOTION_DESCRIPTION] + elif sensor_type is SensorType.VIBRATION: + descriptions = [VIBRATION_DESCRIPTION] elif sensor_type is SensorType.BUTTON: button_count = model_info.button_count descriptions = BUTTON_DESCRIPTIONS[0:button_count] diff --git a/homeassistant/components/govee_ble/icons.json b/homeassistant/components/govee_ble/icons.json new file mode 100644 index 00000000000..4a5d2a2d78c --- /dev/null +++ b/homeassistant/components/govee_ble/icons.json @@ -0,0 +1,9 @@ +{ + "entity": { + "event": { + "vibration": { + "default": "mdi:vibrate" + } + } + } +} diff --git a/homeassistant/components/govee_ble/manifest.json b/homeassistant/components/govee_ble/manifest.json index c4119275dce..0e425977211 100644 --- a/homeassistant/components/govee_ble/manifest.json +++ b/homeassistant/components/govee_ble/manifest.json @@ -26,6 +26,10 @@ "local_name": "GV5123*", "connectable": false }, + { + "local_name": "GV5124*", + "connectable": false + }, { "local_name": "GV5125*", "connectable": false diff --git a/homeassistant/components/govee_ble/strings.json b/homeassistant/components/govee_ble/strings.json index 7608e6c5c82..c3f4729873c 100644 --- a/homeassistant/components/govee_ble/strings.json +++ b/homeassistant/components/govee_ble/strings.json @@ -29,6 +29,16 @@ } } }, + "vibration": { + "name": "Vibration", + "state_attributes": { + "event_type": { + "state": { + "vibration": "Vibration" + } + } + } + }, "button_0": { "name": "Button 1", "state_attributes": { diff --git a/homeassistant/generated/bluetooth.py b/homeassistant/generated/bluetooth.py index b370c161cc0..222cf44d989 100644 --- a/homeassistant/generated/bluetooth.py +++ b/homeassistant/generated/bluetooth.py @@ -152,6 +152,11 @@ BLUETOOTH: Final[list[dict[str, bool | str | int | list[int]]]] = [ "domain": "govee_ble", "local_name": "GV5123*", }, + { + "connectable": False, + "domain": "govee_ble", + "local_name": "GV5124*", + }, { "connectable": False, "domain": "govee_ble", diff --git a/tests/components/govee_ble/__init__.py b/tests/components/govee_ble/__init__.py index 11f4065b506..838abb3d19c 100644 --- a/tests/components/govee_ble/__init__.py +++ b/tests/components/govee_ble/__init__.py @@ -162,3 +162,28 @@ GV5123_CLOSED_SERVICE_INFO = BluetoothServiceInfo( service_uuids=[], source="24:4C:AB:03:E6:B8", ) + + +GVH5124_SERVICE_INFO = BluetoothServiceInfo( + name="GV51242F68", + address="D3:32:39:37:2F:68", + rssi=-67, + manufacturer_data={ + 61320: b"\x08\xa2\x00\x01%\xc2YW\xfdzu\x0e\xf24\xa2\x18\xbb\x15F|[s{\x04" + }, + service_data={}, + service_uuids=[], + 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", +) diff --git a/tests/components/govee_ble/test_event.py b/tests/components/govee_ble/test_event.py index c2e215188ff..c41cdad3c89 100644 --- a/tests/components/govee_ble/test_event.py +++ b/tests/components/govee_ble/test_event.py @@ -9,6 +9,8 @@ from . import ( GV5121_MOTION_SERVICE_INFO_2, GV5125_BUTTON_0_SERVICE_INFO, GV5125_BUTTON_1_SERVICE_INFO, + GVH5124_2_SERVICE_INFO, + GVH5124_SERVICE_INFO, ) from tests.common import MockConfigEntry @@ -73,3 +75,34 @@ async def test_button(hass: HomeAssistant) -> None: assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() + + +async def test_vibration_sensor(hass: HomeAssistant) -> None: + """Test setting up creates the vibration sensor.""" + entry = MockConfigEntry( + domain=DOMAIN, + unique_id=GVH5124_SERVICE_INFO.address, + data={CONF_DEVICE_TYPE: "H5124"}, + ) + entry.add_to_hass(hass) + + assert await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert len(hass.states.async_all()) == 1 + inject_bluetooth_service_info(hass, GVH5124_SERVICE_INFO) + await hass.async_block_till_done() + assert len(hass.states.async_all()) == 2 + + motion_sensor = hass.states.get("event.h5124_vibration") + first_time = motion_sensor.state + assert motion_sensor.state != STATE_UNKNOWN + + inject_bluetooth_service_info(hass, GVH5124_2_SERVICE_INFO) + await hass.async_block_till_done() + + motion_sensor = hass.states.get("event.h5124_vibration") + assert motion_sensor.state != first_time + assert motion_sensor.state != STATE_UNKNOWN + assert await hass.config_entries.async_unload(entry.entry_id) + await hass.async_block_till_done()