From 6b0173ea5e540e1b3c3916bb6c7701cc06db47f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 4 Dec 2024 13:21:22 +0100 Subject: [PATCH] py: fix json loads on get/clear --- py/miniconf-mqtt/miniconf/async_.py | 20 ++++++++++++-------- py/miniconf-mqtt/miniconf/sync.py | 18 ++++++++++-------- py/miniconf-mqtt/pyproject.toml | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/py/miniconf-mqtt/miniconf/async_.py b/py/miniconf-mqtt/miniconf/async_.py index 1d943921..e0342ee3 100644 --- a/py/miniconf-mqtt/miniconf/async_.py +++ b/py/miniconf-mqtt/miniconf/async_.py @@ -195,7 +195,9 @@ async def get(self, path: str, **kwargs): Args: path: The path to get. Must be a leaf node. """ - return await self._do(topic=f"{self.prefix}/settings{path}", **kwargs) + return json.loads( + await self._do(topic=f"{self.prefix}/settings{path}", **kwargs) + ) async def clear(self, path: str, response=True, **kwargs): """Clear retained value from a path. @@ -205,11 +207,13 @@ async def clear(self, path: str, response=True, **kwargs): Args: path: The path to clear. Must be a leaf node. """ - return await self._do( - f"{self.prefix}/settings{path}", - retain=True, - response=response, - **kwargs, + return json.loads( + await self._do( + f"{self.prefix}/settings{path}", + retain=True, + response=response, + **kwargs, + ) ) @@ -406,8 +410,8 @@ async def _handle_commands(interface, commands, retain): path, value = arg.split("=", 1) path = current.normalize(path) if not value: - await interface.clear(path) - print(f"CLEAR '{path}'") + value = await interface.clear(path) + print(f"CLEAR {path}={value}") else: await interface.set(path, json.loads(value), retain) print(f"{path}={value}") diff --git a/py/miniconf-mqtt/miniconf/sync.py b/py/miniconf-mqtt/miniconf/sync.py index fe8756ce..7880b350 100644 --- a/py/miniconf-mqtt/miniconf/sync.py +++ b/py/miniconf-mqtt/miniconf/sync.py @@ -173,7 +173,7 @@ def get(self, path: str, **kwargs): Args: path: The path to get. Must be a leaf node. """ - return self._do(topic=f"{self.prefix}/settings{path}", **kwargs) + return json.loads(self._do(topic=f"{self.prefix}/settings{path}", **kwargs)) def clear(self, path: str, response=True, **kwargs): """Clear retained value from a path. @@ -183,11 +183,13 @@ def clear(self, path: str, response=True, **kwargs): Args: path: The path to clear. Must be a leaf node. """ - return self._do( - f"{self.prefix}/settings{path}", - retain=True, - response=response, - **kwargs, + return json.loads( + self._do( + f"{self.prefix}/settings{path}", + retain=True, + response=response, + **kwargs, + ) ) @@ -306,8 +308,8 @@ def _handle_commands(interface, commands, retain): path, value = arg.split("=", 1) path = current.normalize(path) if not value: - interface.clear(path) - print(f"CLEAR '{path}'") + value = interface.clear(path) + print(f"CLEAR {path}={value}") else: interface.set(path, json.loads(value), retain) print(f"{path}={value}") diff --git a/py/miniconf-mqtt/pyproject.toml b/py/miniconf-mqtt/pyproject.toml index 7a1390ec..9f6fa462 100644 --- a/py/miniconf-mqtt/pyproject.toml +++ b/py/miniconf-mqtt/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "miniconf-mqtt" # Note: keep this in sync with Cargo.toml -version = "0.18.0" +version = "0.18.2" description = "Utilities for configuring Miniconf-configurable devices" authors = [ { name = "Ryan Summers", email = "ryan.summers@vertigo-designs.com" },