From d6665da6e51d696be7eb6976c404ec35bfa4d51d Mon Sep 17 00:00:00 2001 From: Raj Laud Date: Mon, 26 Oct 2020 17:43:39 -0500 Subject: [PATCH] Fix bug comparing limit to cache limit --- pysqueezebox/server.py | 14 +++++++++++--- setup.py | 2 +- tests/test_integration.py | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pysqueezebox/server.py b/pysqueezebox/server.py index 1565efe..79c0ccf 100644 --- a/pysqueezebox/server.py +++ b/pysqueezebox/server.py @@ -292,9 +292,17 @@ async def async_get_category(self, category, limit=None, search=None): status = await self.async_status() if "lastscan" in status and self.__dict__[category] is not None: cached_category = self.__dict__[category] - if status["lastscan"] <= cached_category[0] and limit <= cached_category[1]: - _LOGGER.debug("Using cached category %s", category) - return self.__dict__[category][2] + if status["lastscan"] <= cached_category[0]: + if limit is None: + if cached_category[1] is None: + _LOGGER.debug("Using cached category %s", category) + return self.__dict__[category][2] + else: + if cached_category[1] is None or limit <= cached_category[1]: + _LOGGER.debug( + "Using cached category %s with limit %s", category, limit + ) + return self.__dict__[category][2][:limit] _LOGGER.debug("Updating cache for category %s", category) if self.__dict__[category] is not None: diff --git a/setup.py b/setup.py index 08f677c..6049a28 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pysqueezebox", - version="0.5.3", + version="0.5.4", license="apache-2.0", author="Raj Laud", author_email="raj.laud@gmail.com", diff --git a/tests/test_integration.py b/tests/test_integration.py index 2600ea2..0bd9ec3 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -233,10 +233,13 @@ async def test_browse(lms): for category in categories: await lookup_helper(lms, category[0], category[1]) + # test lookup without limit + await lookup_helper(lms, "artists", "artist_id") -async def lookup_helper(lms, category, id_type): + +async def lookup_helper(lms, category, id_type, limit=BROWSE_LIMIT): """Lookup a known item and make sure the name matches.""" - result = await lms.async_browse(category, limit=BROWSE_LIMIT) + result = await lms.async_browse(category, limit) assert result["title"] is not None assert len(result["items"]) > 0 browse_id = result["items"][0].get("id")