Add H5106 support to govee-ble (#107781)

* Bump govee-ble to 0.27.0

changelog: https://github.com/Bluetooth-Devices/govee-ble/compare/v0.26.0...v0.27.0

note: H5106 is partially supported, full support will be added in another PR + docs

* .1

* Add Govee H5106 support

* 0.27.2

* commit the tests
pull/108002/head
J. Nick Koston 2024-01-13 16:02:38 -10:00 committed by GitHub
parent 9c82df4b98
commit f1228a1cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

@ -19,6 +19,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfTemperature, UnitOfTemperature,
@ -58,6 +59,15 @@ SENSOR_DESCRIPTIONS = {
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
(
DeviceClass.PM25,
Units.CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
): SensorEntityDescription(
key=f"{DeviceClass.PM25}_{Units.CONCENTRATION_MICROGRAMS_PER_CUBIC_METER}",
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT,
),
} }

View File

@ -74,3 +74,13 @@ GVH5178_SERVICE_INFO_ERROR = BluetoothServiceInfo(
service_uuids=["0000ec88-0000-1000-8000-00805f9b34fb"], service_uuids=["0000ec88-0000-1000-8000-00805f9b34fb"],
source="local", source="local",
) )
GVH5106_SERVICE_INFO = BluetoothServiceInfo(
name="GVH5106_4E05",
address="CC:32:37:35:4E:05",
rssi=-66,
manufacturer_data={1: b"\x01\x01\x0e\xd12\x98"},
service_uuids=["0000ec88-0000-1000-8000-00805f9b34fb"],
service_data={},
source="local",
)

View File

@ -17,6 +17,7 @@ from homeassistant.util import dt as dt_util
from . import ( from . import (
GVH5075_SERVICE_INFO, GVH5075_SERVICE_INFO,
GVH5106_SERVICE_INFO,
GVH5178_PRIMARY_SERVICE_INFO, GVH5178_PRIMARY_SERVICE_INFO,
GVH5178_REMOTE_SERVICE_INFO, GVH5178_REMOTE_SERVICE_INFO,
GVH5178_SERVICE_INFO_ERROR, GVH5178_SERVICE_INFO_ERROR,
@ -153,3 +154,30 @@ async def test_gvh5178_multi_sensor(hass: HomeAssistant) -> None:
primary_temp_sensor = hass.states.get("sensor.b51782bc8_primary_temperature") primary_temp_sensor = hass.states.get("sensor.b51782bc8_primary_temperature")
assert primary_temp_sensor.state == STATE_UNAVAILABLE assert primary_temp_sensor.state == STATE_UNAVAILABLE
async def test_gvh5106(hass: HomeAssistant) -> None:
"""Test setting up creates the sensors for a device with PM25."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="CC:32:37:35:4E:05",
)
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()) == 0
inject_bluetooth_service_info(hass, GVH5106_SERVICE_INFO)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 3
pm25_sensor = hass.states.get("sensor.h5106_4e05_pm25")
pm25_sensor_attributes = pm25_sensor.attributes
assert pm25_sensor.state == "0"
assert pm25_sensor_attributes[ATTR_FRIENDLY_NAME] == "H5106 4E05 Pm25"
assert pm25_sensor_attributes[ATTR_UNIT_OF_MEASUREMENT] == "µg/m³"
assert pm25_sensor_attributes[ATTR_STATE_CLASS] == "measurement"
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()