Fixes UniFi Protect reconnect issues (#63047)

This commit is contained in:
Christopher Bailey 2021-12-29 17:39:55 -05:00 committed by GitHub
parent 5eb59092e6
commit 02e59b2f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -1,7 +1,7 @@
"""Shared Entity definition for UniFi Protect Integration."""
from __future__ import annotations
from pyunifiprotect.data import ProtectAdoptableDeviceModel
from pyunifiprotect.data import ProtectAdoptableDeviceModel, StateType
from homeassistant.core import callback
import homeassistant.helpers.device_registry as dr
@ -74,7 +74,7 @@ class ProtectDeviceEntity(Entity):
self.device = devices[self.device.id]
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

View File

@ -8,6 +8,7 @@ from unittest.mock import AsyncMock, Mock, patch
import pytest
from pyunifiprotect.data import Camera as ProtectCamera
from pyunifiprotect.data.devices import CameraChannel
from pyunifiprotect.data.types import StateType
from pyunifiprotect.exceptions import NvrError
from homeassistant.components.camera import (
@ -463,7 +464,7 @@ async def test_camera_ws_update_offline(
# camera goes offline
new_bootstrap = copy(mock_entry.api.bootstrap)
new_camera = camera[0].copy()
new_camera.is_connected = False
new_camera.state = StateType.DISCONNECTED
mock_msg = Mock()
mock_msg.new_obj = new_camera
@ -477,7 +478,7 @@ async def test_camera_ws_update_offline(
assert state and state.state == "unavailable"
# camera comes back online
new_camera.is_connected = True
new_camera.state = StateType.CONNECTED
mock_msg = Mock()
mock_msg.new_obj = new_camera