mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fixes UniFi Protect reconnect issues (#63047)
This commit is contained in:
parent
5eb59092e6
commit
02e59b2f38
@ -1,7 +1,7 @@
|
|||||||
"""Shared Entity definition for UniFi Protect Integration."""
|
"""Shared Entity definition for UniFi Protect Integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pyunifiprotect.data import ProtectAdoptableDeviceModel
|
from pyunifiprotect.data import ProtectAdoptableDeviceModel, StateType
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
import homeassistant.helpers.device_registry as dr
|
import homeassistant.helpers.device_registry as dr
|
||||||
@ -74,7 +74,7 @@ class ProtectDeviceEntity(Entity):
|
|||||||
self.device = devices[self.device.id]
|
self.device = devices[self.device.id]
|
||||||
|
|
||||||
self._attr_available = (
|
self._attr_available = (
|
||||||
self.data.last_update_success and self.device.is_connected
|
self.data.last_update_success and self.device.state == StateType.CONNECTED
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, Mock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
from pyunifiprotect.data import Camera as ProtectCamera
|
from pyunifiprotect.data import Camera as ProtectCamera
|
||||||
from pyunifiprotect.data.devices import CameraChannel
|
from pyunifiprotect.data.devices import CameraChannel
|
||||||
|
from pyunifiprotect.data.types import StateType
|
||||||
from pyunifiprotect.exceptions import NvrError
|
from pyunifiprotect.exceptions import NvrError
|
||||||
|
|
||||||
from homeassistant.components.camera import (
|
from homeassistant.components.camera import (
|
||||||
@ -463,7 +464,7 @@ async def test_camera_ws_update_offline(
|
|||||||
# camera goes offline
|
# camera goes offline
|
||||||
new_bootstrap = copy(mock_entry.api.bootstrap)
|
new_bootstrap = copy(mock_entry.api.bootstrap)
|
||||||
new_camera = camera[0].copy()
|
new_camera = camera[0].copy()
|
||||||
new_camera.is_connected = False
|
new_camera.state = StateType.DISCONNECTED
|
||||||
|
|
||||||
mock_msg = Mock()
|
mock_msg = Mock()
|
||||||
mock_msg.new_obj = new_camera
|
mock_msg.new_obj = new_camera
|
||||||
@ -477,7 +478,7 @@ async def test_camera_ws_update_offline(
|
|||||||
assert state and state.state == "unavailable"
|
assert state and state.state == "unavailable"
|
||||||
|
|
||||||
# camera comes back online
|
# camera comes back online
|
||||||
new_camera.is_connected = True
|
new_camera.state = StateType.CONNECTED
|
||||||
|
|
||||||
mock_msg = Mock()
|
mock_msg = Mock()
|
||||||
mock_msg.new_obj = new_camera
|
mock_msg.new_obj = new_camera
|
||||||
|
Loading…
x
Reference in New Issue
Block a user