Use registry to find linked batteries for homekit (#33519)
This commit is contained in:
1 parent
46920e9be6
commit
96649a7e27
12 files changed
+555
-127
No files matched your search
@@ -24,6 +24,7 @@ from homeassistant.components.homekit.const import (
|
||||
CHAR_MODEL,
|
||||
CHAR_NAME,
|
||||
CHAR_SERIAL_NUMBER,
|
||||
CONF_LINKED_BATTERY_CHARGING_SENSOR,
|
||||
CONF_LINKED_BATTERY_SENSOR,
|
||||
CONF_LOW_BATTERY_THRESHOLD,
|
||||
MANUFACTURER,
|
||||
@@ -36,6 +37,8 @@ from homeassistant.const import (
|
||||
ATTR_NOW,
|
||||
ATTR_SERVICE,
|
||||
EVENT_TIME_CHANGED,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
__version__,
|
||||
)
|
||||
import homeassistant.util.dt as dt_util
|
||||
@@ -245,6 +248,99 @@ async def test_linked_battery_sensor(hass, hk_driver, caplog):
|
||||
assert acc._char_charging.value == 0
|
||||
|
||||
|
||||
async def test_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
||||
"""Test battery service with linked_battery_charging_sensor."""
|
||||
entity_id = "homekit.accessory"
|
||||
linked_battery_charging_sensor = "binary_sensor.battery_charging"
|
||||
hass.states.async_set(entity_id, "open", {ATTR_BATTERY_LEVEL: 100})
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_ON, None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = HomeAccessory(
|
||||
hass,
|
||||
hk_driver,
|
||||
"Battery Service",
|
||||
entity_id,
|
||||
2,
|
||||
{CONF_LINKED_BATTERY_CHARGING_SENSOR: linked_battery_charging_sensor},
|
||||
)
|
||||
acc.update_state = lambda x: None
|
||||
assert acc.linked_battery_charging_sensor == linked_battery_charging_sensor
|
||||
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_battery.value == 100
|
||||
assert acc._char_low_battery.value == 0
|
||||
assert acc._char_charging.value == 1
|
||||
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_OFF, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_charging.value == 0
|
||||
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_ON, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_charging.value == 1
|
||||
|
||||
|
||||
async def test_linked_battery_sensor_and_linked_battery_charging_sensor(
|
||||
hass, hk_driver, caplog
|
||||
):
|
||||
"""Test battery service with linked_battery_sensor and a linked_battery_charging_sensor."""
|
||||
entity_id = "homekit.accessory"
|
||||
linked_battery = "sensor.battery"
|
||||
linked_battery_charging_sensor = "binary_sensor.battery_charging"
|
||||
hass.states.async_set(entity_id, "open", {ATTR_BATTERY_LEVEL: 100})
|
||||
hass.states.async_set(linked_battery, 50, None)
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_ON, None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = HomeAccessory(
|
||||
hass,
|
||||
hk_driver,
|
||||
"Battery Service",
|
||||
entity_id,
|
||||
2,
|
||||
{
|
||||
CONF_LINKED_BATTERY_SENSOR: linked_battery,
|
||||
CONF_LINKED_BATTERY_CHARGING_SENSOR: linked_battery_charging_sensor,
|
||||
},
|
||||
)
|
||||
acc.update_state = lambda x: None
|
||||
assert acc.linked_battery_sensor == linked_battery
|
||||
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_battery.value == 50
|
||||
assert acc._char_low_battery.value == 0
|
||||
assert acc._char_charging.value == 1
|
||||
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_OFF, None)
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_battery.value == 50
|
||||
assert acc._char_low_battery.value == 0
|
||||
assert acc._char_charging.value == 0
|
||||
|
||||
|
||||
async def test_missing_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
||||
"""Test battery service with linked_battery_charging_sensor that is mapping to a missing entity."""
|
||||
entity_id = "homekit.accessory"
|
||||
linked_battery_charging_sensor = "binary_sensor.battery_charging"
|
||||
hass.states.async_set(entity_id, "open", {ATTR_BATTERY_LEVEL: 100})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = HomeAccessory(
|
||||
hass,
|
||||
hk_driver,
|
||||
"Battery Service",
|
||||
entity_id,
|
||||
2,
|
||||
{CONF_LINKED_BATTERY_CHARGING_SENSOR: linked_battery_charging_sensor},
|
||||
)
|
||||
assert acc.linked_battery_charging_sensor is None
|
||||
|
||||
|
||||
async def test_missing_linked_battery_sensor(hass, hk_driver, caplog):
|
||||
"""Test battery service with missing linked_battery_sensor."""
|
||||
entity_id = "homekit.accessory"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"""Tests for the HomeKit component."""
|
||||
from unittest.mock import ANY, Mock, patch
|
||||
|
||||
from asynctest import CoroutineMock
|
||||
import pytest
|
||||
from zeroconf import InterfaceChoice
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant.components.binary_sensor import DEVICE_CLASS_BATTERY_CHARGING
|
||||
from homeassistant.components.homekit import (
|
||||
MAX_DEVICES,
|
||||
STATUS_READY,
|
||||
@@ -27,22 +29,39 @@ from homeassistant.components.homekit.const import (
|
||||
SERVICE_HOMEKIT_START,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.helpers.entityfilter import generate_filter
|
||||
|
||||
from tests.common import MockConfigEntry, mock_device_registry, mock_registry
|
||||
from tests.components.homekit.common import patch_debounce
|
||||
|
||||
IP_ADDRESS = "127.0.0.1"
|
||||
PATH_HOMEKIT = "homeassistant.components.homekit"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device_reg(hass):
|
||||
"""Return an empty, loaded, registry."""
|
||||
return mock_device_registry(hass)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entity_reg(hass):
|
||||
"""Return an empty, loaded, registry."""
|
||||
return mock_registry(hass)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def debounce_patcher():
|
||||
"""Patch debounce method."""
|
||||
@@ -66,7 +85,7 @@ async def test_setup_min(hass):
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_homekit().start.assert_called_with(ANY)
|
||||
mock_homekit().async_start.assert_called_with(ANY)
|
||||
|
||||
|
||||
async def test_setup_auto_start_disabled(hass):
|
||||
@@ -83,6 +102,7 @@ async def test_setup_auto_start_disabled(hass):
|
||||
|
||||
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
|
||||
mock_homekit.return_value = homekit = Mock()
|
||||
type(homekit).async_start = CoroutineMock()
|
||||
assert await setup.async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
mock_homekit.assert_any_call(
|
||||
@@ -92,23 +112,26 @@ async def test_setup_auto_start_disabled(hass):
|
||||
|
||||
# Test auto_start disabled
|
||||
homekit.reset_mock()
|
||||
homekit.async_start.reset_mock()
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
assert homekit.start.called is False
|
||||
assert homekit.async_start.called is False
|
||||
|
||||
# Test start call with driver is ready
|
||||
homekit.reset_mock()
|
||||
homekit.async_start.reset_mock()
|
||||
homekit.status = STATUS_READY
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_HOMEKIT_START, blocking=True)
|
||||
assert homekit.start.called is True
|
||||
assert homekit.async_start.called is True
|
||||
|
||||
# Test start call with driver started
|
||||
homekit.reset_mock()
|
||||
homekit.async_start.reset_mock()
|
||||
homekit.status = STATUS_STOPPED
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_HOMEKIT_START, blocking=True)
|
||||
assert homekit.start.called is False
|
||||
assert homekit.async_start.called is False
|
||||
|
||||
|
||||
async def test_homekit_setup(hass, hk_driver):
|
||||
@@ -279,6 +302,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||
homekit.bridge = Mock()
|
||||
homekit.bridge.accessories = []
|
||||
homekit.driver = hk_driver
|
||||
homekit._filter = Mock(return_value=True)
|
||||
|
||||
hass.states.async_set("light.demo", "on")
|
||||
state = hass.states.async_all()[0]
|
||||
@@ -290,7 +314,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||
) as hk_driver_add_acc, patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.start"
|
||||
) as hk_driver_start:
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
await homekit.async_start()
|
||||
|
||||
mock_add_acc.assert_called_with(state)
|
||||
mock_setup_msg.assert_called_with(hass, pin, ANY)
|
||||
@@ -300,7 +324,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||
|
||||
# Test start() if already started
|
||||
hk_driver_start.reset_mock()
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
await homekit.async_start()
|
||||
assert not hk_driver_start.called
|
||||
|
||||
|
||||
@@ -326,7 +350,7 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
|
||||
) as hk_driver_add_acc, patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.start"
|
||||
) as hk_driver_start:
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
await homekit.async_start()
|
||||
|
||||
mock_setup_msg.assert_called_with(hass, pin, ANY)
|
||||
hk_driver_add_acc.assert_called_with(homekit.bridge)
|
||||
@@ -335,7 +359,7 @@ async def test_homekit_start_with_a_broken_accessory(hass, hk_driver, debounce_p
|
||||
|
||||
# Test start() if already started
|
||||
hk_driver_start.reset_mock()
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
await homekit.async_start()
|
||||
assert not hk_driver_start.called
|
||||
|
||||
|
||||
@@ -344,17 +368,23 @@ async def test_homekit_stop(hass):
|
||||
homekit = HomeKit(hass, None, None, None, None, None, None)
|
||||
homekit.driver = Mock()
|
||||
|
||||
assert await setup.async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
|
||||
assert homekit.status == STATUS_READY
|
||||
await hass.async_add_executor_job(homekit.stop)
|
||||
await homekit.async_stop()
|
||||
await hass.async_block_till_done()
|
||||
homekit.status = STATUS_WAIT
|
||||
await hass.async_add_executor_job(homekit.stop)
|
||||
await homekit.async_stop()
|
||||
await hass.async_block_till_done()
|
||||
homekit.status = STATUS_STOPPED
|
||||
await hass.async_add_executor_job(homekit.stop)
|
||||
await homekit.async_stop()
|
||||
await hass.async_block_till_done()
|
||||
assert homekit.driver.stop.called is False
|
||||
|
||||
# Test if driver is started
|
||||
homekit.status = STATUS_RUNNING
|
||||
await hass.async_add_executor_job(homekit.stop)
|
||||
await homekit.async_stop()
|
||||
await hass.async_block_till_done()
|
||||
assert homekit.driver.stop.called is True
|
||||
|
||||
|
||||
@@ -408,5 +438,74 @@ async def test_homekit_too_many_accessories(hass, hk_driver):
|
||||
), patch("homeassistant.components.homekit._LOGGER.warning") as mock_warn, patch(
|
||||
f"{PATH_HOMEKIT}.show_setup_message"
|
||||
):
|
||||
await hass.async_add_executor_job(homekit.start)
|
||||
await homekit.async_start()
|
||||
await hass.async_block_till_done()
|
||||
assert mock_warn.called is True
|
||||
|
||||
|
||||
async def test_homekit_finds_linked_batteries(
|
||||
hass, hk_driver, debounce_patcher, device_reg, entity_reg
|
||||
):
|
||||
"""Test HomeKit start method."""
|
||||
assert await setup.async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
|
||||
homekit = HomeKit(hass, None, None, None, {}, {"light.demo": {}}, None, None)
|
||||
homekit.driver = hk_driver
|
||||
homekit._filter = Mock(return_value=True)
|
||||
homekit.bridge = HomeBridge(hass, hk_driver, "mock_bridge")
|
||||
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
device_entry = device_reg.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
|
||||
binary_charging_sensor = entity_reg.async_get_or_create(
|
||||
"binary_sensor",
|
||||
"light",
|
||||
"battery_charging",
|
||||
device_id=device_entry.id,
|
||||
device_class=DEVICE_CLASS_BATTERY_CHARGING,
|
||||
)
|
||||
battery_sensor = entity_reg.async_get_or_create(
|
||||
"sensor",
|
||||
"light",
|
||||
"battery",
|
||||
device_id=device_entry.id,
|
||||
device_class=DEVICE_CLASS_BATTERY,
|
||||
)
|
||||
light = entity_reg.async_get_or_create(
|
||||
"light", "light", "demo", device_id=device_entry.id
|
||||
)
|
||||
|
||||
hass.states.async_set(
|
||||
binary_charging_sensor.entity_id,
|
||||
STATE_ON,
|
||||
{ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY_CHARGING},
|
||||
)
|
||||
hass.states.async_set(
|
||||
battery_sensor.entity_id, 30, {ATTR_DEVICE_CLASS: DEVICE_CLASS_BATTERY}
|
||||
)
|
||||
hass.states.async_set(light.entity_id, STATE_ON)
|
||||
|
||||
def _mock_get_accessory(*args, **kwargs):
|
||||
return [None, "acc", None]
|
||||
|
||||
with patch.object(homekit.bridge, "add_accessory"), patch(
|
||||
f"{PATH_HOMEKIT}.show_setup_message"
|
||||
), patch(f"{PATH_HOMEKIT}.get_accessory") as mock_get_acc, patch(
|
||||
"pyhap.accessory_driver.AccessoryDriver.start"
|
||||
):
|
||||
await homekit.async_start()
|
||||
|
||||
mock_get_acc.assert_called_with(
|
||||
hass,
|
||||
hk_driver,
|
||||
ANY,
|
||||
ANY,
|
||||
{
|
||||
"linked_battery_charging_sensor": "binary_sensor.light_battery_charging",
|
||||
"linked_battery_sensor": "sensor.light_battery",
|
||||
},
|
||||
)
|
||||
@@ -65,6 +65,7 @@ async def test_garage_door_open_close(hass, hk_driver, cls, events):
|
||||
await hass.async_block_till_done()
|
||||
acc = cls.garage(hass, hk_driver, "Garage Door", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 4 # GarageDoorOpener
|
||||
@@ -143,6 +144,7 @@ async def test_window_set_cover_position(hass, hk_driver, cls, events):
|
||||
await hass.async_block_till_done()
|
||||
acc = cls.window(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 14 # WindowCovering
|
||||
@@ -214,6 +216,7 @@ async def test_window_cover_set_tilt(hass, hk_driver, cls, events):
|
||||
await hass.async_block_till_done()
|
||||
acc = cls.window(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 14 # CATEGORY_WINDOW_COVERING
|
||||
@@ -277,6 +280,7 @@ async def test_window_open_close(hass, hk_driver, cls, events):
|
||||
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
acc = cls.window_basic(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 14 # WindowCovering
|
||||
@@ -359,6 +363,7 @@ async def test_window_open_close_stop(hass, hk_driver, cls, events):
|
||||
)
|
||||
acc = cls.window_basic(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
call_close_cover = async_mock_service(hass, DOMAIN, "close_cover")
|
||||
@@ -407,10 +412,15 @@ async def test_window_open_close_with_position_and_stop(hass, hk_driver, cls, ev
|
||||
)
|
||||
acc = cls.window(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
call_stop_cover = async_mock_service(hass, DOMAIN, "stop_cover")
|
||||
|
||||
await hass.async_add_executor_job(acc.char_hold_position.client_update_value, 0)
|
||||
await hass.async_block_till_done()
|
||||
assert not call_stop_cover
|
||||
|
||||
await hass.async_add_executor_job(acc.char_hold_position.client_update_value, 1)
|
||||
await hass.async_block_till_done()
|
||||
assert call_stop_cover
|
||||
|
||||
@@ -286,6 +286,8 @@ async def test_fan_speed(hass, hk_driver, cls, events):
|
||||
assert acc.char_speed.value != 0
|
||||
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
acc.speed_mapping.speed_ranges == HomeKitSpeedMapping(speed_list).speed_ranges
|
||||
)
|
||||
@@ -351,6 +353,8 @@ async def test_fan_set_all_one_shot(hass, hk_driver, cls, events):
|
||||
# speed to 100 when turning on a fan on a freshly booted up server.
|
||||
assert acc.char_speed.value != 0
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
acc.speed_mapping.speed_ranges == HomeKitSpeedMapping(speed_list).speed_ranges
|
||||
)
|
||||
|
||||
@@ -58,6 +58,7 @@ async def test_media_player_set_state(hass, hk_driver, events):
|
||||
await hass.async_block_till_done()
|
||||
acc = MediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, config)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 8 # Switch
|
||||
@@ -199,6 +200,7 @@ async def test_media_player_television(hass, hk_driver, events, caplog):
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 31 # Television
|
||||
|
||||
@@ -41,6 +41,7 @@ async def test_temperature(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = TemperatureSensor(hass, hk_driver, "Temperature", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -74,6 +75,7 @@ async def test_humidity(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, "Humidity", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -97,6 +99,7 @@ async def test_air_quality(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = AirQualitySensor(hass, hk_driver, "Air Quality", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -128,6 +131,7 @@ async def test_co(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = CarbonMonoxideSensor(hass, hk_driver, "CO", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -167,6 +171,7 @@ async def test_co2(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = CarbonDioxideSensor(hass, hk_driver, "CO2", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -206,6 +211,7 @@ async def test_light(hass, hk_driver):
|
||||
await hass.async_block_till_done()
|
||||
acc = LightSensor(hass, hk_driver, "Light", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -230,6 +236,7 @@ async def test_binary(hass, hk_driver):
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Window Opening", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
@@ -268,6 +275,7 @@ async def test_motion_uses_bool(hass, hk_driver):
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Motion Sensor", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 10 # Sensor
|
||||
|
||||
@@ -561,3 +561,82 @@ async def test_restore_states(hass):
|
||||
assert hass.states.get("light.simple") is None
|
||||
assert hass.states.get("light.disabled") is None
|
||||
assert hass.states.get("light.all_info_set") is None
|
||||
|
||||
|
||||
async def test_async_get_device_class_lookup(hass):
|
||||
"""Test registry device class lookup."""
|
||||
hass.state = CoreState.not_running
|
||||
|
||||
ent_reg = await entity_registry.async_get_registry(hass)
|
||||
|
||||
ent_reg.async_get_or_create(
|
||||
"binary_sensor",
|
||||
"light",
|
||||
"battery_charging",
|
||||
device_id="light_device_entry_id",
|
||||
device_class="battery_charging",
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"sensor",
|
||||
"light",
|
||||
"battery",
|
||||
device_id="light_device_entry_id",
|
||||
device_class="battery",
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"light", "light", "demo", device_id="light_device_entry_id"
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"binary_sensor",
|
||||
"vacuum",
|
||||
"battery_charging",
|
||||
device_id="vacuum_device_entry_id",
|
||||
device_class="battery_charging",
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"sensor",
|
||||
"vacuum",
|
||||
"battery",
|
||||
device_id="vacuum_device_entry_id",
|
||||
device_class="battery",
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"vacuum", "vacuum", "demo", device_id="vacuum_device_entry_id"
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"binary_sensor",
|
||||
"remote",
|
||||
"battery_charging",
|
||||
device_id="remote_device_entry_id",
|
||||
device_class="battery_charging",
|
||||
)
|
||||
ent_reg.async_get_or_create(
|
||||
"remote", "remote", "demo", device_id="remote_device_entry_id"
|
||||
)
|
||||
|
||||
device_lookup = ent_reg.async_get_device_class_lookup(
|
||||
{("binary_sensor", "battery_charging"), ("sensor", "battery")}
|
||||
)
|
||||
|
||||
assert device_lookup == {
|
||||
"remote_device_entry_id": {
|
||||
(
|
||||
"binary_sensor",
|
||||
"battery_charging",
|
||||
): "binary_sensor.remote_battery_charging"
|
||||
},
|
||||
"light_device_entry_id": {
|
||||
(
|
||||
"binary_sensor",
|
||||
"battery_charging",
|
||||
): "binary_sensor.light_battery_charging",
|
||||
("sensor", "battery"): "sensor.light_battery",
|
||||
},
|
||||
"vacuum_device_entry_id": {
|
||||
(
|
||||
"binary_sensor",
|
||||
"battery_charging",
|
||||
): "binary_sensor.vacuum_battery_charging",
|
||||
("sensor", "battery"): "sensor.vacuum_battery",
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user