Optimize is_entity_exposed in emulated_hue by removing deprec… (#32718)

* emulated_hue: Optimize is_entity_exposed

Switch all list transversals in is_entity_exposed to
hash lookups

get_deprecated is now only called if explict_expose is
set

This funciton was iterating multiple lists per enitity
every time there was an update.  It was responsible for
a chunk of execution time when there are large number
of entities in home assistant.

* Complete deprecation of ATTR_EMULATED_HUE attribute

* Complete deprecation of ATTR_EMULATED_HUE attribute (remove const)

* Remove ATTR_EMULATED_HUE_HIDDEN and Rewrite tests
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-03-13 21:47:47 -07:00
1 parent aa972b0005
commit 750ed2facd
2 files changed
+27 -70

No files matched your search

+11 -42
View File
@@ -130,51 +130,9 @@ def hass_hue(loop, hass):
)
)
# Kitchen light is explicitly excluded from being exposed
kitchen_light_entity = hass.states.get("light.kitchen_lights")
attrs = dict(kitchen_light_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE] = False
hass.states.async_set(
kitchen_light_entity.entity_id, kitchen_light_entity.state, attributes=attrs
)
# create a lamp without brightness support
hass.states.async_set("light.no_brightness", "on", {})
# Ceiling Fan is explicitly excluded from being exposed
ceiling_fan_entity = hass.states.get("fan.ceiling_fan")
attrs = dict(ceiling_fan_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE_HIDDEN] = True
hass.states.async_set(
ceiling_fan_entity.entity_id, ceiling_fan_entity.state, attributes=attrs
)
# Expose the script
script_entity = hass.states.get("script.set_kitchen_light")
attrs = dict(script_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE] = True
hass.states.async_set(
script_entity.entity_id, script_entity.state, attributes=attrs
)
# Expose cover
cover_entity = hass.states.get("cover.living_room_window")
attrs = dict(cover_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE_HIDDEN] = False
hass.states.async_set(cover_entity.entity_id, cover_entity.state, attributes=attrs)
# Expose Hvac
hvac_entity = hass.states.get("climate.hvac")
attrs = dict(hvac_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE_HIDDEN] = False
hass.states.async_set(hvac_entity.entity_id, hvac_entity.state, attributes=attrs)
# Expose HeatPump
hp_entity = hass.states.get("climate.heatpump")
attrs = dict(hp_entity.attributes)
attrs[emulated_hue.ATTR_EMULATED_HUE_HIDDEN] = False
hass.states.async_set(hp_entity.entity_id, hp_entity.state, attributes=attrs)
return hass
@@ -188,7 +146,18 @@ def hue_client(loop, hass_hue, aiohttp_client):
emulated_hue.CONF_TYPE: emulated_hue.TYPE_ALEXA,
emulated_hue.CONF_ENTITIES: {
"light.bed_light": {emulated_hue.CONF_ENTITY_HIDDEN: True},
# Kitchen light is explicitly excluded from being exposed
"light.kitchen_lights": {emulated_hue.CONF_ENTITY_HIDDEN: True},
# Ceiling Fan is explicitly excluded from being exposed
"fan.ceiling_fan": {emulated_hue.CONF_ENTITY_HIDDEN: True},
# Expose the script
"script.set_kitchen_light": {emulated_hue.CONF_ENTITY_HIDDEN: False},
# Expose cover
"cover.living_room_window": {emulated_hue.CONF_ENTITY_HIDDEN: False},
# Expose Hvac
"climate.hvac": {emulated_hue.CONF_ENTITY_HIDDEN: False},
# Expose HeatPump
"climate.heatpump": {emulated_hue.CONF_ENTITY_HIDDEN: False},
},
},
)