From 40d2b36b037dc9d3efb4eccdea967ab2d77d90b9 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 28 Jun 2024 08:49:45 -0700 Subject: [PATCH] fix: don't automatically set default locale --- ecowitt2mqtt/__main__.py | 3 +-- ecowitt2mqtt/config.py | 3 +-- ecowitt2mqtt/const.py | 1 - ecowitt2mqtt/core.py | 5 +++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ecowitt2mqtt/__main__.py b/ecowitt2mqtt/__main__.py index 50e07b65..f66d0b22 100644 --- a/ecowitt2mqtt/__main__.py +++ b/ecowitt2mqtt/__main__.py @@ -46,7 +46,6 @@ DEFAULT_BOOLEAN_BATTERY_TRUE_VALUE, DEFAULT_ENDPOINT, DEFAULT_HASS_DISCOVERY_PREFIX, - DEFAULT_LOCALE, DEFAULT_MQTT_PORT, DEFAULT_PORT, ENV_BATTERY_OVERRIDES, @@ -252,7 +251,7 @@ def get_cli_arguments(args: list[str]) -> dict[str, Any]: parser.add_argument( "--locale", dest=CONF_LOCALE, - help=f"The locale to use (default: {DEFAULT_LOCALE})", + help=f"The locale to set (default: system default)", metavar=CONF_LOCALE, ) parser.add_argument( diff --git a/ecowitt2mqtt/config.py b/ecowitt2mqtt/config.py index 44817625..e4f9b519 100644 --- a/ecowitt2mqtt/config.py +++ b/ecowitt2mqtt/config.py @@ -31,7 +31,6 @@ DEFAULT_BOOLEAN_BATTERY_TRUE_VALUE, DEFAULT_ENDPOINT, DEFAULT_HASS_DISCOVERY_PREFIX, - DEFAULT_LOCALE, DEFAULT_MQTT_PORT, DEFAULT_PORT, ENV_BATTERY_OVERRIDES, @@ -170,7 +169,7 @@ class Config(BaseModel): uuid: str = Field(default_factory=lambda: uuid4().hex) # Misc. parameters: - locale: str = DEFAULT_LOCALE + locale: str | None = None @model_validator(mode="before") @classmethod diff --git a/ecowitt2mqtt/const.py b/ecowitt2mqtt/const.py index e4f0cd13..40a46fa3 100644 --- a/ecowitt2mqtt/const.py +++ b/ecowitt2mqtt/const.py @@ -146,7 +146,6 @@ DEFAULT_BOOLEAN_BATTERY_TRUE_VALUE: Final = 1 DEFAULT_ENDPOINT: Final = "/data/report" DEFAULT_HASS_DISCOVERY_PREFIX: Final = "homeassistant" -DEFAULT_LOCALE: Final = "en_US.UTF-8" DEFAULT_MQTT_PORT: Final = 1883 DEFAULT_PORT: Final = 8080 diff --git a/ecowitt2mqtt/core.py b/ecowitt2mqtt/core.py index 322b6bf4..97121545 100644 --- a/ecowitt2mqtt/core.py +++ b/ecowitt2mqtt/core.py @@ -63,8 +63,9 @@ def __init__(self, params: dict[str, Any]) -> None: LOGGER.debug("Input CLI options/environment variables: %s", params) LOGGER.debug("Configs loaded: %s", self.configs) - LOGGER.debug("Setting locale: %s", self.configs.default_config.locale) - locale.setlocale(locale.LC_ALL, self.configs.default_config.locale) + if locale := self.configs.default_config.locale: + LOGGER.debug("Setting locale: %s", self.configs.default_config.locale) + locale.setlocale(locale.LC_ALL, locale) self.runtime = Runtime(self)