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_CAMERAS,
|
||||||
DATA_EVENTS,
|
DATA_EVENTS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
EVENT_TYPE_CONNECTION,
|
||||||
|
EVENT_TYPE_DISCONNECTION,
|
||||||
EVENT_TYPE_LIGHT_MODE,
|
EVENT_TYPE_LIGHT_MODE,
|
||||||
EVENT_TYPE_OFF,
|
EVENT_TYPE_OFF,
|
||||||
EVENT_TYPE_ON,
|
EVENT_TYPE_ON,
|
||||||
@@ -123,7 +125,13 @@ class NetatmoCamera(NetatmoModuleEntity, Camera):
|
|||||||
"""Entity created."""
|
"""Entity created."""
|
||||||
await super().async_added_to_hass()
|
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(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass,
|
self.hass,
|
||||||
@@ -146,12 +154,19 @@ class NetatmoCamera(NetatmoModuleEntity, Camera):
|
|||||||
data["home_id"] == self.home.entity_id
|
data["home_id"] == self.home.entity_id
|
||||||
and data["camera_id"] == self.device.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._attr_is_streaming = False
|
||||||
self._monitoring = False
|
self._monitoring = False
|
||||||
elif data[WEBHOOK_PUSH_TYPE] in (
|
elif data[WEBHOOK_PUSH_TYPE] in (
|
||||||
"NACamera-on",
|
"NACamera-on",
|
||||||
|
"NOCamera-on",
|
||||||
WEBHOOK_NACAMERA_CONNECTION,
|
WEBHOOK_NACAMERA_CONNECTION,
|
||||||
|
"NOCamera-connection",
|
||||||
):
|
):
|
||||||
self._attr_is_streaming = True
|
self._attr_is_streaming = True
|
||||||
self._monitoring = 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_BIG_MOVE = "tag_big_move"
|
||||||
EVENT_TYPE_DOOR_TAG_OPEN = "tag_open"
|
EVENT_TYPE_DOOR_TAG_OPEN = "tag_open"
|
||||||
EVENT_TYPE_DOOR_TAG_SMALL_MOVE = "tag_small_move"
|
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_OFF = "off"
|
||||||
EVENT_TYPE_ON = "on"
|
EVENT_TYPE_ON = "on"
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ async def test_setup_component_with_webhook(
|
|||||||
|
|
||||||
assert hass.states.get(camera_entity_indoor).state == "streaming"
|
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"
|
assert hass.states.get(camera_entity_outdoor).state == "streaming"
|
||||||
response = {
|
response = {
|
||||||
"event_type": "off",
|
"event_type": "off",
|
||||||
@@ -100,8 +100,7 @@ async def test_setup_component_with_webhook(
|
|||||||
}
|
}
|
||||||
await simulate_webhook(hass, webhook_id, response)
|
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 == "idle"
|
||||||
assert hass.states.get(camera_entity_outdoor).state == "streaming"
|
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"event_type": "on",
|
"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]
|
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(
|
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:
|
) -> None:
|
||||||
"""Test webhook event on camera reconnect."""
|
"""Test webhook event on camera reconnect."""
|
||||||
fake_post_hits = 0
|
fake_post_hits = 0
|
||||||
@@ -472,7 +482,7 @@ async def test_camera_reconnect_webhook(
|
|||||||
|
|
||||||
# Fake camera reconnect
|
# Fake camera reconnect
|
||||||
response = {
|
response = {
|
||||||
"push_type": "NACamera-connection",
|
"push_type": f"{camera_type}-connection",
|
||||||
}
|
}
|
||||||
await simulate_webhook(hass, webhook_id, response)
|
await simulate_webhook(hass, webhook_id, response)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@@ -484,6 +494,30 @@ async def test_camera_reconnect_webhook(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert fake_post_hits >= calls
|
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(
|
async def test_webhook_person_event(
|
||||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||||
|
|||||||
Reference in New Issue
Block a user