Provide device_id in hue_event (#56982)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
pull/57619/head
Christian Manivong 2021-10-13 20:20:38 +02:00 committed by GitHub
parent df4e8721e9
commit 16b7375e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -8,7 +8,7 @@ from aiohue.sensors import (
TYPE_ZLL_SWITCH,
)
from homeassistant.const import CONF_EVENT, CONF_ID, CONF_UNIQUE_ID
from homeassistant.const import CONF_DEVICE_ID, CONF_EVENT, CONF_ID, CONF_UNIQUE_ID
from homeassistant.core import callback
from homeassistant.util import dt as dt_util, slugify
@ -85,6 +85,7 @@ class HueEvent(GenericHueDevice):
# Fire event
data = {
CONF_ID: self.event_id,
CONF_DEVICE_ID: self.device_registry_id,
CONF_UNIQUE_ID: self.unique_id,
CONF_EVENT: state,
CONF_LAST_UPDATED: self.sensor.lastupdated,

View File

@ -3,14 +3,27 @@ import asyncio
from unittest.mock import Mock
import aiohue
import pytest
from homeassistant.components import hue
from homeassistant.components.hue import sensor_base
from homeassistant.components.hue.hue_event import CONF_HUE_EVENT
from homeassistant.util import dt as dt_util
from .conftest import create_mock_bridge, setup_bridge_for_sensors as setup_bridge
from tests.common import async_capture_events, async_fire_time_changed
from tests.common import (
async_capture_events,
async_fire_time_changed,
mock_device_registry,
)
@pytest.fixture
def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass)
PRESENCE_SENSOR_1_PRESENT = {
"state": {"presence": True, "lastupdated": "2019-01-01T01:00:00"},
@ -435,7 +448,7 @@ async def test_update_unauthorized(hass, mock_bridge):
assert len(mock_bridge.handle_unauthorized_error.mock_calls) == 1
async def test_hue_events(hass, mock_bridge):
async def test_hue_events(hass, mock_bridge, device_reg):
"""Test that hue remotes fire events when pressed."""
mock_bridge.mock_sensor_responses.append(SENSOR_RESPONSE)
@ -446,6 +459,10 @@ async def test_hue_events(hass, mock_bridge):
assert len(hass.states.async_all()) == 7
assert len(events) == 0
hue_tap_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:00:00:00:00:44:23:08")}
)
mock_bridge.api.sensors["7"].last_event = {"type": "button"}
mock_bridge.api.sensors["8"].last_event = {"type": "button"}
@ -467,12 +484,17 @@ async def test_hue_events(hass, mock_bridge):
assert len(hass.states.async_all()) == 7
assert len(events) == 1
assert events[-1].data == {
"device_id": hue_tap_device.id,
"id": "hue_tap",
"unique_id": "00:00:00:00:00:44:23:08-f2",
"event": 18,
"last_updated": "2019-12-28T22:58:03",
}
hue_dimmer_device = device_reg.async_get_device(
{(hue.DOMAIN, "00:17:88:01:10:3e:3a:dc")}
)
new_sensor_response = dict(new_sensor_response)
new_sensor_response["8"] = dict(new_sensor_response["8"])
new_sensor_response["8"]["state"] = {
@ -491,6 +513,7 @@ async def test_hue_events(hass, mock_bridge):
assert len(hass.states.async_all()) == 7
assert len(events) == 2
assert events[-1].data == {
"device_id": hue_dimmer_device.id,
"id": "hue_dimmer_switch_1",
"unique_id": "00:17:88:01:10:3e:3a:dc-02-fc00",
"event": 3002,
@ -571,10 +594,15 @@ async def test_hue_events(hass, mock_bridge):
)
await hass.async_block_till_done()
hue_aurora_device = device_reg.async_get_device(
{(hue.DOMAIN, "ff:ff:00:0f:e7:fd:bc:b7")}
)
assert len(mock_bridge.mock_requests) == 6
assert len(hass.states.async_all()) == 8
assert len(events) == 3
assert events[-1].data == {
"device_id": hue_aurora_device.id,
"id": "lutron_aurora_1",
"unique_id": "ff:ff:00:0f:e7:fd:bc:b7-01-fc00-0014",
"event": 2,