mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Small fix for device triggers and events on Hue integration (#61462)
This commit is contained in:
parent
6d54261322
commit
0d36b07d10
@ -40,6 +40,19 @@ TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DEFAULT_BUTTON_EVENT_TYPES = (
|
||||||
|
# all except `DOUBLE_SHORT_RELEASE`
|
||||||
|
ButtonEvent.INITIAL_PRESS,
|
||||||
|
ButtonEvent.REPEAT,
|
||||||
|
ButtonEvent.SHORT_RELEASE,
|
||||||
|
ButtonEvent.LONG_RELEASE,
|
||||||
|
)
|
||||||
|
|
||||||
|
DEVICE_SPECIFIC_EVENT_TYPES = {
|
||||||
|
# device specific overrides of specific supported button events
|
||||||
|
"Hue tap switch": (ButtonEvent.INITIAL_PRESS,),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_validate_trigger_config(
|
async def async_validate_trigger_config(
|
||||||
bridge: "HueBridge",
|
bridge: "HueBridge",
|
||||||
@ -84,10 +97,13 @@ async def async_get_triggers(bridge: "HueBridge", device_entry: DeviceEntry):
|
|||||||
hue_dev_id = get_hue_device_id(device_entry)
|
hue_dev_id = get_hue_device_id(device_entry)
|
||||||
# extract triggers from all button resources of this Hue device
|
# extract triggers from all button resources of this Hue device
|
||||||
triggers = []
|
triggers = []
|
||||||
|
model_id = api.devices[hue_dev_id].product_data.product_name
|
||||||
for resource in api.devices.get_sensors(hue_dev_id):
|
for resource in api.devices.get_sensors(hue_dev_id):
|
||||||
if resource.type != ResourceTypes.BUTTON:
|
if resource.type != ResourceTypes.BUTTON:
|
||||||
continue
|
continue
|
||||||
for event_type in (x.value for x in ButtonEvent if x != ButtonEvent.UNKNOWN):
|
for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get(
|
||||||
|
model_id, DEFAULT_BUTTON_EVENT_TYPES
|
||||||
|
):
|
||||||
triggers.append(
|
triggers.append(
|
||||||
{
|
{
|
||||||
CONF_DEVICE_ID: device_entry.id,
|
CONF_DEVICE_ID: device_entry.id,
|
||||||
@ -95,7 +111,7 @@ async def async_get_triggers(bridge: "HueBridge", device_entry: DeviceEntry):
|
|||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
CONF_TYPE: event_type,
|
CONF_TYPE: event_type,
|
||||||
CONF_SUBTYPE: resource.metadata.control_id,
|
CONF_SUBTYPE: resource.metadata.control_id,
|
||||||
CONF_UNIQUE_ID: device_entry.id,
|
CONF_UNIQUE_ID: resource.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return triggers
|
return triggers
|
||||||
|
@ -70,12 +70,20 @@ async def test_get_triggers(hass, mock_bridge_v2, v2_resources_test_data, device
|
|||||||
"platform": "device",
|
"platform": "device",
|
||||||
"domain": hue.DOMAIN,
|
"domain": hue.DOMAIN,
|
||||||
"device_id": hue_wall_switch_device.id,
|
"device_id": hue_wall_switch_device.id,
|
||||||
"unique_id": hue_wall_switch_device.id,
|
"unique_id": resource_id,
|
||||||
"type": event_type,
|
"type": event_type,
|
||||||
"subtype": control_id,
|
"subtype": control_id,
|
||||||
}
|
}
|
||||||
for event_type in (x.value for x in ButtonEvent if x != ButtonEvent.UNKNOWN)
|
for event_type in (
|
||||||
for control_id in range(1, 3)
|
ButtonEvent.INITIAL_PRESS,
|
||||||
|
ButtonEvent.LONG_RELEASE,
|
||||||
|
ButtonEvent.REPEAT,
|
||||||
|
ButtonEvent.SHORT_RELEASE,
|
||||||
|
)
|
||||||
|
for control_id, resource_id in (
|
||||||
|
(1, "c658d3d8-a013-4b81-8ac6-78b248537e70"),
|
||||||
|
(2, "be1eb834-bdf5-4d26-8fba-7b1feaa83a9d"),
|
||||||
|
)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user