mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Publish timestamps in nest events (#44641)
This commit is contained in:
parent
a212248f8d
commit
baacf2cd7d
@ -138,6 +138,7 @@ class SignalUpdateCallback:
|
||||
message = {
|
||||
"device_id": device_entry.id,
|
||||
"type": event_type,
|
||||
"timestamp": event_message.timestamp,
|
||||
}
|
||||
self._hass.bus.async_fire(NEST_EVENT, message)
|
||||
|
||||
|
@ -10,6 +10,7 @@ from homeassistant.components.device_automation.exceptions import (
|
||||
from homeassistant.components.nest import DOMAIN
|
||||
from homeassistant.components.nest.events import NEST_EVENT
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from .common import async_setup_sdm_platform
|
||||
|
||||
@ -213,7 +214,7 @@ async def test_fires_on_camera_motion(hass, calls):
|
||||
"""Test camera_motion triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_motion"}
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_motion", "timestamp": utcnow()}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
@ -224,7 +225,7 @@ async def test_fires_on_camera_person(hass, calls):
|
||||
"""Test camera_person triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_person")
|
||||
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_person"}
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_person", "timestamp": utcnow()}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
@ -235,7 +236,7 @@ async def test_fires_on_camera_sound(hass, calls):
|
||||
"""Test camera_person triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_sound")
|
||||
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_sound"}
|
||||
message = {"device_id": DEVICE_ID, "type": "camera_sound", "timestamp": utcnow()}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
@ -246,7 +247,7 @@ async def test_fires_on_doorbell_chime(hass, calls):
|
||||
"""Test doorbell_chime triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "doorbell_chime")
|
||||
|
||||
message = {"device_id": DEVICE_ID, "type": "doorbell_chime"}
|
||||
message = {"device_id": DEVICE_ID, "type": "doorbell_chime", "timestamp": utcnow()}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
@ -257,7 +258,11 @@ async def test_trigger_for_wrong_device_id(hass, calls):
|
||||
"""Test for turn_on and turn_off triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
message = {"device_id": "wrong-device-id", "type": "camera_motion"}
|
||||
message = {
|
||||
"device_id": "wrong-device-id",
|
||||
"type": "camera_motion",
|
||||
"timestamp": utcnow(),
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
@ -267,7 +272,11 @@ async def test_trigger_for_wrong_event_type(hass, calls):
|
||||
"""Test for turn_on and turn_off triggers firing."""
|
||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
||||
|
||||
message = {"device_id": DEVICE_ID, "type": "wrong-event-type"}
|
||||
message = {
|
||||
"device_id": DEVICE_ID,
|
||||
"type": "wrong-event-type",
|
||||
"timestamp": utcnow(),
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
|
@ -54,7 +54,7 @@ def create_device_traits(event_trait):
|
||||
}
|
||||
|
||||
|
||||
def create_event(event_type, device_id=DEVICE_ID):
|
||||
def create_event(event_type, device_id=DEVICE_ID, timestamp=None):
|
||||
"""Create an EventMessage for a single event type."""
|
||||
events = {
|
||||
event_type: {
|
||||
@ -65,12 +65,14 @@ def create_event(event_type, device_id=DEVICE_ID):
|
||||
return create_events(events=events, device_id=device_id)
|
||||
|
||||
|
||||
def create_events(events, device_id=DEVICE_ID):
|
||||
def create_events(events, device_id=DEVICE_ID, timestamp=None):
|
||||
"""Create an EventMessage for events."""
|
||||
if not timestamp:
|
||||
timestamp = utcnow()
|
||||
return EventMessage(
|
||||
{
|
||||
"eventId": "some-event-id",
|
||||
"timestamp": utcnow().isoformat(timespec="seconds"),
|
||||
"timestamp": timestamp.isoformat(timespec="seconds"),
|
||||
"resourceUpdate": {
|
||||
"name": device_id,
|
||||
"events": events,
|
||||
@ -102,15 +104,18 @@ async def test_doorbell_chime_event(hass):
|
||||
assert device.model == "Doorbell"
|
||||
assert device.identifiers == {("nest", DEVICE_ID)}
|
||||
|
||||
timestamp = utcnow()
|
||||
await subscriber.async_receive_event(
|
||||
create_event("sdm.devices.events.DoorbellChime.Chime")
|
||||
create_event("sdm.devices.events.DoorbellChime.Chime", timestamp=timestamp)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event_time = timestamp.replace(microsecond=0)
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "doorbell_chime",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
|
||||
|
||||
@ -126,15 +131,18 @@ async def test_camera_motion_event(hass):
|
||||
entry = registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
timestamp = utcnow()
|
||||
await subscriber.async_receive_event(
|
||||
create_event("sdm.devices.events.CameraMotion.Motion")
|
||||
create_event("sdm.devices.events.CameraMotion.Motion", timestamp=timestamp)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event_time = timestamp.replace(microsecond=0)
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "camera_motion",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
|
||||
|
||||
@ -150,15 +158,18 @@ async def test_camera_sound_event(hass):
|
||||
entry = registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
timestamp = utcnow()
|
||||
await subscriber.async_receive_event(
|
||||
create_event("sdm.devices.events.CameraSound.Sound")
|
||||
create_event("sdm.devices.events.CameraSound.Sound", timestamp=timestamp)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event_time = timestamp.replace(microsecond=0)
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "camera_sound",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
|
||||
|
||||
@ -174,15 +185,18 @@ async def test_camera_person_event(hass):
|
||||
entry = registry.async_get("camera.front")
|
||||
assert entry is not None
|
||||
|
||||
timestamp = utcnow()
|
||||
await subscriber.async_receive_event(
|
||||
create_event("sdm.devices.events.CameraPerson.Person")
|
||||
create_event("sdm.devices.events.CameraPerson.Person", timestamp=timestamp)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event_time = timestamp.replace(microsecond=0)
|
||||
assert len(events) == 1
|
||||
assert events[0].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "camera_person",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
|
||||
|
||||
@ -209,17 +223,21 @@ async def test_camera_multiple_event(hass):
|
||||
},
|
||||
}
|
||||
|
||||
await subscriber.async_receive_event(create_events(event_map))
|
||||
timestamp = utcnow()
|
||||
await subscriber.async_receive_event(create_events(event_map, timestamp=timestamp))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
event_time = timestamp.replace(microsecond=0)
|
||||
assert len(events) == 2
|
||||
assert events[0].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "camera_motion",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
assert events[1].data == {
|
||||
"device_id": entry.device_id,
|
||||
"type": "camera_person",
|
||||
"timestamp": event_time,
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user