Skip to content

Commit

Permalink
Merge pull request #270 from quartiq/py-client
Browse files Browse the repository at this point in the history
py: fix json loads on get/clear
  • Loading branch information
jordens authored Dec 4, 2024
2 parents 0d58b18 + 6b0173e commit 89a1ac5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
20 changes: 12 additions & 8 deletions py/miniconf-mqtt/miniconf/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
)
)


Expand Down Expand Up @@ -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}")
Expand Down
18 changes: 10 additions & 8 deletions py/miniconf-mqtt/miniconf/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
)
)


Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion py/miniconf-mqtt/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" },
Expand Down

0 comments on commit 89a1ac5

Please sign in to comment.