Skip to content

Commit 5dba5fc

Browse files
funkadelicbdraco
andauthored
Add Govee H5140 CO2 monitor support to govee_ble (home-assistant#164365)
Co-authored-by: J. Nick Koston <nick@koston.org>
1 parent 713b7cf commit 5dba5fc

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

homeassistant/components/govee_ble/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
"connectable": false,
5555
"local_name": "GVH5110*"
5656
},
57+
{
58+
"connectable": false,
59+
"local_name": "GV5140*"
60+
},
5761
{
5862
"connectable": false,
5963
"manufacturer_id": 1,

homeassistant/components/govee_ble/sensor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222
from homeassistant.const import (
2323
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
24+
CONCENTRATION_PARTS_PER_MILLION,
2425
PERCENTAGE,
2526
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
2627
UnitOfTemperature,
@@ -72,6 +73,12 @@
7273
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
7374
state_class=SensorStateClass.MEASUREMENT,
7475
),
76+
(DeviceClass.CO2, Units.CONCENTRATION_PARTS_PER_MILLION): SensorEntityDescription(
77+
key=f"{DeviceClass.CO2}_{Units.CONCENTRATION_PARTS_PER_MILLION}",
78+
device_class=SensorDeviceClass.CO2,
79+
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
80+
state_class=SensorStateClass.MEASUREMENT,
81+
),
7582
}
7683

7784

homeassistant/generated/bluetooth.py

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/components/govee_ble/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
source="local",
8585
)
8686

87-
8887
GV5125_BUTTON_0_SERVICE_INFO = BluetoothServiceInfo(
8988
name="GV51255367",
9089
address="C1:37:37:32:0F:45",
@@ -163,6 +162,16 @@
163162
source="24:4C:AB:03:E6:B8",
164163
)
165164

165+
# Encodes: temperature=21.6°C, humidity=67.8%, CO2=531 ppm, no error
166+
GV5140_SERVICE_INFO = BluetoothServiceInfo(
167+
name="GV5140EEFF",
168+
address="AA:BB:CC:DD:EE:FF",
169+
rssi=-63,
170+
manufacturer_data={1: b"\x01\x01\x03\x4e\x66\x02\x13\x00"},
171+
service_uuids=["0000ec88-0000-1000-8000-00805f9b34fb"],
172+
service_data={},
173+
source="local",
174+
)
166175

167176
GVH5124_SERVICE_INFO = BluetoothServiceInfo(
168177
name="GV51242F68",

tests/components/govee_ble/test_sensor.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from homeassistant.util import dt as dt_util
1818

1919
from . import (
20+
GV5140_SERVICE_INFO,
2021
GVH5075_SERVICE_INFO,
2122
GVH5106_SERVICE_INFO,
2223
GVH5178_PRIMARY_SERVICE_INFO,
@@ -163,6 +164,33 @@ async def test_gvh5178_multi_sensor(hass: HomeAssistant) -> None:
163164
assert primary_temp_sensor.state == STATE_UNAVAILABLE
164165

165166

167+
async def test_gv5140(hass: HomeAssistant) -> None:
168+
"""Test setting up creates the sensors for a device with CO2."""
169+
entry = MockConfigEntry(
170+
domain=DOMAIN,
171+
unique_id="AA:BB:CC:DD:EE:FF",
172+
)
173+
entry.add_to_hass(hass)
174+
175+
assert await hass.config_entries.async_setup(entry.entry_id)
176+
await hass.async_block_till_done()
177+
178+
assert len(hass.states.async_all()) == 0
179+
inject_bluetooth_service_info(hass, GV5140_SERVICE_INFO)
180+
await hass.async_block_till_done()
181+
assert len(hass.states.async_all()) == 3
182+
183+
co2_sensor = hass.states.get("sensor.5140eeff_carbon_dioxide")
184+
co2_sensor_attributes = co2_sensor.attributes
185+
assert co2_sensor.state == "531"
186+
assert co2_sensor_attributes[ATTR_FRIENDLY_NAME] == "5140EEFF Carbon Dioxide"
187+
assert co2_sensor_attributes[ATTR_UNIT_OF_MEASUREMENT] == "ppm"
188+
assert co2_sensor_attributes[ATTR_STATE_CLASS] == "measurement"
189+
190+
assert await hass.config_entries.async_unload(entry.entry_id)
191+
await hass.async_block_till_done()
192+
193+
166194
async def test_gvh5106(hass: HomeAssistant) -> None:
167195
"""Test setting up creates the sensors for a device with PM25."""
168196
entry = MockConfigEntry(

0 commit comments

Comments
 (0)