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
This commit is contained in:
2025-12-28 09:20:33 +01:00
parent 4000d0972e
commit c5e6187523
2 changed files with 6 additions and 6 deletions

View File

@@ -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:

View File

@@ -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...")