diff --git a/aiocloudweather/conversion.py b/aiocloudweather/conversion.py index 21f65bd..ffa6b0d 100644 --- a/aiocloudweather/conversion.py +++ b/aiocloudweather/conversion.py @@ -1,7 +1,6 @@ """ A list of all the unit conversions. Many are just approximations.""" from .const import ( - LIGHT_LUX, UnitOfIrradiance, UnitOfPrecipitationDepth, UnitOfPressure, @@ -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 \ No newline at end of file + return speed * 0.44704 diff --git a/aiocloudweather/station.py b/aiocloudweather/station.py index 449c5dc..fdd028c 100644 --- a/aiocloudweather/station.py +++ b/aiocloudweather/station.py @@ -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, @@ -201,6 +196,7 @@ class WeathercloudRawSensor: UnitOfSpeed.MILES_PER_HOUR: mph_to_ms, } + @dataclass class Sensor: """Represents a weather sensor.""" @@ -210,6 +206,7 @@ class Sensor: value: float unit: str + @dataclass class WeatherStation: """ @@ -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, diff --git a/tests/test_conversion.py b/tests/test_conversion.py index c3f109f..3c5bbf4 100644 --- a/tests/test_conversion.py +++ b/tests/test_conversion.py @@ -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, ) @@ -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 diff --git a/tests/test_sensor.py b/tests/test_sensor.py index be275f7..9dcf7d2 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -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(): @@ -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 == "%"