mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Fix reolink media source data access (#114593)
* Add test * Fix reolink media source data access
This commit is contained in:
parent
acdb3cc7a2
commit
b1af590eed
@ -46,7 +46,6 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
"""Initialize ReolinkVODMediaSource."""
|
"""Initialize ReolinkVODMediaSource."""
|
||||||
super().__init__(DOMAIN)
|
super().__init__(DOMAIN)
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.data: dict[str, ReolinkData] = hass.data[DOMAIN]
|
|
||||||
|
|
||||||
async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
|
async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
|
||||||
"""Resolve media to a url."""
|
"""Resolve media to a url."""
|
||||||
@ -57,7 +56,8 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
_, config_entry_id, channel_str, stream_res, filename = identifier
|
_, config_entry_id, channel_str, stream_res, filename = identifier
|
||||||
channel = int(channel_str)
|
channel = int(channel_str)
|
||||||
|
|
||||||
host = self.data[config_entry_id].host
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
|
host = data[config_entry_id].host
|
||||||
|
|
||||||
vod_type = VodRequestType.RTMP
|
vod_type = VodRequestType.RTMP
|
||||||
if host.api.is_nvr:
|
if host.api.is_nvr:
|
||||||
@ -130,7 +130,8 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
if config_entry.state != ConfigEntryState.LOADED:
|
if config_entry.state != ConfigEntryState.LOADED:
|
||||||
continue
|
continue
|
||||||
channels: list[str] = []
|
channels: list[str] = []
|
||||||
host = self.data[config_entry.entry_id].host
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
|
host = data[config_entry.entry_id].host
|
||||||
entities = er.async_entries_for_config_entry(
|
entities = er.async_entries_for_config_entry(
|
||||||
entity_reg, config_entry.entry_id
|
entity_reg, config_entry.entry_id
|
||||||
)
|
)
|
||||||
@ -187,7 +188,8 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
self, config_entry_id: str, channel: int
|
self, config_entry_id: str, channel: int
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""Allow the user to select the high or low playback resolution, (low loads faster)."""
|
"""Allow the user to select the high or low playback resolution, (low loads faster)."""
|
||||||
host = self.data[config_entry_id].host
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
|
host = data[config_entry_id].host
|
||||||
|
|
||||||
main_enc = await host.api.get_encoding(channel, "main")
|
main_enc = await host.api.get_encoding(channel, "main")
|
||||||
if main_enc == "h265":
|
if main_enc == "h265":
|
||||||
@ -236,7 +238,8 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
self, config_entry_id: str, channel: int, stream: str
|
self, config_entry_id: str, channel: int, stream: str
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""Return all days on which recordings are available for a reolink camera."""
|
"""Return all days on which recordings are available for a reolink camera."""
|
||||||
host = self.data[config_entry_id].host
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
|
host = data[config_entry_id].host
|
||||||
|
|
||||||
# We want today of the camera, not necessarily today of the server
|
# We want today of the camera, not necessarily today of the server
|
||||||
now = host.api.time() or await host.api.async_get_time()
|
now = host.api.time() or await host.api.async_get_time()
|
||||||
@ -288,7 +291,8 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
day: int,
|
day: int,
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""Return all recording files on a specific day of a Reolink camera."""
|
"""Return all recording files on a specific day of a Reolink camera."""
|
||||||
host = self.data[config_entry_id].host
|
data: dict[str, ReolinkData] = self.hass.data[DOMAIN]
|
||||||
|
host = data[config_entry_id].host
|
||||||
|
|
||||||
start = dt.datetime(year, month, day, hour=0, minute=0, second=0)
|
start = dt.datetime(year, month, day, hour=0, minute=0, second=0)
|
||||||
end = dt.datetime(year, month, day, hour=23, minute=59, second=59)
|
end = dt.datetime(year, month, day, hour=23, minute=59, second=59)
|
||||||
|
@ -65,6 +65,17 @@ async def setup_component(hass: HomeAssistant) -> None:
|
|||||||
assert await async_setup_component(hass, MEDIA_STREAM_DOMAIN, {})
|
assert await async_setup_component(hass, MEDIA_STREAM_DOMAIN, {})
|
||||||
|
|
||||||
|
|
||||||
|
async def test_platform_loads_before_config_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_setup_entry: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test that the platform can be loaded before the config entry."""
|
||||||
|
# Fake that the config entry is not loaded before the media_source platform
|
||||||
|
assert await async_setup_component(hass, DOMAIN, {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert mock_setup_entry.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_resolve(
|
async def test_resolve(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
reolink_connect: MagicMock,
|
reolink_connect: MagicMock,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user