Ensure homekit state changed listeners are unsubscribed on reload (#37200)

* Ensure homekit state changed listeners are unsubscribed on reload

* fix mocking
This commit is contained in:
J. Nick Koston 2020-06-29 11:25:26 -05:00 committed by GitHub
parent 7ef33a7219
commit 0f72008090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 10 deletions

View file

@ -45,6 +45,7 @@ from homeassistant.const import (
STATE_UNAVAILABLE,
__version__,
)
from homeassistant.helpers.event import TRACK_STATE_CHANGE_CALLBACKS
import homeassistant.util.dt as dt_util
from tests.async_mock import Mock, patch
@ -83,6 +84,22 @@ async def test_debounce(hass):
assert counter == 2
async def test_accessory_cancels_track_state_change_on_stop(hass, hk_driver):
"""Ensure homekit state changed listeners are unsubscribed on reload."""
entity_id = "sensor.accessory"
hass.states.async_set(entity_id, None)
acc = HomeAccessory(
hass, hk_driver, "Home Accessory", entity_id, 2, {"platform": "isy994"}
)
with patch(
"homeassistant.components.homekit.accessories.HomeAccessory.async_update_state"
):
await acc.run_handler()
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]
async def test_home_accessory(hass, hk_driver):
"""Test HomeAccessory class."""
entity_id = "sensor.accessory"