diff --git a/homeassistant/components/hue/v2/hue_event.py b/homeassistant/components/hue/v2/hue_event.py index 496507aff4d..1d45293012c 100644 --- a/homeassistant/components/hue/v2/hue_event.py +++ b/homeassistant/components/hue/v2/hue_event.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING from aiohue.v2 import HueBridgeV2 from aiohue.v2.controllers.events import EventType -from aiohue.v2.models.button import Button, ButtonEvent +from aiohue.v2.models.button import Button from homeassistant.const import CONF_DEVICE_ID, CONF_ID, CONF_TYPE, CONF_UNIQUE_ID from homeassistant.core import callback @@ -27,11 +27,6 @@ async def async_setup_hue_events(bridge: "HueBridge"): api: HueBridgeV2 = bridge.api # to satisfy typing conf_entry = bridge.config_entry dev_reg = device_registry.async_get(hass) - last_state = { - x.id: x.button.last_event - for x in api.sensors.button.items - if x.button is not None - } # at this time the `button` resource is the only source of hue events btn_controller = api.sensors.button @@ -45,26 +40,16 @@ async def async_setup_hue_events(bridge: "HueBridge"): if hue_resource.button is None: return - cur_event = hue_resource.button.last_event - last_event = last_state.get(hue_resource.id) - # ignore the event if the last_event value is exactly the same - # this may happen if some other metadata of the button resource is adjusted - if cur_event == last_event: - return - if cur_event != ButtonEvent.REPEAT: - # do not store repeat event - last_state[hue_resource.id] = cur_event - hue_device = btn_controller.get_device(hue_resource.id) device = dev_reg.async_get_device({(DOMAIN, hue_device.id)}) # Fire event data = { # send slugified entity name as id = backwards compatibility with previous version - CONF_ID: slugify(f"{hue_device.metadata.name}: Button"), + CONF_ID: slugify(f"{hue_device.metadata.name} Button"), CONF_DEVICE_ID: device.id, # type: ignore CONF_UNIQUE_ID: hue_resource.id, - CONF_TYPE: cur_event.value, + CONF_TYPE: hue_resource.button.last_event.value, CONF_SUBTYPE: hue_resource.metadata.control_id, } hass.bus.async_fire(ATTR_HUE_EVENT, data)