Skip to content

Commit

Permalink
Move diagnostics log level config into ecowitt2mqtt.config
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Jan 19, 2024
1 parent 01a4a6a commit a1bbddf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 0 additions & 4 deletions ecowitt2mqtt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,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())
19 changes: 18 additions & 1 deletion ecowitt2mqtt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a1bbddf

Please sign in to comment.