Fire event when core config is updated (#23922)
* Fire event when core config is updated
This commit is contained in:
parent
eb912be47a
commit
afe9fc221e
6 changed files with 180 additions and 97 deletions
|
@ -23,7 +23,8 @@ from homeassistant.const import (
|
|||
__version__, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM,
|
||||
ATTR_NOW, EVENT_TIME_CHANGED, EVENT_TIMER_OUT_OF_SYNC, ATTR_SECONDS,
|
||||
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_CLOSE,
|
||||
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, EVENT_CALL_SERVICE)
|
||||
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, EVENT_CALL_SERVICE,
|
||||
EVENT_CORE_CONFIG_UPDATE)
|
||||
|
||||
from tests.common import get_test_home_assistant, async_mock_service
|
||||
|
||||
|
@ -871,7 +872,7 @@ class TestConfig(unittest.TestCase):
|
|||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.config = ha.Config()
|
||||
self.config = ha.Config(None)
|
||||
assert self.config.config_dir is None
|
||||
|
||||
def test_path_with_file(self):
|
||||
|
@ -942,6 +943,32 @@ class TestConfig(unittest.TestCase):
|
|||
self.config.is_allowed_path(None)
|
||||
|
||||
|
||||
async def test_event_on_update(hass, hass_storage):
|
||||
"""Test that event is fired on update."""
|
||||
events = []
|
||||
|
||||
@ha.callback
|
||||
def callback(event):
|
||||
events.append(event)
|
||||
|
||||
hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, callback)
|
||||
|
||||
assert hass.config.latitude != 12
|
||||
|
||||
await hass.config.update(latitude=12)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.config.latitude == 12
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {'latitude': 12}
|
||||
|
||||
|
||||
def test_bad_timezone_raises_value_error(hass):
|
||||
"""Test bad timezone raises ValueError."""
|
||||
with pytest.raises(ValueError):
|
||||
hass.config.set_time_zone('not_a_timezone')
|
||||
|
||||
|
||||
@patch('homeassistant.core.monotonic')
|
||||
def test_create_timer(mock_monotonic, loop):
|
||||
"""Test create timer."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue