mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Remove duplicate filter for Hue button events (#62974)
This commit is contained in:
parent
bc7e51b992
commit
c7f465ff3b
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
from aiohue.v2 import HueBridgeV2
|
from aiohue.v2 import HueBridgeV2
|
||||||
from aiohue.v2.controllers.events import EventType
|
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.const import CONF_DEVICE_ID, CONF_ID, CONF_TYPE, CONF_UNIQUE_ID
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -27,11 +27,6 @@ async def async_setup_hue_events(bridge: "HueBridge"):
|
|||||||
api: HueBridgeV2 = bridge.api # to satisfy typing
|
api: HueBridgeV2 = bridge.api # to satisfy typing
|
||||||
conf_entry = bridge.config_entry
|
conf_entry = bridge.config_entry
|
||||||
dev_reg = device_registry.async_get(hass)
|
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
|
# at this time the `button` resource is the only source of hue events
|
||||||
btn_controller = api.sensors.button
|
btn_controller = api.sensors.button
|
||||||
@ -45,26 +40,16 @@ async def async_setup_hue_events(bridge: "HueBridge"):
|
|||||||
if hue_resource.button is None:
|
if hue_resource.button is None:
|
||||||
return
|
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)
|
hue_device = btn_controller.get_device(hue_resource.id)
|
||||||
device = dev_reg.async_get_device({(DOMAIN, hue_device.id)})
|
device = dev_reg.async_get_device({(DOMAIN, hue_device.id)})
|
||||||
|
|
||||||
# Fire event
|
# Fire event
|
||||||
data = {
|
data = {
|
||||||
# send slugified entity name as id = backwards compatibility with previous version
|
# 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_DEVICE_ID: device.id, # type: ignore
|
||||||
CONF_UNIQUE_ID: hue_resource.id,
|
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,
|
CONF_SUBTYPE: hue_resource.metadata.control_id,
|
||||||
}
|
}
|
||||||
hass.bus.async_fire(ATTR_HUE_EVENT, data)
|
hass.bus.async_fire(ATTR_HUE_EVENT, data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user