Run homekit service calls in async since the server is now async (#45859)
* Simplify homekit runs and service calls Now that the homekit server is async, call_service and run are running in the Home Assistant event loop * remove comment * remove another comment
This commit is contained in:
parent
41332493b5
commit
b775a0d796
23 changed files with 157 additions and 167 deletions
|
@ -300,17 +300,7 @@ class HomeAccessory(Accessory):
|
|||
return state is not None and state.state != STATE_UNAVAILABLE
|
||||
|
||||
async def run(self):
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the HAP-python event loop.
|
||||
"""
|
||||
self.hass.add_job(self.run_handler)
|
||||
|
||||
async def run_handler(self):
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
"""
|
||||
"""Handle accessory driver started event."""
|
||||
state = self.hass.states.get(self.entity_id)
|
||||
self.async_update_state_callback(state)
|
||||
self._subscriptions.append(
|
||||
|
@ -441,15 +431,9 @@ class HomeAccessory(Accessory):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def call_service(self, domain, service, service_data, value=None):
|
||||
@ha_callback
|
||||
def async_call_service(self, domain, service, service_data, value=None):
|
||||
"""Fire event and call service for changes from HomeKit."""
|
||||
self.hass.add_job(self.async_call_service, domain, service, service_data, value)
|
||||
|
||||
async def async_call_service(self, domain, service, service_data, value=None):
|
||||
"""Fire event and call service for changes from HomeKit.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
event_data = {
|
||||
ATTR_ENTITY_ID: self.entity_id,
|
||||
ATTR_DISPLAY_NAME: self.display_name,
|
||||
|
@ -459,8 +443,10 @@ class HomeAccessory(Accessory):
|
|||
context = Context()
|
||||
|
||||
self.hass.bus.async_fire(EVENT_HOMEKIT_CHANGED, event_data, context=context)
|
||||
await self.hass.services.async_call(
|
||||
domain, service, service_data, context=context
|
||||
self.hass.async_create_task(
|
||||
self.hass.services.async_call(
|
||||
domain, service, service_data, context=context
|
||||
)
|
||||
)
|
||||
|
||||
@ha_callback
|
||||
|
|
|
@ -240,7 +240,7 @@ class Camera(HomeAccessory, PyhapCamera):
|
|||
|
||||
self._async_update_doorbell_state(state)
|
||||
|
||||
async def run_handler(self):
|
||||
async def run(self):
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
|
@ -259,7 +259,7 @@ class Camera(HomeAccessory, PyhapCamera):
|
|||
self._async_update_doorbell_state_event,
|
||||
)
|
||||
|
||||
await super().run_handler()
|
||||
await super().run()
|
||||
|
||||
@callback
|
||||
def _async_update_motion_state_event(self, event):
|
||||
|
|
|
@ -113,7 +113,7 @@ class GarageDoorOpener(HomeAccessory):
|
|||
|
||||
self.async_update_state(state)
|
||||
|
||||
async def run_handler(self):
|
||||
async def run(self):
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
|
@ -125,7 +125,7 @@ class GarageDoorOpener(HomeAccessory):
|
|||
self._async_update_obstruction_event,
|
||||
)
|
||||
|
||||
await super().run_handler()
|
||||
await super().run()
|
||||
|
||||
@callback
|
||||
def _async_update_obstruction_event(self, event):
|
||||
|
@ -158,11 +158,11 @@ class GarageDoorOpener(HomeAccessory):
|
|||
if value == HK_DOOR_OPEN:
|
||||
if self.char_current_state.value != value:
|
||||
self.char_current_state.set_value(HK_DOOR_OPENING)
|
||||
self.call_service(DOMAIN, SERVICE_OPEN_COVER, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_OPEN_COVER, params)
|
||||
elif value == HK_DOOR_CLOSED:
|
||||
if self.char_current_state.value != value:
|
||||
self.char_current_state.set_value(HK_DOOR_CLOSING)
|
||||
self.call_service(DOMAIN, SERVICE_CLOSE_COVER, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_CLOSE_COVER, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -231,7 +231,9 @@ class OpeningDeviceBase(HomeAccessory):
|
|||
"""Stop the cover motion from HomeKit."""
|
||||
if value != 1:
|
||||
return
|
||||
self.call_service(DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: self.entity_id})
|
||||
self.async_call_service(
|
||||
DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: self.entity_id}
|
||||
)
|
||||
|
||||
def set_tilt(self, value):
|
||||
"""Set tilt to value if call came from HomeKit."""
|
||||
|
@ -243,7 +245,7 @@ class OpeningDeviceBase(HomeAccessory):
|
|||
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_TILT_POSITION: value}
|
||||
|
||||
self.call_service(DOMAIN, SERVICE_SET_COVER_TILT_POSITION, params, value)
|
||||
self.async_call_service(DOMAIN, SERVICE_SET_COVER_TILT_POSITION, params, value)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -287,7 +289,7 @@ class OpeningDevice(OpeningDeviceBase, HomeAccessory):
|
|||
"""Move cover to value if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set position to %d", self.entity_id, value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_POSITION: value}
|
||||
self.call_service(DOMAIN, SERVICE_SET_COVER_POSITION, params, value)
|
||||
self.async_call_service(DOMAIN, SERVICE_SET_COVER_POSITION, params, value)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -376,7 +378,7 @@ class WindowCoveringBasic(OpeningDeviceBase, HomeAccessory):
|
|||
service, position = (SERVICE_CLOSE_COVER, 0)
|
||||
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
# Snap the current/target position to the expected final position.
|
||||
self.char_current_position.set_value(position)
|
||||
|
|
|
@ -125,27 +125,27 @@ class Fan(HomeAccessory):
|
|||
_LOGGER.debug("%s: Set state to %d", self.entity_id, value)
|
||||
service = SERVICE_TURN_ON if value == 1 else SERVICE_TURN_OFF
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_direction(self, value):
|
||||
"""Set state if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set direction to %d", self.entity_id, value)
|
||||
direction = DIRECTION_REVERSE if value == 1 else DIRECTION_FORWARD
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_DIRECTION: direction}
|
||||
self.call_service(DOMAIN, SERVICE_SET_DIRECTION, params, direction)
|
||||
self.async_call_service(DOMAIN, SERVICE_SET_DIRECTION, params, direction)
|
||||
|
||||
def set_oscillating(self, value):
|
||||
"""Set state if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set oscillating to %d", self.entity_id, value)
|
||||
oscillating = value == 1
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_OSCILLATING: oscillating}
|
||||
self.call_service(DOMAIN, SERVICE_OSCILLATE, params, oscillating)
|
||||
self.async_call_service(DOMAIN, SERVICE_OSCILLATE, params, oscillating)
|
||||
|
||||
def set_percentage(self, value):
|
||||
"""Set state if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set speed to %d", self.entity_id, value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_PERCENTAGE: value}
|
||||
self.call_service(DOMAIN, SERVICE_SET_PERCENTAGE, params, value)
|
||||
self.async_call_service(DOMAIN, SERVICE_SET_PERCENTAGE, params, value)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
|
|
@ -143,7 +143,7 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||
if humidity_state:
|
||||
self._async_update_current_humidity(humidity_state)
|
||||
|
||||
async def run_handler(self):
|
||||
async def run(self):
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
|
@ -155,7 +155,7 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||
self.async_update_current_humidity_event,
|
||||
)
|
||||
|
||||
await super().run_handler()
|
||||
await super().run()
|
||||
|
||||
@callback
|
||||
def async_update_current_humidity_event(self, event):
|
||||
|
@ -201,7 +201,7 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||
)
|
||||
|
||||
if CHAR_ACTIVE in char_values:
|
||||
self.call_service(
|
||||
self.async_call_service(
|
||||
DOMAIN,
|
||||
SERVICE_TURN_ON if char_values[CHAR_ACTIVE] else SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: self.entity_id},
|
||||
|
@ -210,7 +210,7 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||
|
||||
if self._target_humidity_char_name in char_values:
|
||||
humidity = round(char_values[self._target_humidity_char_name])
|
||||
self.call_service(
|
||||
self.async_call_service(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: humidity},
|
||||
|
|
|
@ -139,7 +139,7 @@ class Light(HomeAccessory):
|
|||
params[ATTR_HS_COLOR] = color
|
||||
events.append(f"set color at {color}")
|
||||
|
||||
self.call_service(DOMAIN, service, params, ", ".join(events))
|
||||
self.async_call_service(DOMAIN, service, params, ", ".join(events))
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
|
|
@ -61,7 +61,7 @@ class Lock(HomeAccessory):
|
|||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
if self._code:
|
||||
params[ATTR_CODE] = self._code
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
|
|
@ -177,7 +177,7 @@ class MediaPlayer(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set switch state for "on_off" to %s', self.entity_id, value)
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_play_pause(self, value):
|
||||
"""Move switch state to value if call came from HomeKit."""
|
||||
|
@ -186,7 +186,7 @@ class MediaPlayer(HomeAccessory):
|
|||
)
|
||||
service = SERVICE_MEDIA_PLAY if value else SERVICE_MEDIA_PAUSE
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_play_stop(self, value):
|
||||
"""Move switch state to value if call came from HomeKit."""
|
||||
|
@ -195,7 +195,7 @@ class MediaPlayer(HomeAccessory):
|
|||
)
|
||||
service = SERVICE_MEDIA_PLAY if value else SERVICE_MEDIA_STOP
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_toggle_mute(self, value):
|
||||
"""Move switch state to value if call came from HomeKit."""
|
||||
|
@ -203,7 +203,7 @@ class MediaPlayer(HomeAccessory):
|
|||
'%s: Set switch state for "toggle_mute" to %s', self.entity_id, value
|
||||
)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_MUTED: value}
|
||||
self.call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -344,7 +344,7 @@ class TelevisionMediaPlayer(HomeAccessory):
|
|||
_LOGGER.debug('%s: Set switch state for "on_off" to %s', self.entity_id, value)
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_mute(self, value):
|
||||
"""Move switch state to value if call came from HomeKit."""
|
||||
|
@ -352,27 +352,27 @@ class TelevisionMediaPlayer(HomeAccessory):
|
|||
'%s: Set switch state for "toggle_mute" to %s', self.entity_id, value
|
||||
)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_MUTED: value}
|
||||
self.call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_VOLUME_MUTE, params)
|
||||
|
||||
def set_volume(self, value):
|
||||
"""Send volume step value if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set volume to %s", self.entity_id, value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_MEDIA_VOLUME_LEVEL: value}
|
||||
self.call_service(DOMAIN, SERVICE_VOLUME_SET, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_VOLUME_SET, params)
|
||||
|
||||
def set_volume_step(self, value):
|
||||
"""Send volume step value if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Step volume by %s", self.entity_id, value)
|
||||
service = SERVICE_VOLUME_DOWN if value else SERVICE_VOLUME_UP
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
def set_input_source(self, value):
|
||||
"""Send input set value if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set current input to %s", self.entity_id, value)
|
||||
source = self.sources[value]
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_INPUT_SOURCE: source}
|
||||
self.call_service(DOMAIN, SERVICE_SELECT_SOURCE, params)
|
||||
self.async_call_service(DOMAIN, SERVICE_SELECT_SOURCE, params)
|
||||
|
||||
def set_remote_key(self, value):
|
||||
"""Send remote key value if call came from HomeKit."""
|
||||
|
@ -392,7 +392,7 @@ class TelevisionMediaPlayer(HomeAccessory):
|
|||
else:
|
||||
service = SERVICE_MEDIA_PLAY_PAUSE
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
else:
|
||||
# Unhandled keys can be handled by listening to the event bus
|
||||
self.hass.bus.fire(
|
||||
|
|
|
@ -150,7 +150,7 @@ class SecuritySystem(HomeAccessory):
|
|||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
if self._alarm_code:
|
||||
params[ATTR_CODE] = self._alarm_code
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
|
|
@ -80,7 +80,7 @@ class Outlet(HomeAccessory):
|
|||
_LOGGER.debug("%s: Set switch state to %s", self.entity_id, value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -131,7 +131,7 @@ class Switch(HomeAccessory):
|
|||
return
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
self.call_service(self._domain, service, params)
|
||||
self.async_call_service(self._domain, service, params)
|
||||
|
||||
if self.activate_only:
|
||||
call_later(self.hass, 1, self.reset_switch)
|
||||
|
@ -169,7 +169,9 @@ class Vacuum(Switch):
|
|||
sup_return_home = features & SUPPORT_RETURN_HOME
|
||||
service = SERVICE_RETURN_TO_BASE if sup_return_home else SERVICE_TURN_OFF
|
||||
|
||||
self.call_service(VACUUM_DOMAIN, service, {ATTR_ENTITY_ID: self.entity_id})
|
||||
self.async_call_service(
|
||||
VACUUM_DOMAIN, service, {ATTR_ENTITY_ID: self.entity_id}
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
@ -209,7 +211,7 @@ class Valve(HomeAccessory):
|
|||
self.char_in_use.set_value(value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id}
|
||||
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
|
||||
self.call_service(DOMAIN, service, params)
|
||||
self.async_call_service(DOMAIN, service, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
|
|
|
@ -356,7 +356,7 @@ class Thermostat(HomeAccessory):
|
|||
|
||||
if service:
|
||||
params[ATTR_ENTITY_ID] = self.entity_id
|
||||
self.call_service(
|
||||
self.async_call_service(
|
||||
DOMAIN_CLIMATE,
|
||||
service,
|
||||
params,
|
||||
|
@ -407,7 +407,7 @@ class Thermostat(HomeAccessory):
|
|||
"""Set target humidity to value if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set target humidity to %d", self.entity_id, value)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_HUMIDITY: value}
|
||||
self.call_service(
|
||||
self.async_call_service(
|
||||
DOMAIN_CLIMATE, SERVICE_SET_HUMIDITY, params, f"{value}{PERCENTAGE}"
|
||||
)
|
||||
|
||||
|
@ -584,7 +584,7 @@ class WaterHeater(HomeAccessory):
|
|||
_LOGGER.debug("%s: Set target temperature to %.1f°C", self.entity_id, value)
|
||||
temperature = temperature_to_states(value, self._unit)
|
||||
params = {ATTR_ENTITY_ID: self.entity_id, ATTR_TEMPERATURE: temperature}
|
||||
self.call_service(
|
||||
self.async_call_service(
|
||||
DOMAIN_WATER_HEATER,
|
||||
SERVICE_SET_TEMPERATURE_WATER_HEATER,
|
||||
params,
|
||||
|
|
|
@ -57,7 +57,7 @@ async def test_accessory_cancels_track_state_change_on_stop(hass, hk_driver):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
assert len(hass.data[TRACK_STATE_CHANGE_CALLBACKS][entity_id]) == 1
|
||||
acc.async_stop()
|
||||
assert entity_id not in hass.data[TRACK_STATE_CHANGE_CALLBACKS]
|
||||
|
@ -121,7 +121,7 @@ async def test_home_accessory(hass, hk_driver):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -156,7 +156,7 @@ async def test_battery_service(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -212,7 +212,7 @@ async def test_battery_service(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -253,7 +253,7 @@ async def test_linked_battery_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -298,7 +298,7 @@ async def test_linked_battery_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -340,7 +340,7 @@ async def test_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -352,7 +352,7 @@ async def test_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
"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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -362,7 +362,7 @@ async def test_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
"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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -372,7 +372,7 @@ async def test_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_remove(linked_battery_charging_sensor)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc._char_charging.value == 1
|
||||
|
||||
|
@ -405,7 +405,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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -449,7 +449,7 @@ async def test_missing_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Make sure we don't throw if the entity_id
|
||||
|
@ -458,7 +458,7 @@ async def test_missing_linked_battery_charging_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
):
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
|
@ -482,7 +482,7 @@ async def test_missing_linked_battery_sensor(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await 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_missing_linked_battery_sensor(hass, hk_driver, caplog):
|
|||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
hass.states.async_remove(entity_id)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not acc.linked_battery_sensor
|
||||
|
@ -517,7 +517,7 @@ async def test_battery_appears_after_startup(hass, hk_driver, caplog):
|
|||
with patch(
|
||||
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
|
||||
) as mock_async_update_state:
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(entity_id)
|
||||
mock_async_update_state.assert_called_with(state)
|
||||
|
@ -551,7 +551,7 @@ async def test_call_service(hass, hk_driver, events):
|
|||
test_service = "open_cover"
|
||||
test_value = "value"
|
||||
|
||||
await acc.async_call_service(
|
||||
acc.async_call_service(
|
||||
test_domain, test_service, {ATTR_ENTITY_ID: entity_id}, test_value
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -45,35 +45,35 @@ PID_THAT_WILL_NEVER_BE_ALIVE = 2147483647
|
|||
async def _async_start_streaming(hass, acc):
|
||||
"""Start streaming a camera."""
|
||||
acc.set_selected_stream_configuration(MOCK_START_STREAM_TLV)
|
||||
await acc.run_handler()
|
||||
await 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_handler()
|
||||
await 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_handler()
|
||||
await 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_handler()
|
||||
await 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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
|
@ -156,7 +156,7 @@ async def test_camera_stream_source_configured(hass, run_driver, events):
|
|||
bridge.add_accessory(acc)
|
||||
bridge.add_accessory(not_camera_acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -271,7 +271,7 @@ async def test_camera_stream_source_configured_with_failing_ffmpeg(
|
|||
bridge.add_accessory(acc)
|
||||
bridge.add_accessory(not_camera_acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -311,7 +311,7 @@ async def test_camera_stream_source_found(hass, run_driver, events):
|
|||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -361,7 +361,7 @@ async def test_camera_stream_source_fails(hass, run_driver, events):
|
|||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -396,7 +396,7 @@ async def test_camera_with_no_stream(hass, run_driver, events):
|
|||
2,
|
||||
{},
|
||||
)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -439,7 +439,7 @@ async def test_camera_stream_source_configured_and_copy_codec(hass, run_driver,
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -510,7 +510,7 @@ async def test_camera_streaming_fails_after_starting_ffmpeg(hass, run_driver, ev
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -588,7 +588,7 @@ async def test_camera_with_linked_motion_sensor(hass, run_driver, events):
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -617,7 +617,7 @@ async def test_camera_with_linked_motion_sensor(hass, run_driver, events):
|
|||
# motion sensor is removed
|
||||
hass.states.async_remove(motion_entity_id)
|
||||
await hass.async_block_till_done()
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert char.value is True
|
||||
|
||||
|
@ -644,7 +644,7 @@ async def test_camera_with_a_missing_linked_motion_sensor(hass, run_driver, even
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -686,7 +686,7 @@ async def test_camera_with_linked_doorbell_sensor(hass, run_driver, events):
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
@ -725,7 +725,7 @@ async def test_camera_with_linked_doorbell_sensor(hass, run_driver, events):
|
|||
# doorbell sensor is removed
|
||||
hass.states.async_remove(doorbell_entity_id)
|
||||
await hass.async_block_till_done()
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert char.value == 0
|
||||
assert char2.value == 0
|
||||
|
@ -753,7 +753,7 @@ async def test_camera_with_a_missing_linked_doorbell_sensor(hass, run_driver, ev
|
|||
bridge = HomeBridge("hass", run_driver, "Test Bridge")
|
||||
bridge.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 17 # Camera
|
||||
|
|
|
@ -52,7 +52,7 @@ async def test_garage_door_open_close(hass, 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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -136,7 +136,7 @@ async def test_windowcovering_set_cover_position(hass, hk_driver, events):
|
|||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -206,7 +206,7 @@ async def test_window_instantiate(hass, hk_driver, events):
|
|||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
acc = Window(hass, hk_driver, "Window", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -225,7 +225,7 @@ async def test_windowcovering_cover_set_tilt(hass, hk_driver, events):
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -289,7 +289,7 @@ async def test_windowcovering_open_close(hass, hk_driver, events):
|
|||
|
||||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -372,7 +372,7 @@ async def test_windowcovering_open_close_stop(hass, hk_driver, events):
|
|||
entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: SUPPORT_STOP}
|
||||
)
|
||||
acc = WindowCoveringBasic(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
|
@ -423,7 +423,7 @@ async def test_windowcovering_open_close_with_position_and_stop(
|
|||
{ATTR_SUPPORTED_FEATURES: SUPPORT_STOP | SUPPORT_SET_POSITION},
|
||||
)
|
||||
acc = WindowCovering(hass, hk_driver, "Cover", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Set from HomeKit
|
||||
|
@ -534,7 +534,7 @@ async def test_garage_door_with_linked_obstruction_sensor(hass, hk_driver, event
|
|||
2,
|
||||
{CONF_LINKED_OBSTRUCTION_SENSOR: linked_obstruction_sensor_entity_id},
|
||||
)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
|
|
@ -46,7 +46,7 @@ async def test_fan_basic(hass, hk_driver, events):
|
|||
# If there are no speed_list values, then HomeKit speed is unsupported
|
||||
assert acc.char_speed is None
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_active.value == 1
|
||||
|
||||
|
@ -123,7 +123,7 @@ async def test_fan_direction(hass, hk_driver, events):
|
|||
|
||||
assert acc.char_direction.value == 0
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_direction.value == 0
|
||||
|
||||
|
@ -191,7 +191,7 @@ async def test_fan_oscillate(hass, hk_driver, events):
|
|||
|
||||
assert acc.char_swing.value == 0
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_swing.value == 0
|
||||
|
||||
|
@ -267,7 +267,7 @@ async def test_fan_speed(hass, hk_driver, events):
|
|||
assert acc.char_speed.value != 0
|
||||
assert acc.char_speed.properties[PROP_MIN_STEP] == 25
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_PERCENTAGE: 100})
|
||||
|
@ -349,7 +349,7 @@ async def test_fan_set_all_one_shot(hass, hk_driver, events):
|
|||
# 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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
|
|
|
@ -54,7 +54,7 @@ async def test_humidifier(hass, hk_driver, events):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
|
@ -135,7 +135,7 @@ async def test_dehumidifier(hass, hk_driver, events):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
|
@ -220,7 +220,7 @@ async def test_hygrostat_power_state(hass, hk_driver, events):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidifier_dehumidifier.value == 2
|
||||
|
@ -298,7 +298,7 @@ async def test_hygrostat_get_humidity_range(hass, hk_driver):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidity.properties[PROP_MAX_VALUE] == 45
|
||||
|
@ -332,7 +332,7 @@ async def test_humidifier_with_linked_humidity_sensor(hass, hk_driver):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 42.0
|
||||
|
@ -384,7 +384,7 @@ async def test_humidifier_with_a_missing_linked_humidity_sensor(hass, hk_driver)
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 0
|
||||
|
@ -401,7 +401,7 @@ async def test_humidifier_as_dehumidifier(hass, hk_driver, events, caplog):
|
|||
)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidifier_dehumidifier.value == 1
|
||||
|
|
|
@ -42,7 +42,7 @@ async def test_light_basic(hass, hk_driver, events):
|
|||
assert acc.category == 5 # Lightbulb
|
||||
assert acc.char_on.value
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_on.value == 1
|
||||
|
||||
|
@ -117,7 +117,7 @@ async def test_light_brightness(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
|
@ -231,7 +231,7 @@ async def test_light_color_temperature(hass, hk_driver, events):
|
|||
|
||||
assert acc.char_color_temperature.value == 190
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_color_temperature.value == 190
|
||||
|
||||
|
@ -285,14 +285,14 @@ async def test_light_color_temperature_and_rgb_color(hass, hk_driver, events):
|
|||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP: 224})
|
||||
await hass.async_block_till_done()
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 27
|
||||
assert acc.char_saturation.value == 27
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP: 352})
|
||||
await hass.async_block_till_done()
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 28
|
||||
assert acc.char_saturation.value == 61
|
||||
|
@ -314,7 +314,7 @@ async def test_light_rgb_color(hass, hk_driver, events):
|
|||
assert acc.char_hue.value == 260
|
||||
assert acc.char_saturation.value == 90
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_hue.value == 260
|
||||
assert acc.char_saturation.value == 90
|
||||
|
@ -407,7 +407,7 @@ async def test_light_set_brightness_and_color(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
|
@ -482,7 +482,7 @@ async def test_light_set_brightness_and_color_temp(hass, hk_driver, events):
|
|||
char_brightness_iid = acc.char_brightness.to_HAP()[HAP_REPR_IID]
|
||||
char_color_temperature_iid = acc.char_color_temperature.to_HAP()[HAP_REPR_IID]
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_brightness.value == 100
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ async def test_lock_unlock(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 6 # DoorLock
|
||||
|
|
|
@ -61,7 +61,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 acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -203,7 +203,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 acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -375,7 +375,7 @@ async def test_media_player_television_basic(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 acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.chars_tv == [CHAR_REMOTE_KEY]
|
||||
|
@ -411,7 +411,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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.support_select_source is False
|
||||
|
|
|
@ -34,7 +34,7 @@ async def test_switch_set_state(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -238,7 +238,7 @@ async def test_supported_states(hass, hk_driver, events):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
acc = SecuritySystem(hass, hk_driver, "SecuritySystem", entity_id, 2, config)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
valid_current_values = acc.char_current_state.properties.get("ValidValues")
|
||||
|
|
|
@ -40,7 +40,7 @@ async def test_temperature(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -74,7 +74,7 @@ async def test_humidity(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -98,7 +98,7 @@ async def test_air_quality(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -130,7 +130,7 @@ async def test_co(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -170,7 +170,7 @@ async def test_co2(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -210,7 +210,7 @@ async def test_light(hass, hk_driver):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -235,7 +235,7 @@ async def test_binary(hass, hk_driver):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Window Opening", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -274,7 +274,7 @@ async def test_motion_uses_bool(hass, hk_driver):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
acc = BinarySensor(hass, hk_driver, "Motion Sensor", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
|
|
@ -42,7 +42,7 @@ async def test_outlet_set_state(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -95,7 +95,7 @@ async def test_switch_set_state(hass, hk_driver, entity_id, attrs, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -139,25 +139,25 @@ async def test_valve_set_state(hass, hk_driver, events):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
acc = Valve(hass, hk_driver, "Valve", entity_id, 2, {CONF_TYPE: TYPE_FAUCET})
|
||||
await acc.run_handler()
|
||||
await 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, 2, {CONF_TYPE: TYPE_SHOWER})
|
||||
await acc.run_handler()
|
||||
await 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, 2, {CONF_TYPE: TYPE_SPRINKLER})
|
||||
await acc.run_handler()
|
||||
await 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, 2, {CONF_TYPE: TYPE_VALVE})
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -210,7 +210,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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 8 # Switch
|
||||
|
@ -266,7 +266,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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 8 # Switch
|
||||
|
@ -310,7 +310,7 @@ async def test_reset_switch(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.activate_only is True
|
||||
|
@ -347,7 +347,7 @@ async def test_reset_switch_reload(hass, hk_driver, events):
|
|||
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_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.activate_only is False
|
||||
|
|
|
@ -89,7 +89,7 @@ async def test_thermostat(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 1
|
||||
|
@ -431,7 +431,7 @@ async def test_thermostat_auto(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
|
@ -570,7 +570,7 @@ async def test_thermostat_humidity(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_humidity.value == 50
|
||||
|
@ -645,7 +645,7 @@ async def test_thermostat_power_state(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_heat_cool.value == 1
|
||||
|
@ -756,7 +756,7 @@ async def test_thermostat_fahrenheit(hass, hk_driver, events):
|
|||
with patch.object(hass.config.units, CONF_TEMPERATURE_UNIT, new=TEMP_FAHRENHEIT):
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(
|
||||
|
@ -879,7 +879,7 @@ async def test_thermostat_temperature_step_whole(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_target_temp.properties[PROP_MIN_STEP] == 0.1
|
||||
|
@ -942,7 +942,7 @@ async def test_thermostat_hvac_modes(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1]
|
||||
|
@ -985,7 +985,7 @@ async def test_thermostat_hvac_modes_with_auto_heat_cool(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1, 3]
|
||||
|
@ -1041,7 +1041,7 @@ async def test_thermostat_hvac_modes_with_auto_no_heat_cool(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 1, 3]
|
||||
|
@ -1095,7 +1095,7 @@ async def test_thermostat_hvac_modes_with_auto_only(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [0, 3]
|
||||
|
@ -1149,7 +1149,7 @@ async def test_thermostat_hvac_modes_with_heat_only(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await 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]
|
||||
|
@ -1209,7 +1209,7 @@ async def test_thermostat_hvac_modes_with_cool_only(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await 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]
|
||||
|
@ -1273,7 +1273,7 @@ async def test_thermostat_hvac_modes_with_heat_cool_only(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [
|
||||
|
@ -1362,7 +1362,7 @@ async def test_thermostat_hvac_modes_without_off(hass, hk_driver):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
hap = acc.char_target_heat_cool.to_HAP()
|
||||
assert hap["valid-values"] == [1, 3]
|
||||
|
@ -1401,7 +1401,7 @@ async def test_thermostat_without_target_temp_only_range(hass, hk_driver, events
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
|
@ -1576,7 +1576,7 @@ async def test_water_heater(hass, hk_driver, events):
|
|||
hass.states.async_set(entity_id, HVAC_MODE_HEAT)
|
||||
await hass.async_block_till_done()
|
||||
acc = WaterHeater(hass, hk_driver, "WaterHeater", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
|
@ -1655,7 +1655,7 @@ async def test_water_heater_fahrenheit(hass, hk_driver, events):
|
|||
await hass.async_block_till_done()
|
||||
with patch.object(hass.config.units, CONF_TEMPERATURE_UNIT, new=TEMP_FAHRENHEIT):
|
||||
acc = WaterHeater(hass, hk_driver, "WaterHeater", entity_id, 2, None)
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set(entity_id, HVAC_MODE_HEAT, {ATTR_TEMPERATURE: 131})
|
||||
|
@ -1762,7 +1762,7 @@ async def test_thermostat_with_no_modes_when_we_first_see(hass, hk_driver, event
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
|
@ -1815,7 +1815,7 @@ async def test_thermostat_with_no_off_after_recheck(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 23.0
|
||||
|
@ -1869,7 +1869,7 @@ async def test_thermostat_with_temp_clamps(hass, hk_driver, events):
|
|||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run_handler()
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_cooling_thresh_temp.value == 100
|
||||
|
|
Loading…
Add table
Reference in a new issue