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:
@@ -85,11 +85,11 @@ class SensorConfig:
|
|||||||
def load(self):
|
def load(self):
|
||||||
"""Load sensor configuration from JSON file."""
|
"""Load sensor configuration from JSON file."""
|
||||||
if not self.config_file.exists():
|
if not self.config_file.exists():
|
||||||
raise FileNotFoundError(
|
logger.warning(
|
||||||
f"Sensor configuration file not found: {self.config_file}\n"
|
f"Sensor configuration file not found: {self.config_file}\n"
|
||||||
f"Please copy config/sensors.json.example to config/sensors.json "
|
f"Starting with no sensors - use discovery to add sensors"
|
||||||
f"and configure your sensors."
|
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self.config_file, 'r') as f:
|
with open(self.config_file, 'r') as f:
|
||||||
|
|||||||
@@ -125,9 +125,9 @@ class Sensorpajen:
|
|||||||
self.sensor_config = config.SensorConfig()
|
self.sensor_config = config.SensorConfig()
|
||||||
|
|
||||||
if len(self.sensor_config.sensors) == 0:
|
if len(self.sensor_config.sensors) == 0:
|
||||||
self.logger.error("No sensors configured!")
|
self.logger.warning("No sensors configured")
|
||||||
self.logger.error("Please configure sensors in config/sensors.json")
|
self.logger.warning("Starting in discovery-only mode")
|
||||||
sys.exit(1)
|
self.logger.warning("Use 'sensorpajen approve-sensors' to add sensors")
|
||||||
|
|
||||||
# Initialize discovery manager
|
# Initialize discovery manager
|
||||||
self.logger.info("Initializing discovery manager...")
|
self.logger.info("Initializing discovery manager...")
|
||||||
|
|||||||
Reference in New Issue
Block a user