diff --git a/ecowitt2mqtt/__main__.py b/ecowitt2mqtt/__main__.py index aa7ea47c..4fa84c3e 100644 --- a/ecowitt2mqtt/__main__.py +++ b/ecowitt2mqtt/__main__.py @@ -397,9 +397,5 @@ def main() -> None: cli_arguments = get_cli_arguments(sys.argv[1:]) env_vars = get_env_vars() params: dict[str, Any] = env_vars | cli_arguments - - if CONF_DIAGNOSTICS in params: - params[CONF_VERBOSE] = True - ecowitt = Ecowitt(params) uvloop.run(ecowitt.async_start()) diff --git a/ecowitt2mqtt/config.py b/ecowitt2mqtt/config.py index 1a9f6e77..a0eac9d6 100644 --- a/ecowitt2mqtt/config.py +++ b/ecowitt2mqtt/config.py @@ -20,11 +20,13 @@ from ecowitt2mqtt.const import ( CONF_BATTERY_OVERRIDES, CONF_CONFIG, + CONF_DIAGNOSTICS, CONF_GATEWAYS, CONF_HASS_DISCOVERY, CONF_MQTT_BROKER, CONF_MQTT_PASSWORD, CONF_MQTT_USERNAME, + CONF_VERBOSE, DEFAULT_ENDPOINT, DEFAULT_HASS_DISCOVERY_PREFIX, DEFAULT_MQTT_PORT, @@ -155,12 +157,27 @@ def get_raw_battery_overrides(cls, data: dict[str, Any]) -> dict[str, Any]: data: The config data. Returns: - The config data with the raw battery overrides. + The potentially altered config data. """ if battery_overrides_env_var := os.getenv(ENV_BATTERY_OVERRIDES): data[CONF_BATTERY_OVERRIDES] = battery_overrides_env_var return data + @model_validator(mode="before") + @classmethod + def set_diagnostics_verbosity(cls, data: dict[str, Any]) -> dict[str, Any]: + """Set verbose when diagnostics is set. + + Args: + data: The config data. + + Returns: + The potentially altered config data. + """ + if data.get(CONF_DIAGNOSTICS): + data[CONF_VERBOSE] = True + return data + @field_validator("battery_overrides", mode="before") @classmethod def validate_battery_overrides(