mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Avoid creating tasks to run homekit accessories (#110895)
This commit is contained in:
parent
4bc28489c5
commit
136a31e4bc
@ -620,9 +620,7 @@ class HomeKit:
|
||||
self._async_shutdown_accessory(acc)
|
||||
if new_acc := self._async_create_single_accessory([state]):
|
||||
self.driver.accessory = new_acc
|
||||
# Run must be awaited here since it may change
|
||||
# the accessories hash
|
||||
await new_acc.run()
|
||||
new_acc.run()
|
||||
self._async_update_accessories_hash()
|
||||
|
||||
def _async_remove_accessories_by_entity_id(
|
||||
@ -675,9 +673,7 @@ class HomeKit:
|
||||
)
|
||||
continue
|
||||
if acc := self.add_bridge_accessory(state):
|
||||
# Run must be awaited here since it may change
|
||||
# the accessories hash
|
||||
await acc.run()
|
||||
acc.run()
|
||||
self._async_update_accessories_hash()
|
||||
|
||||
@callback
|
||||
@ -752,7 +748,7 @@ class HomeKit:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_bridge_triggers_accessory(
|
||||
async def add_bridge_triggers_accessory(
|
||||
self, device: dr.DeviceEntry, device_triggers: list[dict[str, Any]]
|
||||
) -> None:
|
||||
"""Add device automation triggers to the bridge."""
|
||||
@ -767,18 +763,18 @@ class HomeKit:
|
||||
# the rest of the accessories from being created
|
||||
config: dict[str, Any] = {}
|
||||
self._fill_config_from_device_registry_entry(device, config)
|
||||
self.bridge.add_accessory(
|
||||
DeviceTriggerAccessory(
|
||||
self.hass,
|
||||
self.driver,
|
||||
device.name,
|
||||
None,
|
||||
aid,
|
||||
config,
|
||||
device_id=device.id,
|
||||
device_triggers=device_triggers,
|
||||
)
|
||||
trigger_accessory = DeviceTriggerAccessory(
|
||||
self.hass,
|
||||
self.driver,
|
||||
device.name,
|
||||
None,
|
||||
aid,
|
||||
config,
|
||||
device_id=device.id,
|
||||
device_triggers=device_triggers,
|
||||
)
|
||||
await trigger_accessory.async_attach()
|
||||
self.bridge.add_accessory(trigger_accessory)
|
||||
|
||||
@callback
|
||||
def async_remove_bridge_accessory(self, aid: int) -> HomeAccessory | None:
|
||||
@ -1019,7 +1015,7 @@ class HomeKit:
|
||||
)
|
||||
continue
|
||||
valid_device_triggers.append(trigger)
|
||||
self.add_bridge_triggers_accessory(device, valid_device_triggers)
|
||||
await self.add_bridge_triggers_accessory(device, valid_device_triggers)
|
||||
|
||||
async def _async_create_accessories(self) -> bool:
|
||||
"""Create the accessories."""
|
||||
|
@ -426,7 +426,9 @@ class HomeAccessory(Accessory): # type: ignore[misc]
|
||||
"""Return if accessory is available."""
|
||||
return self._available
|
||||
|
||||
async def run(self) -> None:
|
||||
@ha_callback
|
||||
@pyhap_callback # type: ignore[misc]
|
||||
def run(self) -> None:
|
||||
"""Handle accessory driver started event."""
|
||||
if state := self.hass.states.get(self.entity_id):
|
||||
self.async_update_state_callback(state)
|
||||
|
@ -11,6 +11,7 @@ from pyhap.camera import (
|
||||
Camera as PyhapCamera,
|
||||
)
|
||||
from pyhap.const import CATEGORY_CAMERA
|
||||
from pyhap.util import callback as pyhap_callback
|
||||
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.ffmpeg import get_ffmpeg_manager
|
||||
@ -251,7 +252,9 @@ class Camera(HomeAccessory, PyhapCamera): # type: ignore[misc]
|
||||
|
||||
self._async_update_doorbell_state(state)
|
||||
|
||||
async def run(self) -> None:
|
||||
@pyhap_callback # type: ignore[misc]
|
||||
@callback
|
||||
def run(self) -> None:
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
@ -276,7 +279,7 @@ class Camera(HomeAccessory, PyhapCamera): # type: ignore[misc]
|
||||
)
|
||||
)
|
||||
|
||||
await super().run()
|
||||
super().run()
|
||||
|
||||
@callback
|
||||
def _async_update_motion_state_event(
|
||||
|
@ -9,6 +9,7 @@ from pyhap.const import (
|
||||
CATEGORY_WINDOW_COVERING,
|
||||
)
|
||||
from pyhap.service import Service
|
||||
from pyhap.util import callback as pyhap_callback
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
@ -125,7 +126,9 @@ class GarageDoorOpener(HomeAccessory):
|
||||
|
||||
self.async_update_state(state)
|
||||
|
||||
async def run(self) -> None:
|
||||
@callback
|
||||
@pyhap_callback # type: ignore[misc]
|
||||
def run(self) -> None:
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
@ -139,7 +142,7 @@ class GarageDoorOpener(HomeAccessory):
|
||||
)
|
||||
)
|
||||
|
||||
await super().run()
|
||||
super().run()
|
||||
|
||||
@callback
|
||||
def _async_update_obstruction_event(
|
||||
|
@ -3,6 +3,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from pyhap.const import CATEGORY_HUMIDIFIER
|
||||
from pyhap.util import callback as pyhap_callback
|
||||
|
||||
from homeassistant.components.humidifier import (
|
||||
ATTR_CURRENT_HUMIDITY,
|
||||
@ -173,7 +174,9 @@ class HumidifierDehumidifier(HomeAccessory):
|
||||
if humidity_state := states.get(self.linked_humidity_sensor):
|
||||
self._async_update_current_humidity(humidity_state)
|
||||
|
||||
async def run(self) -> None:
|
||||
@callback
|
||||
@pyhap_callback # type: ignore[misc]
|
||||
def run(self) -> None:
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
@ -187,7 +190,7 @@ class HumidifierDehumidifier(HomeAccessory):
|
||||
)
|
||||
)
|
||||
|
||||
await super().run()
|
||||
super().run()
|
||||
|
||||
@callback
|
||||
def async_update_current_humidity_event(
|
||||
|
@ -5,6 +5,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from pyhap.const import CATEGORY_SENSOR
|
||||
from pyhap.util import callback as pyhap_callback
|
||||
|
||||
from homeassistant.core import CALLBACK_TYPE, Context, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -84,6 +85,30 @@ class DeviceTriggerAccessory(HomeAccessory):
|
||||
serv_service_label.configure_char(CHAR_SERVICE_LABEL_NAMESPACE, value=1)
|
||||
serv_stateless_switch.add_linked_service(serv_service_label)
|
||||
|
||||
@callback
|
||||
def _remove_triggers_if_configured(self) -> None:
|
||||
if self._remove_triggers:
|
||||
self._remove_triggers()
|
||||
self._remove_triggers = None
|
||||
|
||||
async def async_attach(self) -> None:
|
||||
"""Start the accessory."""
|
||||
self._remove_triggers_if_configured()
|
||||
self._remove_triggers = await async_initialize_triggers(
|
||||
self.hass,
|
||||
self._device_triggers,
|
||||
self.async_trigger,
|
||||
"homekit",
|
||||
self.display_name,
|
||||
_LOGGER.log,
|
||||
)
|
||||
|
||||
@pyhap_callback # type: ignore[misc]
|
||||
@callback
|
||||
def run(self) -> None:
|
||||
"""Run the accessory."""
|
||||
# Triggers have not entities so we do not call super().run()
|
||||
|
||||
async def async_trigger(
|
||||
self,
|
||||
run_variables: dict[str, Any],
|
||||
@ -101,24 +126,10 @@ class DeviceTriggerAccessory(HomeAccessory):
|
||||
idx = int(run_variables["trigger"]["idx"])
|
||||
self.triggers[idx].set_value(0)
|
||||
|
||||
# Attach the trigger using the helper in async run
|
||||
# and detach it in async stop
|
||||
async def run(self) -> None:
|
||||
"""Handle accessory driver started event."""
|
||||
self._remove_triggers = await async_initialize_triggers(
|
||||
self.hass,
|
||||
self._device_triggers,
|
||||
self.async_trigger,
|
||||
"homekit",
|
||||
self.display_name,
|
||||
_LOGGER.log,
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_stop(self) -> None:
|
||||
"""Handle accessory driver stop event."""
|
||||
if self._remove_triggers:
|
||||
self._remove_triggers()
|
||||
self._remove_triggers_if_configured()
|
||||
super().async_stop()
|
||||
|
||||
@property
|
||||
|
@ -63,7 +63,7 @@ async def test_accessory_cancels_track_state_change_on_stop(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run()
|
||||
acc.run()
|
||||
assert len(hass.data[TRACK_STATE_CHANGE_CALLBACKS][entity_id]) == 1
|
||||
await acc.stop()
|
||||
assert entity_id not in hass.data[TRACK_STATE_CHANGE_CALLBACKS]
|
||||
@ -178,7 +178,7 @@ async def test_home_accessory(hass: HomeAssistant, hk_driver) -> None:
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -276,7 +276,7 @@ async def test_battery_service(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -332,7 +332,7 @@ async def test_battery_service(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -375,7 +375,7 @@ async def test_linked_battery_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -420,7 +420,7 @@ async def test_linked_battery_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -464,7 +464,7 @@ async def test_linked_battery_charging_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -476,7 +476,7 @@ async def test_linked_battery_charging_sensor(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_OFF, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -486,7 +486,7 @@ async def test_linked_battery_charging_sensor(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_set(linked_battery_charging_sensor, STATE_ON, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -496,7 +496,7 @@ async def test_linked_battery_charging_sensor(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_remove(linked_battery_charging_sensor)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_charging.value == 1
|
||||
|
||||
@ -529,7 +529,7 @@ async def test_linked_battery_sensor_and_linked_battery_charging_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -575,7 +575,7 @@ async def test_missing_linked_battery_charging_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Make sure we don't throw if the entity_id
|
||||
@ -584,7 +584,7 @@ async def test_missing_linked_battery_charging_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@ -610,7 +610,7 @@ async def test_missing_linked_battery_sensor(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
@ -624,7 +624,7 @@ async def test_missing_linked_battery_sensor(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_remove(entity_id)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not acc.linked_battery_sensor
|
||||
@ -647,7 +647,7 @@ async def test_battery_appears_after_startup(
|
||||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -982,7 +982,7 @@ async def test_homekit_reload_accessory_in_accessory_mode(
|
||||
with patch(f"{PATH_HOMEKIT}.HomeKit", return_value=homekit):
|
||||
await async_init_entry(hass, entry)
|
||||
primary_accessory = homekit.driver.accessory
|
||||
await primary_accessory.run()
|
||||
primary_accessory.run()
|
||||
assert type(primary_accessory).__name__ == "Switch"
|
||||
await hass.async_block_till_done()
|
||||
assert homekit.status == STATUS_RUNNING
|
||||
|
@ -53,35 +53,35 @@ async def _async_start_streaming(hass, acc):
|
||||
"""Start streaming a camera."""
|
||||
acc.set_selected_stream_configuration(MOCK_START_STREAM_TLV)
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _async_setup_endpoints(hass, acc):
|
||||
"""Set camera endpoints."""
|
||||
acc.set_endpoints(MOCK_END_POINTS_TLV)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _async_reconfigure_stream(hass, acc, session_info, stream_config):
|
||||
"""Reconfigure the stream."""
|
||||
await acc.reconfigure_stream(session_info, stream_config)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _async_stop_all_streams(hass, acc):
|
||||
"""Stop all camera streams."""
|
||||
await acc.stop()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def _async_stop_stream(hass, acc, session_info):
|
||||
"""Stop a camera stream."""
|
||||
await acc.stop_stream(session_info)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ async def test_camera_stream_source_configured(
|
||||
bridge.add_accessory(acc)
|
||||
bridge.add_accessory(not_camera_acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -278,7 +278,7 @@ async def test_camera_stream_source_configured_with_failing_ffmpeg(
|
||||
bridge.add_accessory(acc)
|
||||
bridge.add_accessory(not_camera_acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -320,7 +320,7 @@ async def test_camera_stream_source_found(
|
||||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -402,7 +402,7 @@ async def test_camera_stream_source_fails(
|
||||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -437,7 +437,7 @@ async def test_camera_with_no_stream(hass: HomeAssistant, run_driver, events) ->
|
||||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -482,7 +482,7 @@ async def test_camera_stream_source_configured_and_copy_codec(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -555,7 +555,7 @@ async def test_camera_stream_source_configured_and_override_profile_names(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -627,7 +627,7 @@ async def test_camera_streaming_fails_after_starting_ffmpeg(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -707,7 +707,7 @@ async def test_camera_with_linked_motion_sensor(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -760,7 +760,7 @@ async def test_camera_with_linked_motion_sensor(
|
||||
# motion sensor is removed
|
||||
hass.states.async_remove(motion_entity_id)
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert char.value is True
|
||||
|
||||
@ -789,7 +789,7 @@ async def test_camera_with_a_missing_linked_motion_sensor(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -835,7 +835,7 @@ async def test_camera_with_linked_doorbell_sensor(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
@ -907,7 +907,7 @@ async def test_camera_with_linked_doorbell_sensor(
|
||||
# doorbell sensor is removed
|
||||
hass.states.async_remove(doorbell_entity_id)
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert char.value is None
|
||||
assert char2.value is None
|
||||
@ -937,7 +937,7 @@ async def test_camera_with_a_missing_linked_doorbell_sensor(
|
||||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -52,7 +52,7 @@ async def test_garage_door_open_close(hass: HomeAssistant, hk_driver, events) ->
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = GarageDoorOpener(hass, hk_driver, "Garage Door", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -147,7 +147,7 @@ async def test_door_instantiate_set_position(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = Door(hass, hk_driver, "Door", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -196,7 +196,7 @@ async def test_windowcovering_set_cover_position(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -310,7 +310,7 @@ async def test_window_instantiate_set_position(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = Window(hass, hk_driver, "Window", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -359,7 +359,7 @@ async def test_windowcovering_cover_set_tilt(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -428,7 +428,7 @@ async def test_windowcovering_tilt_only(hass: HomeAssistant, hk_driver, events)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -448,7 +448,7 @@ async def test_windowcovering_open_close(
|
||||
|
||||
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: 0})
|
||||
acc = WindowCoveringBasic(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -533,7 +533,7 @@ async def test_windowcovering_open_close_stop(
|
||||
entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: CoverEntityFeature.STOP}
|
||||
)
|
||||
acc = WindowCoveringBasic(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
@ -587,7 +587,7 @@ async def test_windowcovering_open_close_with_position_and_stop(
|
||||
},
|
||||
)
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
@ -700,7 +700,7 @@ async def test_garage_door_with_linked_obstruction_sensor(
|
||||
2,
|
||||
{CONF_LINKED_OBSTRUCTION_SENSOR: linked_obstruction_sensor_entity_id},
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -45,7 +45,7 @@ async def test_fan_basic(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
# If there are no speed_list values, then HomeKit speed is unsupported
|
||||
assert acc.char_speed is None
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_active.value == 1
|
||||
|
||||
@ -125,7 +125,7 @@ async def test_fan_direction(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
|
||||
assert acc.char_direction.value == 0
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_direction.value == 0
|
||||
|
||||
@ -200,7 +200,7 @@ async def test_fan_oscillate(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
|
||||
assert acc.char_swing.value == 0
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_swing.value == 0
|
||||
|
||||
@ -280,7 +280,7 @@ async def test_fan_speed(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
assert acc.char_speed.value != 0
|
||||
assert acc.char_speed.properties[PROP_MIN_STEP] == 25
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
@ -383,7 +383,7 @@ async def test_fan_set_all_one_shot(hass: HomeAssistant, hk_driver, events) -> N
|
||||
# Initial value can be anything but 0. If it is 0, it might cause HomeKit to set the
|
||||
# speed to 100 when turning on a fan on a freshly booted up server.
|
||||
assert acc.char_speed.value != 0
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
@ -617,7 +617,7 @@ async def test_fan_multiple_preset_modes(
|
||||
assert acc.preset_mode_chars["auto"].value == 1
|
||||
assert acc.preset_mode_chars["smart"].value == 0
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
@ -698,7 +698,7 @@ async def test_fan_single_preset_mode(hass: HomeAssistant, hk_driver, events) ->
|
||||
|
||||
assert acc.char_target_fan_state.value == 1
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
|
@ -59,7 +59,7 @@ async def test_humidifier(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
@ -144,7 +144,7 @@ async def test_dehumidifier(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
@ -234,7 +234,7 @@ async def test_hygrostat_power_state(hass: HomeAssistant, hk_driver, events) ->
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidifier_dehumidifier.value == 2
|
||||
@ -314,7 +314,7 @@ async def test_hygrostat_get_humidity_range(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
@ -390,7 +390,7 @@ async def test_humidifier_with_linked_humidity_sensor(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 42.0
|
||||
@ -444,7 +444,7 @@ async def test_humidifier_with_a_missing_linked_humidity_sensor(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 0
|
||||
@ -465,7 +465,7 @@ async def test_humidifier_as_dehumidifier(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidifier_dehumidifier.value == 1
|
||||
@ -508,7 +508,7 @@ async def test_dehumidifier_as_humidifier(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidifier_dehumidifier.value == 2
|
||||
@ -553,7 +553,7 @@ async def test_humidifier_that_reports_current_humidity(
|
||||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 42.0
|
||||
|
@ -65,7 +65,7 @@ async def test_light_basic(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
assert acc.category == 5 # Lightbulb
|
||||
assert acc.char_on.value
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_on.value == 1
|
||||
|
||||
@ -146,7 +146,7 @@ async def test_light_brightness(
|
||||
char_on_iid = acc.char_on.to_HAP()[HAP_REPR_IID]
|
||||
char_brightness_iid = acc.char_brightness.to_HAP()[HAP_REPR_IID]
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
@ -288,7 +288,7 @@ async def test_light_color_temperature(hass: HomeAssistant, hk_driver, events) -
|
||||
|
||||
assert acc.char_color_temp.value == 190
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_color_temp.value == 190
|
||||
|
||||
@ -348,7 +348,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 4464})
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_color_temp.value == 224
|
||||
assert acc.char_hue.value == 27
|
||||
@ -356,7 +356,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP_KELVIN: 2840})
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_color_temp.value == 352
|
||||
assert acc.char_hue.value == 28
|
||||
@ -512,7 +512,7 @@ async def test_light_color_temperature_and_rgb_color(
|
||||
# Set from HASS
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_HS_COLOR: (100, 100)})
|
||||
await hass.async_block_till_done()
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_color_temp.value == 404
|
||||
assert acc.char_hue.value == 100
|
||||
@ -540,7 +540,7 @@ async def test_light_rgb_color(
|
||||
assert acc.char_hue.value == 260
|
||||
assert acc.char_saturation.value == 90
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 260
|
||||
assert acc.char_saturation.value == 90
|
||||
@ -661,7 +661,7 @@ async def test_light_rgb_with_color_temp(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -781,7 +781,7 @@ async def test_light_rgbwx_with_color_temp_and_brightness(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -847,7 +847,7 @@ async def test_light_rgb_or_w_lights(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -975,7 +975,7 @@ async def test_light_rgb_with_white_switch_to_temp(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -1060,7 +1060,7 @@ async def test_light_rgb_with_hs_color_none(
|
||||
assert acc.char_hue.value == 0
|
||||
assert acc.char_saturation.value == 75
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 0
|
||||
assert acc.char_saturation.value == 75
|
||||
@ -1094,7 +1094,7 @@ async def test_light_rgbww_with_color_temp_conversion(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -1215,7 +1215,7 @@ async def test_light_rgbw_with_color_temp_conversion(
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 23
|
||||
assert acc.char_saturation.value == 100
|
||||
@ -1304,7 +1304,7 @@ async def test_light_set_brightness_and_color(
|
||||
char_hue_iid = acc.char_hue.to_HAP()[HAP_REPR_IID]
|
||||
char_saturation_iid = acc.char_saturation.to_HAP()[HAP_REPR_IID]
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
@ -1409,7 +1409,7 @@ async def test_light_set_brightness_and_color_temp(
|
||||
char_brightness_iid = acc.char_brightness.to_HAP()[HAP_REPR_IID]
|
||||
char_color_temp_iid = acc.char_color_temp.to_HAP()[HAP_REPR_IID]
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
|
@ -31,7 +31,7 @@ async def test_lock_unlock(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Lock(hass, hk_driver, "Lock", entity_id, 2, config)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 6 # DoorLock
|
||||
|
@ -65,7 +65,7 @@ async def test_media_player_set_state(hass: HomeAssistant, hk_driver, events) ->
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = MediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, config)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -196,7 +196,7 @@ async def test_media_player_television(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -382,7 +382,7 @@ async def test_media_player_television_basic(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.chars_tv == [CHAR_REMOTE_KEY]
|
||||
@ -422,7 +422,7 @@ async def test_media_player_television_supports_source_select_no_sources(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.support_select_source is False
|
||||
@ -500,7 +500,7 @@ async def test_media_player_television_max_sources(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -559,7 +559,7 @@ async def test_media_player_television_duplicate_sources(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -604,7 +604,7 @@ async def test_media_player_television_unsafe_chars(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = TelevisionMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -671,7 +671,7 @@ async def test_media_player_receiver(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = ReceiverMediaPlayer(hass, hk_driver, "MediaPlayer", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -47,7 +47,7 @@ async def test_activity_remote(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = ActivityRemote(hass, hk_driver, "ActivityRemote", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -171,7 +171,7 @@ async def test_activity_remote_bad_names(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = ActivityRemote(hass, hk_driver, "ActivityRemote", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -34,7 +34,7 @@ async def test_switch_set_state(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = SecuritySystem(hass, hk_driver, "SecuritySystem", entity_id, 2, config)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -145,7 +145,7 @@ async def test_arming(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
|
||||
acc = SecuritySystem(hass, hk_driver, "SecuritySystem", entity_id, 2, {})
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ALARM_ARMED_AWAY)
|
||||
@ -293,7 +293,7 @@ async def test_supported_states(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
|
||||
aid += 1
|
||||
acc = SecuritySystem(hass, hk_driver, "SecuritySystem", entity_id, aid, config)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
valid_current_values = acc.char_current_state.properties.get("ValidValues")
|
||||
|
@ -45,7 +45,7 @@ async def test_temperature(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = TemperatureSensor(hass, hk_driver, "Temperature", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -89,7 +89,7 @@ async def test_humidity(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, "Humidity", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -117,7 +117,7 @@ async def test_air_quality(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = AirQualitySensor(hass, hk_driver, "Air Quality", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -149,7 +149,7 @@ async def test_pm10(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = PM10Sensor(hass, hk_driver, "PM10 Sensor", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -196,7 +196,7 @@ async def test_pm25(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = PM25Sensor(hass, hk_driver, "PM25 Sensor", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -245,7 +245,7 @@ async def test_no2(hass: HomeAssistant, hk_driver) -> None:
|
||||
acc = NitrogenDioxideSensor(
|
||||
hass, hk_driver, "Nitrogen Dioxide Sensor", entity_id, 2, None
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -294,7 +294,7 @@ async def test_voc(hass: HomeAssistant, hk_driver) -> None:
|
||||
acc = VolatileOrganicCompoundsSensor(
|
||||
hass, hk_driver, "Volatile Organic Compounds Sensor", entity_id, 2, None
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -341,7 +341,7 @@ async def test_co(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = CarbonMonoxideSensor(hass, hk_driver, "CO", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -381,7 +381,7 @@ async def test_co2(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = CarbonDioxideSensor(hass, hk_driver, "CO2", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -421,7 +421,7 @@ async def test_light(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = LightSensor(hass, hk_driver, "Light", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -450,7 +450,7 @@ async def test_binary(hass: HomeAssistant, hk_driver) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Window Opening", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -489,7 +489,7 @@ async def test_motion_uses_bool(hass: HomeAssistant, hk_driver) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Motion Sensor", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -579,7 +579,7 @@ async def test_bad_name(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, "20")
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, "[[Humid]]", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -596,7 +596,7 @@ async def test_empty_name(hass: HomeAssistant, hk_driver) -> None:
|
||||
hass.states.async_set(entity_id, "20")
|
||||
await hass.async_block_till_done()
|
||||
acc = HumiditySensor(hass, hk_driver, None, entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -49,7 +49,7 @@ async def test_outlet_set_state(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Outlet(hass, hk_driver, "Outlet", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -103,7 +103,7 @@ async def test_switch_set_state(
|
||||
hass.states.async_set(entity_id, None, attrs)
|
||||
await hass.async_block_till_done()
|
||||
acc = Switch(hass, hk_driver, "Switch", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -147,25 +147,25 @@ async def test_valve_set_state(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = Valve(hass, hk_driver, "Valve", entity_id, 2, {CONF_TYPE: TYPE_FAUCET})
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 29 # Faucet
|
||||
assert acc.char_valve_type.value == 3 # Water faucet
|
||||
|
||||
acc = Valve(hass, hk_driver, "Valve", entity_id, 3, {CONF_TYPE: TYPE_SHOWER})
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 30 # Shower
|
||||
assert acc.char_valve_type.value == 2 # Shower head
|
||||
|
||||
acc = Valve(hass, hk_driver, "Valve", entity_id, 4, {CONF_TYPE: TYPE_SPRINKLER})
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 28 # Sprinkler
|
||||
assert acc.char_valve_type.value == 1 # Irrigation
|
||||
|
||||
acc = Valve(hass, hk_driver, "Valve", entity_id, 5, {CONF_TYPE: TYPE_VALVE})
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 5
|
||||
@ -223,7 +223,7 @@ async def test_vacuum_set_state_with_returnhome_and_start_support(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = Vacuum(hass, hk_driver, "Vacuum", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 8 # Switch
|
||||
@ -285,7 +285,7 @@ async def test_vacuum_set_state_without_returnhome_and_start_support(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = Vacuum(hass, hk_driver, "Vacuum", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 8 # Switch
|
||||
@ -329,7 +329,7 @@ async def test_reset_switch(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Switch(hass, hk_driver, "Switch", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.activate_only is True
|
||||
@ -373,7 +373,7 @@ async def test_script_switch(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Switch(hass, hk_driver, "Switch", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.activate_only is True
|
||||
@ -424,7 +424,7 @@ async def test_input_select_switch(
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = SelectSwitch(hass, hk_driver, "SelectSwitch", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.select_chars["option1"].value is True
|
||||
@ -476,7 +476,7 @@ async def test_button_switch(hass: HomeAssistant, hk_driver, events, domain) ->
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Switch(hass, hk_driver, "Switch", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.activate_only is True
|
||||
|
@ -103,7 +103,7 @@ async def test_thermostat(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
@ -399,7 +399,7 @@ async def test_thermostat_auto(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -534,7 +534,7 @@ async def test_thermostat_mode_and_temp_change(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -625,7 +625,7 @@ async def test_thermostat_humidity(hass: HomeAssistant, hk_driver, events) -> No
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidity.value == 50
|
||||
@ -694,7 +694,7 @@ async def test_thermostat_humidity_with_target_humidity(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 40
|
||||
@ -729,7 +729,7 @@ async def test_thermostat_power_state(hass: HomeAssistant, hk_driver, events) ->
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_heat_cool.value == 1
|
||||
@ -830,7 +830,7 @@ async def test_thermostat_fahrenheit(hass: HomeAssistant, hk_driver, events) ->
|
||||
):
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
@ -961,7 +961,7 @@ async def test_thermostat_temperature_step_whole(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_temp.properties[PROP_MIN_STEP] == 0.1
|
||||
@ -1033,7 +1033,7 @@ async def test_thermostat_hvac_modes(hass: HomeAssistant, hk_driver) -> None:
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1]
|
||||
@ -1078,7 +1078,7 @@ async def test_thermostat_hvac_modes_with_auto_heat_cool(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1, 3]
|
||||
@ -1136,7 +1136,7 @@ async def test_thermostat_hvac_modes_with_auto_no_heat_cool(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1, 3]
|
||||
@ -1192,7 +1192,7 @@ async def test_thermostat_hvac_modes_with_auto_only(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 3]
|
||||
@ -1248,7 +1248,7 @@ async def test_thermostat_hvac_modes_with_heat_only(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [HC_HEAT_COOL_OFF, HC_HEAT_COOL_HEAT]
|
||||
@ -1328,7 +1328,7 @@ async def test_thermostat_hvac_modes_with_cool_only(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [HC_HEAT_COOL_OFF, HC_HEAT_COOL_COOL]
|
||||
@ -1388,7 +1388,7 @@ async def test_thermostat_hvac_modes_with_heat_cool_only(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [
|
||||
@ -1473,7 +1473,7 @@ async def test_thermostat_hvac_modes_without_off(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [1, 3]
|
||||
@ -1517,7 +1517,7 @@ async def test_thermostat_without_target_temp_only_range(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -1668,7 +1668,7 @@ async def test_water_heater(hass: HomeAssistant, hk_driver, events) -> None:
|
||||
hass.states.async_set(entity_id, HVACMode.HEAT)
|
||||
await hass.async_block_till_done()
|
||||
acc = WaterHeater(hass, hk_driver, "WaterHeater", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
@ -1745,7 +1745,7 @@ async def test_water_heater_fahrenheit(hass: HomeAssistant, hk_driver, events) -
|
||||
hass.config.units, CONF_TEMPERATURE_UNIT, new=UnitOfTemperature.FAHRENHEIT
|
||||
):
|
||||
acc = WaterHeater(hass, hk_driver, "WaterHeater", entity_id, 2, None)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(entity_id, HVACMode.HEAT, {ATTR_TEMPERATURE: 131})
|
||||
@ -1868,7 +1868,7 @@ async def test_thermostat_with_no_modes_when_we_first_see(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -1922,7 +1922,7 @@ async def test_thermostat_with_no_off_after_recheck(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -1976,7 +1976,7 @@ async def test_thermostat_with_temp_clamps(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 100
|
||||
@ -2043,7 +2043,7 @@ async def test_thermostat_with_fan_modes_with_auto(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -2249,7 +2249,7 @@ async def test_thermostat_with_fan_modes_with_off(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -2358,7 +2358,7 @@ async def test_thermostat_with_fan_modes_set_to_none(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -2401,7 +2401,7 @@ async def test_thermostat_with_fan_modes_set_to_none_not_supported(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
@ -2444,7 +2444,7 @@ async def test_thermostat_with_supported_features_target_temp_but_fan_mode_set(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.ordered_fan_speeds == []
|
||||
@ -2485,7 +2485,7 @@ async def test_thermostat_handles_unknown_state(
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await hass.async_block_till_done()
|
||||
heat_cool_char: Characteristic = acc.char_target_heat_cool
|
||||
|
||||
|
@ -48,7 +48,8 @@ async def test_programmable_switch_button_fires_on_trigger(
|
||||
device_id=device_id,
|
||||
device_triggers=device_triggers,
|
||||
)
|
||||
await acc.run()
|
||||
acc.run()
|
||||
await acc.async_attach()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.entity_id is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user