Entity to handle updates via events (#24733)

* Entity to handle updates via events

* Fix a bug

* Update entity.py
This commit is contained in:
Paulus Schoutsen 2019-06-26 09:22:51 -07:00 committed by GitHub
parent 9e0636eefa
commit 06af6f19a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 66 deletions

View file

@ -104,12 +104,12 @@ async def test_dump_data(hass):
entity = Entity()
entity.hass = hass
entity.entity_id = 'input_boolean.b0'
await entity.async_added_to_hass()
await entity.async_internal_added_to_hass()
entity = RestoreEntity()
entity.hass = hass
entity.entity_id = 'input_boolean.b1'
await entity.async_added_to_hass()
await entity.async_internal_added_to_hass()
data = await RestoreStateData.async_get_instance(hass)
now = dt_util.utcnow()
@ -144,7 +144,7 @@ async def test_dump_data(hass):
assert written_states[1]['state']['state'] == 'off'
# Test that removed entities are not persisted
await entity.async_will_remove_from_hass()
await entity.async_remove()
with patch('homeassistant.helpers.restore_state.Store.async_save'
) as mock_write_data, patch.object(
@ -170,12 +170,12 @@ async def test_dump_error(hass):
entity = Entity()
entity.hass = hass
entity.entity_id = 'input_boolean.b0'
await entity.async_added_to_hass()
await entity.async_internal_added_to_hass()
entity = RestoreEntity()
entity.hass = hass
entity.entity_id = 'input_boolean.b1'
await entity.async_added_to_hass()
await entity.async_internal_added_to_hass()
data = await RestoreStateData.async_get_instance(hass)
@ -206,7 +206,7 @@ async def test_state_saved_on_remove(hass):
entity = RestoreEntity()
entity.hass = hass
entity.entity_id = 'input_boolean.b0'
await entity.async_added_to_hass()
await entity.async_internal_added_to_hass()
hass.states.async_set('input_boolean.b0', 'on')
@ -215,7 +215,7 @@ async def test_state_saved_on_remove(hass):
# No last states should currently be saved
assert not data.last_states
await entity.async_will_remove_from_hass()
await entity.async_remove()
# We should store the input boolean state when it is removed
assert data.last_states['input_boolean.b0'].state.state == 'on'