Skip to content

Commit

Permalink
Skip update if kodi is not connected.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed Dec 19, 2021
1 parent f24a8a8 commit 5433e49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/kodi_recently_added/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def state(self) -> Optional[str]:
return self._state

async def async_update(self) -> None:
if not self.kodi._conn.connected:
_LOGGER.debug("Kodi is not connected, skipping update.")
return

result = None
try:
result = await self.kodi.call_method(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Tests for entities.py."""
from unittest import mock

import pykodi

from custom_components.kodi_recently_added.entities import KodiMediaEntity


Expand Down Expand Up @@ -74,3 +76,22 @@ def test_get_web_url_non_http():
path = "nfs://127.0.0.2/volume1/image.png"
expected = "http://username:password@127.0.0.1:8080/image/image%3A%2F%2Fnfs%253A%252F%252F127.0.0.2%252Fvolume1%252Fimage.png"
assert expected == entity.get_web_url(path)


@mock.patch("custom_components.kodi_recently_added.entities._LOGGER")
async def test_async_update_skips_if_not_connected(logger):
"""Test we skip the update if kodi is not connected."""
config = {
"host": "127.0.0.1",
"password": "password",
"port": 8080,
"ssl": False,
"username": "username",
}
kodi = mock.Mock(spec=pykodi.Kodi)
kodi._conn = mock.Mock(connected=False)
entity = KodiMediaEntity(kodi, config)
await entity.async_update()
assert kodi.call_method.called is False
expected_call = mock.call("Kodi is not connected, skipping update.")
assert expected_call == logger.debug.call_args

0 comments on commit 5433e49

Please sign in to comment.