Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"step": {
"availability": {
"title": "Availability options",
"description": "The availability feature allows a device to report it's availability.",
"description": "The availability feature allows a device to report its availability.",
"data": {
"availability_topic": "Availability topic",
"availability_template": "Availability template",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/purpleair/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class PurpleAirSensorEntityDescription(SensorEntityDescription):
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda sensor: sensor.pressure,
value_fn=lambda sensor: sensor.rssi,
),
PurpleAirSensorEntityDescription(
key="temperature",
Expand Down
7 changes: 7 additions & 0 deletions tests/components/reolink/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _init_host_mock(host_mock: MagicMock) -> None:
host_mock.get_host_data = AsyncMock(return_value=None)
host_mock.get_states = AsyncMock(return_value=None)
host_mock.get_state = AsyncMock()
host_mock.async_get_time = AsyncMock()
host_mock.check_new_firmware = AsyncMock(return_value=False)
host_mock.subscribe = AsyncMock()
host_mock.unsubscribe = AsyncMock(return_value=True)
Expand All @@ -80,12 +81,16 @@ def _init_host_mock(host_mock: MagicMock) -> None:
host_mock.pull_point_request = AsyncMock()
host_mock.set_audio = AsyncMock()
host_mock.set_email = AsyncMock()
host_mock.set_siren = AsyncMock()
host_mock.ONVIF_event_callback = AsyncMock()
host_mock.set_whiteled = AsyncMock()
host_mock.set_state_light = AsyncMock()
host_mock.renew = AsyncMock()
host_mock.get_vod_source = AsyncMock()
host_mock.request_vod_files = AsyncMock()
host_mock.expire_session = AsyncMock()
host_mock.set_volume = AsyncMock()
host_mock.set_hub_audio = AsyncMock()
host_mock.is_nvr = True
host_mock.is_hub = False
host_mock.mac_address = TEST_MAC
Expand Down Expand Up @@ -168,6 +173,7 @@ def _init_host_mock(host_mock: MagicMock) -> None:
0: {"chnID": 0, "aitype": 34615},
"Host": {"pushAlarm": 7},
}
host_mock.baichuan.set_smart_ai = AsyncMock()
host_mock.baichuan.smart_location_list.return_value = [0]
host_mock.baichuan.smart_ai_type_list.return_value = ["people"]
host_mock.baichuan.smart_ai_index.return_value = 1
Expand Down Expand Up @@ -281,6 +287,7 @@ def reolink_chime(reolink_host: MagicMock) -> None:
"visitor": {"switch": 1, "musicId": 2},
}
TEST_CHIME.remove = AsyncMock()
TEST_CHIME.set_option = AsyncMock()

reolink_host.chime_list = [TEST_CHIME]
reolink_host.chime.return_value = TEST_CHIME
Expand Down
58 changes: 26 additions & 32 deletions tests/components/reolink/test_media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_platform_loads_before_config_entry(

async def test_resolve(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
caplog: pytest.LogCaptureFixture,
) -> None:
Expand All @@ -99,30 +99,30 @@ async def test_resolve(
caplog.set_level(logging.DEBUG)

file_id = f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}|{TEST_START}|{TEST_END}"
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL)

play_media = await async_resolve_media(
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
)
assert play_media.mime_type == TEST_MIME_TYPE_MP4

file_id = f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME_MP4}|{TEST_START}|{TEST_END}"
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL2)
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE_MP4, TEST_URL2)

play_media = await async_resolve_media(
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
)
assert play_media.mime_type == TEST_MIME_TYPE_MP4

reolink_connect.is_nvr = False
reolink_host.is_nvr = False

play_media = await async_resolve_media(
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
)
assert play_media.mime_type == TEST_MIME_TYPE_MP4

file_id = f"FILE|{config_entry.entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_FILE_NAME}|{TEST_START}|{TEST_END}"
reolink_connect.get_vod_source.return_value = (TEST_MIME_TYPE, TEST_URL)
reolink_host.get_vod_source.return_value = (TEST_MIME_TYPE, TEST_URL)

play_media = await async_resolve_media(
hass, f"{URI_SCHEME}{DOMAIN}/{file_id}", None
Expand All @@ -132,16 +132,16 @@ async def test_resolve(

async def test_browsing(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test browsing the Reolink three."""
entry_id = config_entry.entry_id
reolink_connect.supported.return_value = 1
reolink_connect.model = "Reolink TrackMix PoE"
reolink_connect.is_nvr = False
reolink_host.supported.return_value = 1
reolink_host.model = "Reolink TrackMix PoE"
reolink_host.is_nvr = False

with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(entry_id) is True
Expand Down Expand Up @@ -184,7 +184,7 @@ async def test_browsing(
mock_status.year = TEST_YEAR
mock_status.month = TEST_MONTH
mock_status.days = (TEST_DAY, TEST_DAY2)
reolink_connect.request_vod_files.return_value = ([mock_status], [])
reolink_host.request_vod_files.return_value = ([mock_status], [])

browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}/{browse_res_sub_id}")
assert browse.domain == DOMAIN
Expand Down Expand Up @@ -223,7 +223,7 @@ async def test_browsing(
mock_vod_file.duration = timedelta(minutes=5)
mock_vod_file.file_name = TEST_FILE_NAME
mock_vod_file.triggers = VOD_trigger.PERSON
reolink_connect.request_vod_files.return_value = ([mock_status], [mock_vod_file])
reolink_host.request_vod_files.return_value = ([mock_status], [mock_vod_file])

browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}/{browse_day_0_id}")

Expand All @@ -236,7 +236,7 @@ async def test_browsing(
)
assert browse.identifier == browse_files_id
assert browse.children[0].identifier == browse_file_id
reolink_connect.request_vod_files.assert_called_with(
reolink_host.request_vod_files.assert_called_with(
int(TEST_CHANNEL),
TEST_START_TIME,
TEST_END_TIME,
Expand All @@ -245,10 +245,10 @@ async def test_browsing(
trigger=None,
)

reolink_connect.model = TEST_HOST_MODEL
reolink_host.model = TEST_HOST_MODEL

# browse event trigger person on a NVR
reolink_connect.is_nvr = True
reolink_host.is_nvr = True
browse_event_person_id = f"EVE|{entry_id}|{TEST_CHANNEL}|{TEST_STREAM}|{TEST_YEAR}|{TEST_MONTH}|{TEST_DAY}|{VOD_trigger.PERSON.name}"

browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}/{browse_day_0_id}")
Expand All @@ -265,7 +265,7 @@ async def test_browsing(
)
assert browse.identifier == browse_files_id
assert browse.children[0].identifier == browse_file_id
reolink_connect.request_vod_files.assert_called_with(
reolink_host.request_vod_files.assert_called_with(
int(TEST_CHANNEL),
TEST_START_TIME,
TEST_END_TIME,
Expand All @@ -274,17 +274,15 @@ async def test_browsing(
trigger=VOD_trigger.PERSON,
)

reolink_connect.is_nvr = False


async def test_browsing_h265_encoding(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera with h265 stream encoding."""
entry_id = config_entry.entry_id
reolink_connect.is_nvr = True
reolink_host.is_nvr = True

with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(entry_id) is True
Expand All @@ -296,10 +294,10 @@ async def test_browsing_h265_encoding(
mock_status.year = TEST_YEAR
mock_status.month = TEST_MONTH
mock_status.days = (TEST_DAY, TEST_DAY2)
reolink_connect.request_vod_files.return_value = ([mock_status], [])
reolink_connect.time.return_value = None
reolink_connect.get_encoding.return_value = "h265"
reolink_connect.supported.return_value = False
reolink_host.request_vod_files.return_value = ([mock_status], [])
reolink_host.time.return_value = None
reolink_host.get_encoding.return_value = "h265"
reolink_host.supported.return_value = False

browse = await async_browse_media(hass, f"{URI_SCHEME}{DOMAIN}/{browse_root_id}")

Expand Down Expand Up @@ -331,7 +329,7 @@ async def test_browsing_h265_encoding(

async def test_browsing_rec_playback_unsupported(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera which does not support playback of recordings."""
Expand All @@ -342,7 +340,7 @@ def test_supported(ch, key):
return False
return True

reolink_connect.supported = test_supported
reolink_host.supported = test_supported

with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
Expand All @@ -356,12 +354,10 @@ def test_supported(ch, key):
assert browse.identifier is None
assert browse.children == []

reolink_connect.supported = lambda ch, key: True # Reset supported function


async def test_browsing_errors(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera errors."""
Expand All @@ -378,15 +374,15 @@ async def test_browsing_errors(

async def test_browsing_not_loaded(
hass: HomeAssistant,
reolink_connect: MagicMock,
reolink_host: MagicMock,
config_entry: MockConfigEntry,
) -> None:
"""Test browsing a Reolink camera integration which is not loaded."""
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.CAMERA]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

reolink_connect.get_host_data.side_effect = ReolinkError("Test error")
reolink_host.get_host_data.side_effect = ReolinkError("Test error")
config_entry2 = MockConfigEntry(
domain=DOMAIN,
unique_id=format_mac(TEST_MAC2),
Expand Down Expand Up @@ -414,5 +410,3 @@ async def test_browsing_not_loaded(
assert browse.title == "Reolink"
assert browse.identifier is None
assert len(browse.children) == 1

reolink_connect.get_host_data.side_effect = None
Loading
Loading