Skip to content

Commit

Permalink
Replace voluptuous with pydantic (#847)
Browse files Browse the repository at this point in the history
* Replace `voluptuous` with `pydantic`

* Typing

* Update
  • Loading branch information
bachya authored Jan 18, 2024
1 parent aed6f53 commit 5405382
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 583 deletions.
674 changes: 250 additions & 424 deletions ecowitt2mqtt/config.py

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions ecowitt2mqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import logging
from typing import Final

from ecowitt2mqtt.helpers.typing import UnitSystemType

__version__ = "2024.01.0"

LOGGER = logging.getLogger(__package__)

# Configuration keys:
CONF_BATTERY_OVERRIDES: Final = "battery_override"
CONF_BATTERY_OVERRIDES: Final = "battery_overrides"
CONF_CONFIG: Final = "config"
CONF_DEFAULT_BATTERY_STRATEGY: Final = "default_battery_strategy"
CONF_DIAGNOSTICS: Final = "diagnostics"
Expand Down Expand Up @@ -196,8 +194,8 @@
LEGACY_ENV_RAW_DATA: Final = "RAW_DATA"

# Unit systems:
UNIT_SYSTEM_IMPERIAL: UnitSystemType = "imperial"
UNIT_SYSTEM_METRIC: UnitSystemType = "metric"
UNIT_SYSTEM_IMPERIAL: Final = "imperial"
UNIT_SYSTEM_METRIC: Final = "metric"
UNIT_SYSTEMS: Final = [UNIT_SYSTEM_IMPERIAL, UNIT_SYSTEM_METRIC]

# Unit classes:
Expand Down
75 changes: 0 additions & 75 deletions ecowitt2mqtt/helpers/config_validation.py

This file was deleted.

3 changes: 1 addition & 2 deletions ecowitt2mqtt/helpers/typing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Define typing helpers."""
from collections.abc import Collection
from datetime import datetime
from typing import Literal, Union
from typing import Union

# pylint: disable=consider-alternative-union-syntax
CalculatedValueType = Union[Collection[str], float, str, datetime, None]
PreCalculatedValueType = Union[float, str]
UnitSystemType = Literal["imperial", "metric"]
21 changes: 8 additions & 13 deletions ecowitt2mqtt/util/meteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
UNIT_SYSTEM_IMPERIAL,
UNIT_SYSTEM_METRIC,
)
from ecowitt2mqtt.helpers.typing import UnitSystemType
from ecowitt2mqtt.util.unit_conversion import TemperatureConverter


Expand Down Expand Up @@ -41,7 +40,7 @@ def get_absolute_humidity_in_metric(


def get_dew_point_meteocalc_object(
temperature: float, relative_humidity: float, unit_system: UnitSystemType
temperature: float, relative_humidity: float, unit_system: str
) -> meteocalc.Temp:
"""Get a dew point meteocalc object.
Expand All @@ -61,7 +60,7 @@ def get_feels_like_meteocalc_object(
temperature: float,
relative_humidity: float,
wind_speed: float,
unit_system: UnitSystemType,
unit_system: str,
) -> meteocalc.Temp:
"""Get a "feels like" meteocalc object.
Expand Down Expand Up @@ -115,7 +114,7 @@ def get_frost_point_meteocalc_object(
def get_heat_index_meteocalc_object(
temperature: float,
relative_humidity: float,
unit_system: UnitSystemType,
unit_system: str,
) -> meteocalc.Temp:
"""Get a heat index meteocalc object.
Expand All @@ -131,9 +130,7 @@ def get_heat_index_meteocalc_object(
return meteocalc.heat_index(temp_obj, relative_humidity)


def get_humidex(
temperature: float, relative_humidity: float, unit_system: UnitSystemType
) -> int:
def get_humidex(temperature: float, relative_humidity: float, unit_system: str) -> int:
"""Get a humidex.
Args:
Expand Down Expand Up @@ -179,7 +176,7 @@ def get_humidex(


def get_relative_strain_index(
temperature: float, relative_humidity: float, unit_system: UnitSystemType
temperature: float, relative_humidity: float, unit_system: str
) -> float:
"""Get a simmer index meteocalc object.
Expand Down Expand Up @@ -220,7 +217,7 @@ def get_relative_strain_index(


def get_simmer_index_meteocalc_object(
temp_obj: meteocalc.Temp, relative_humidity: float, unit_system: UnitSystemType
temp_obj: meteocalc.Temp, relative_humidity: float, unit_system: str
) -> meteocalc.Temp:
"""Get a simmer index meteocalc object.
Expand Down Expand Up @@ -252,7 +249,7 @@ def get_simmer_index_meteocalc_object(


def get_temperature_meteocalc_object(
temperature: float, unit_system: UnitSystemType
temperature: float, unit_system: str
) -> meteocalc.Temp:
"""Get a temperature meteocalc object.
Expand All @@ -271,9 +268,7 @@ def get_temperature_meteocalc_object(


def get_wind_chill_meteocalc_object(
temperature: float,
wind_speed: float,
unit_system: UnitSystemType,
temperature: float, wind_speed: float, unit_system: str
) -> meteocalc.Temp:
"""Get a wind chill meteocalc object.
Expand Down
Loading

0 comments on commit 5405382

Please sign in to comment.