Remove duplicate filter for Hue button events ()

pull/62981/head
Marcel van der Veldt 2021-12-29 07:21:23 +01:00 committed by GitHub
parent bc7e51b992
commit c7f465ff3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 18 deletions
homeassistant/components/hue/v2

View File

@ -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)