Add get_states faster (#23315)

This commit is contained in:
Paulus Schoutsen 2019-04-23 03:46:23 -07:00 committed by Pascal Vizeli
parent 00d26b3049
commit 5b0ee473b6
4 changed files with 56 additions and 5 deletions

View file

@ -142,11 +142,14 @@ def handle_get_states(hass, connection, msg):
Async friendly.
"""
entity_perm = connection.user.permissions.check_entity
states = [
state for state in hass.states.async_all()
if entity_perm(state.entity_id, 'read')
]
if connection.user.permissions.access_all_entities('read'):
states = hass.states.async_all()
else:
entity_perm = connection.user.permissions.check_entity
states = [
state for state in hass.states.async_all()
if entity_perm(state.entity_id, 'read')
]
connection.send_message(messages.result_message(
msg['id'], states))