From fa012069c1d521f9932fc2f1606f0491456c8632 Mon Sep 17 00:00:00 2001 From: Walter Boring Date: Thu, 22 Jan 2026 17:48:44 -0500 Subject: [PATCH] Added enabled config option for the plugin. --- aprsd_weewx_plugin/conf/__init__.py | 4 +- aprsd_weewx_plugin/conf/main.py | 58 +++++++++++++++++++++++++++++ aprsd_weewx_plugin/conf/weewx.py | 5 +++ aprsd_weewx_plugin/weewx.py | 2 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 aprsd_weewx_plugin/conf/main.py diff --git a/aprsd_weewx_plugin/conf/__init__.py b/aprsd_weewx_plugin/conf/__init__.py index 5c91f20..fae2319 100644 --- a/aprsd_weewx_plugin/conf/__init__.py +++ b/aprsd_weewx_plugin/conf/__init__.py @@ -1,6 +1,6 @@ from oslo_config import cfg -from aprsd_weewx_plugin.conf import weewx +from aprsd_weewx_plugin.conf import main CONF = cfg.CONF -weewx.register_opts(CONF) +main.register_opts(CONF) diff --git a/aprsd_weewx_plugin/conf/main.py b/aprsd_weewx_plugin/conf/main.py new file mode 100644 index 0000000..82286b3 --- /dev/null +++ b/aprsd_weewx_plugin/conf/main.py @@ -0,0 +1,58 @@ +from oslo_config import cfg + +weewx_group = cfg.OptGroup( + name="aprsd_weewx_plugin", + title="APRSD Weewx Plugin settings", +) + +weewx_opts = [ + cfg.FloatOpt( + "latitude", + default=None, + help="Latitude of the station you want to report as", + ), + cfg.FloatOpt( + "longitude", + default=None, + help="Longitude of the station you want to report as", + ), + cfg.IntOpt( + "report_interval", + default=60, + help="How long (in seconds) in between weather reports", + ), +] + +weewx_mqtt_opts = [ + cfg.StrOpt( + "mqtt_user", + help="MQTT username", + ), + cfg.StrOpt( + "mqtt_password", + secret=True, + help="MQTT password", + ), + cfg.StrOpt( + "mqtt_host", + help="MQTT Hostname to connect to", + ), + cfg.PortOpt( + "mqtt_port", + help="MQTT Port", + ), +] + +ALL_OPTS = weewx_opts + weewx_mqtt_opts + + +def register_opts(cfg): + cfg.register_group(weewx_group) + cfg.register_opts(ALL_OPTS, group=weewx_group) + + +def list_opts(): + register_opts(cfg.CONF) + return { + weewx_group.name: ALL_OPTS, + } diff --git a/aprsd_weewx_plugin/conf/weewx.py b/aprsd_weewx_plugin/conf/weewx.py index 82286b3..8fa769b 100644 --- a/aprsd_weewx_plugin/conf/weewx.py +++ b/aprsd_weewx_plugin/conf/weewx.py @@ -6,6 +6,11 @@ weewx_group = cfg.OptGroup( ) weewx_opts = [ + cfg.BoolOpt( + "enabled", + default=False, + help="Enable the plugin?", + ), cfg.FloatOpt( "latitude", default=None, diff --git a/aprsd_weewx_plugin/weewx.py b/aprsd_weewx_plugin/weewx.py index 6674372..89dfc42 100644 --- a/aprsd_weewx_plugin/weewx.py +++ b/aprsd_weewx_plugin/weewx.py @@ -44,7 +44,7 @@ class WeewxMQTTPlugin(plugin.APRSDRegexCommandPluginBase): def setup(self): """Ensure that the plugin has been configured.""" - self.enabled = True + self.enabled = CONF.aprsd_weewx_plugin.enabled if not CONF.aprsd_weewx_plugin.mqtt_host: LOG.error("aprsd_weewx_plugin.mqtt_host is not set in config!") self.enabled = False