mirror of
https://github.com/home-assistant/core.git
synced 2025-12-20 02:48:57 +00:00
Netatmo NOCamera on/off fix (#158741)
This commit is contained in:
@@ -27,6 +27,8 @@ from .const import (
|
||||
DATA_CAMERAS,
|
||||
DATA_EVENTS,
|
||||
DOMAIN,
|
||||
EVENT_TYPE_CONNECTION,
|
||||
EVENT_TYPE_DISCONNECTION,
|
||||
EVENT_TYPE_LIGHT_MODE,
|
||||
EVENT_TYPE_OFF,
|
||||
EVENT_TYPE_ON,
|
||||
@@ -123,7 +125,13 @@ class NetatmoCamera(NetatmoModuleEntity, Camera):
|
||||
"""Entity created."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
for event_type in (EVENT_TYPE_LIGHT_MODE, EVENT_TYPE_OFF, EVENT_TYPE_ON):
|
||||
for event_type in (
|
||||
EVENT_TYPE_LIGHT_MODE,
|
||||
EVENT_TYPE_OFF,
|
||||
EVENT_TYPE_ON,
|
||||
EVENT_TYPE_CONNECTION,
|
||||
EVENT_TYPE_DISCONNECTION,
|
||||
):
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
@@ -146,12 +154,19 @@ class NetatmoCamera(NetatmoModuleEntity, Camera):
|
||||
data["home_id"] == self.home.entity_id
|
||||
and data["camera_id"] == self.device.entity_id
|
||||
):
|
||||
if data[WEBHOOK_PUSH_TYPE] in ("NACamera-off", "NACamera-disconnection"):
|
||||
if data[WEBHOOK_PUSH_TYPE] in (
|
||||
"NACamera-off",
|
||||
"NOCamera-off",
|
||||
"NACamera-disconnection",
|
||||
"NOCamera-disconnection",
|
||||
):
|
||||
self._attr_is_streaming = False
|
||||
self._monitoring = False
|
||||
elif data[WEBHOOK_PUSH_TYPE] in (
|
||||
"NACamera-on",
|
||||
"NOCamera-on",
|
||||
WEBHOOK_NACAMERA_CONNECTION,
|
||||
"NOCamera-connection",
|
||||
):
|
||||
self._attr_is_streaming = True
|
||||
self._monitoring = True
|
||||
|
||||
@@ -127,6 +127,9 @@ EVENT_TYPE_ALARM_STARTED = "alarm_started"
|
||||
EVENT_TYPE_DOOR_TAG_BIG_MOVE = "tag_big_move"
|
||||
EVENT_TYPE_DOOR_TAG_OPEN = "tag_open"
|
||||
EVENT_TYPE_DOOR_TAG_SMALL_MOVE = "tag_small_move"
|
||||
# Generic events
|
||||
EVENT_TYPE_CONNECTION = "connection"
|
||||
EVENT_TYPE_DISCONNECTION = "disconnection"
|
||||
EVENT_TYPE_OFF = "off"
|
||||
EVENT_TYPE_ON = "on"
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ async def test_setup_component_with_webhook(
|
||||
|
||||
assert hass.states.get(camera_entity_indoor).state == "streaming"
|
||||
|
||||
# Test outdoor camera events - not yet supported
|
||||
# Test outdoor camera events
|
||||
assert hass.states.get(camera_entity_outdoor).state == "streaming"
|
||||
response = {
|
||||
"event_type": "off",
|
||||
@@ -100,8 +100,7 @@ async def test_setup_component_with_webhook(
|
||||
}
|
||||
await simulate_webhook(hass, webhook_id, response)
|
||||
|
||||
# The NOCamera-off push_type is not yet supported (assert should be "idle" when supported)
|
||||
assert hass.states.get(camera_entity_outdoor).state == "streaming"
|
||||
assert hass.states.get(camera_entity_outdoor).state == "idle"
|
||||
|
||||
response = {
|
||||
"event_type": "on",
|
||||
@@ -425,8 +424,19 @@ async def test_service_set_camera_light_invalid_type(
|
||||
assert "NACamera <Hall> does not have a floodlight" in excinfo.value.args[0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("camera_type", "camera_id", "camera_entity"),
|
||||
[
|
||||
("NACamera", "12:34:56:00:f1:62", "camera.hall"),
|
||||
("NOCamera", "12:34:56:10:b9:0e", "camera.front"),
|
||||
],
|
||||
)
|
||||
async def test_camera_reconnect_webhook(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
camera_type: str,
|
||||
camera_id: str,
|
||||
camera_entity: str,
|
||||
) -> None:
|
||||
"""Test webhook event on camera reconnect."""
|
||||
fake_post_hits = 0
|
||||
@@ -472,7 +482,7 @@ async def test_camera_reconnect_webhook(
|
||||
|
||||
# Fake camera reconnect
|
||||
response = {
|
||||
"push_type": "NACamera-connection",
|
||||
"push_type": f"{camera_type}-connection",
|
||||
}
|
||||
await simulate_webhook(hass, webhook_id, response)
|
||||
await hass.async_block_till_done()
|
||||
@@ -484,6 +494,30 @@ async def test_camera_reconnect_webhook(
|
||||
await hass.async_block_till_done()
|
||||
assert fake_post_hits >= calls
|
||||
|
||||
# Real camera disconnect
|
||||
assert hass.states.get(camera_entity).state == "streaming"
|
||||
response = {
|
||||
"event_type": "disconnection",
|
||||
"device_id": camera_id,
|
||||
"camera_id": camera_id,
|
||||
"event_id": "601dce1560abca1ebad9b723",
|
||||
"push_type": f"{camera_type}-disconnection",
|
||||
}
|
||||
await simulate_webhook(hass, webhook_id, response)
|
||||
|
||||
assert hass.states.get(camera_entity).state == "idle"
|
||||
|
||||
response = {
|
||||
"event_type": "connection",
|
||||
"device_id": camera_id,
|
||||
"camera_id": camera_id,
|
||||
"event_id": "646227f1dc0dfa000ec5f350",
|
||||
"push_type": f"{camera_type}-connection",
|
||||
}
|
||||
await simulate_webhook(hass, webhook_id, response)
|
||||
|
||||
assert hass.states.get(camera_entity).state == "streaming"
|
||||
|
||||
|
||||
async def test_webhook_person_event(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
|
||||
Reference in New Issue
Block a user