Skip to content

Commit 49e58f7

Browse files
committed
configuration["discovery_filter"] fix test for Docker & HA Add-on
This will need testing and verification with the Docker image and HA Add-on. The HA Add-on also converts identities to a whole string, which Docker keeps it as a dictionary, same for bindkeys. Would and should it not be possible and preferable to make any such type format conversions, if and when required, in the projects themselves, so that the underlying config file can be assumed to be identical across all incarnations of Theengs Gateway?
1 parent 64ff872 commit 49e58f7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

TheengsGateway/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def main() -> None:
5858
if not configuration["host"]:
5959
sys.exit("MQTT host is not specified")
6060

61+
# Make sure discovery_filter is a list, and convert to list
62+
# if it is actually a string (Docker and HA Add-in)
63+
if isinstance(configuration["discovery_filter"], str):
64+
# Convert the string to a list by removing brackets and splitting by commas
65+
configuration["discovery_filter"] = configuration["discovery_filter"].strip("[]").split(",")
66+
6167
# Remove possible discovery filter remnants not required after the RMAC introduction
6268
if "GAEN" in configuration["discovery_filter"]:
6369
configuration["discovery_filter"].remove("GAEN")

TheengsGateway/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ def read_configuration(config_path: Path) -> dict:
311311

312312
def write_configuration(configuration: dict, config_path: Path) -> None:
313313
"""Write a Theengs Gateway configuration to a file."""
314+
# Ensure discovery_filter is a list before writing
315+
if isinstance(configuration.get("discovery_filter"), str):
316+
configuration["discovery_filter"] = configuration["discovery_filter"].strip("[]").split(",")
317+
314318
try:
315319
with config_path.open(encoding="utf-8", mode="w") as config_file:
316320
config_file.write(
@@ -338,5 +342,7 @@ def merge_args_with_config(config: dict, args: argparse.Namespace) -> None:
338342
config[key].extend(
339343
element for element in value if element not in config[key]
340344
)
345+
elif key == "discovery_filter" and isinstance(value, str):
346+
config[key] = value.strip("[]").split(",")
341347
elif key != "config":
342348
config[key] = value

0 commit comments

Comments
 (0)