From c5e618752362c73be86d299b2169bd6e3d24641b Mon Sep 17 00:00:00 2001 From: Fredrik Wahlberg Date: Sun, 28 Dec 2025 09:20:33 +0100 Subject: [PATCH] Allow starting without configured sensors for discovery-only mode - config.SensorConfig.load() now warns instead of raising FileNotFoundError if sensors.json doesn't exist - main.py no longer exits if len(sensors) == 0 - Instead, warns user and suggests using 'sensorpajen approve-sensors' - Application will now start in discovery-only mode - This allows users to use the discovery workflow to add sensors Changes: - config.py: Handle missing sensors.json gracefully - main.py: Log warning instead of error when no sensors configured and continue running (allows discovery to work) Fixes: Unable to start application for initial sensor discovery --- src/sensorpajen/config.py | 6 +++--- src/sensorpajen/main.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sensorpajen/config.py b/src/sensorpajen/config.py index 52ecbbe..2d8f77d 100644 --- a/src/sensorpajen/config.py +++ b/src/sensorpajen/config.py @@ -85,11 +85,11 @@ class SensorConfig: def load(self): """Load sensor configuration from JSON file.""" if not self.config_file.exists(): - raise FileNotFoundError( + logger.warning( f"Sensor configuration file not found: {self.config_file}\n" - f"Please copy config/sensors.json.example to config/sensors.json " - f"and configure your sensors." + f"Starting with no sensors - use discovery to add sensors" ) + return try: with open(self.config_file, 'r') as f: diff --git a/src/sensorpajen/main.py b/src/sensorpajen/main.py index c3b4cc1..1fefb81 100644 --- a/src/sensorpajen/main.py +++ b/src/sensorpajen/main.py @@ -125,9 +125,9 @@ class Sensorpajen: self.sensor_config = config.SensorConfig() if len(self.sensor_config.sensors) == 0: - self.logger.error("No sensors configured!") - self.logger.error("Please configure sensors in config/sensors.json") - sys.exit(1) + self.logger.warning("No sensors configured") + self.logger.warning("Starting in discovery-only mode") + self.logger.warning("Use 'sensorpajen approve-sensors' to add sensors") # Initialize discovery manager self.logger.info("Initializing discovery manager...")