Skip to content

Commit

Permalink
fixed conversions/test
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw committed Dec 27, 2024
1 parent abcb571 commit 33506ac
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 54 deletions.
3 changes: 1 addition & 2 deletions aiocloudweather/conversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" A list of all the unit conversions. Many are just approximations."""

from .const import (
LIGHT_LUX,
UnitOfIrradiance,
UnitOfPrecipitationDepth,
UnitOfPressure,
Expand Down Expand Up @@ -52,4 +51,4 @@ def lux_to_wm2(lux: float) -> float:
@unit(UnitOfSpeed.METERS_PER_SECOND)
def mph_to_ms(speed: float) -> float:
"""Convert miles per hour (mph) to meters per second (m/s)."""
return speed * 0.44704
return speed * 0.44704
9 changes: 4 additions & 5 deletions aiocloudweather/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
from typing import Final

from aiocloudweather.conversion import (
celsius_to_fahrenheit,
fahrenheit_to_celsius,
hpa_to_inhg,
in_to_mm,
inhg_to_hpa,
lux_to_wm2,
mm_to_in,
mph_to_ms,
ms_to_mph,
wm2_to_lux,
)
from .const import (
DEGREE,
Expand Down Expand Up @@ -201,6 +196,7 @@ class WeathercloudRawSensor:
UnitOfSpeed.MILES_PER_HOUR: mph_to_ms,
}


@dataclass
class Sensor:
"""Represents a weather sensor."""
Expand All @@ -210,6 +206,7 @@ class Sensor:
value: float
unit: str


@dataclass
class WeatherStation:
"""
Expand Down Expand Up @@ -351,6 +348,8 @@ def from_weathercloud(data: WeathercloudRawSensor) -> "WeatherStation":

value = sensor_field.type(value) # No idea why this is needed
unit = sensor_field.metadata.get("unit")
if unit != PERCENTAGE:
value: float = float(value) / 10 # All values are shifted by 10

sensor_data[sensor_field.name] = Sensor(
name=sensor_field.name,
Expand Down
35 changes: 0 additions & 35 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from aiocloudweather.conversion import (
celsius_to_fahrenheit,
fahrenheit_to_celsius,
hpa_to_inhg,
in_to_mm,
inhg_to_hpa,
lux_to_wm2,
mm_to_in,
mph_to_ms,
ms_to_mph,
wm2_to_lux,
)


Expand Down Expand Up @@ -40,33 +35,3 @@ def test_mph_to_ms():
assert round(mph_to_ms(10), 4) == 4.4704
assert round(mph_to_ms(30), 4) == 13.4112
assert round(mph_to_ms(5), 4) == 2.2352


def test_hpa_to_inhg():
assert round(hpa_to_inhg(1013.25), 2) == 29.92
assert round(hpa_to_inhg(1000), 2) == 29.53
assert round(hpa_to_inhg(950), 2) == 28.05


def test_celsius_to_fahrenheit():
assert round(celsius_to_fahrenheit(0)) == 32
assert round(celsius_to_fahrenheit(100)) == 212
assert round(celsius_to_fahrenheit(10)) == 50


def test_mm_to_in():
assert round(mm_to_in(25.4), 2) == 1
assert round(mm_to_in(63.5), 2) == 2.5
assert round(mm_to_in(12.7), 2) == 0.5


def test_wm2_to_lux():
assert round(wm2_to_lux(1)) == 93
assert round(wm2_to_lux(5)) == 465
assert round(wm2_to_lux(10)) == 930


def test_ms_to_mph():
assert round(ms_to_mph(4.4704), 4) == 10
assert round(ms_to_mph(13.4112), 4) == 30
assert round(ms_to_mph(2.2352), 4) == 5
12 changes: 0 additions & 12 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ def test_weather_station_from_wunderground():
assert weather_station.station_key == "12345"
assert round(weather_station.barometer.value, 2) == 1013.21
assert weather_station.barometer.unit == "hPa"
assert weather_station.barometer.imperial == 29.92
assert weather_station.barometer.imperial_unit == "inHg"
assert weather_station.temperature.value == 22.5
assert weather_station.temperature.unit == "°C"
assert weather_station.temperature.imperial == 72.5
assert weather_station.temperature.imperial_unit == "°F"
assert weather_station.humidity.value == 44
assert weather_station.humidity.unit == "%"
assert weather_station.humidity.imperial == 44
assert weather_station.humidity.imperial_unit == "%"


def test_weather_station_from_weathercloud():
Expand All @@ -61,13 +55,7 @@ def test_weather_station_from_weathercloud():
assert weather_station.station_key == "12345"
assert weather_station.barometer.value == 1013
assert weather_station.barometer.unit == "hPa"
assert round(weather_station.barometer.imperial, 2) == 29.91
assert weather_station.barometer.imperial_unit == "inHg"
assert weather_station.temperature.value == 16
assert weather_station.temperature.unit == "°C"
assert weather_station.temperature.imperial == 60.8
assert weather_station.temperature.imperial_unit == "°F"
assert weather_station.humidity.value == 80
assert weather_station.humidity.unit == "%"
assert weather_station.humidity.imperial == 80
assert weather_station.humidity.imperial_unit == "%"

0 comments on commit 33506ac

Please sign in to comment.