Add Qingping integration (BLE) (#76598)
* Add Qingping integration (BLE) * commit the binary sensor * add binary_sensor file * Update homeassistant/components/qingping/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/qingping/config_flow.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/qingping/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * fix const CONCENTRATION_MICROGRAMS_PER_CUBIC_METER * cover case where config flow is started, another path adds it, and then they resume * fix missed values Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
0d45cef6f6
commit
f55c274d83
19 changed files with 918 additions and 0 deletions
50
tests/components/qingping/test_sensor.py
Normal file
50
tests/components/qingping/test_sensor.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""Test the Qingping sensors."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.bluetooth import BluetoothChange
|
||||
from homeassistant.components.qingping.const import DOMAIN
|
||||
from homeassistant.components.sensor import ATTR_STATE_CLASS
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT
|
||||
|
||||
from . import LIGHT_AND_SIGNAL_SERVICE_INFO
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_sensors(hass):
|
||||
"""Test setting up creates the sensors."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="aa:bb:cc:dd:ee:ff",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
saved_callback = None
|
||||
|
||||
def _async_register_callback(_hass, _callback, _matcher, _mode):
|
||||
nonlocal saved_callback
|
||||
saved_callback = _callback
|
||||
return lambda: None
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.bluetooth.update_coordinator.async_register_callback",
|
||||
_async_register_callback,
|
||||
):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all("sensor")) == 0
|
||||
saved_callback(LIGHT_AND_SIGNAL_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_all("sensor")) == 1
|
||||
|
||||
lux_sensor = hass.states.get("sensor.motion_light_eeff_illuminance")
|
||||
lux_sensor_attrs = lux_sensor.attributes
|
||||
assert lux_sensor.state == "13"
|
||||
assert lux_sensor_attrs[ATTR_FRIENDLY_NAME] == "Motion & Light EEFF Illuminance"
|
||||
assert lux_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "lx"
|
||||
assert lux_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
Loading…
Add table
Add a link
Reference in a new issue