Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw committed May 26, 2024
1 parent 1b9826e commit c95d0bf
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .github/FUNDING.yml

This file was deleted.

4 changes: 2 additions & 2 deletions aiocloudweather/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def lux_to_wm2(lux: float) -> float:

@unit(UnitOfSpeed.METERS_PER_SECOND)
def mph_to_ms(speed: float) -> float:
return speed * 2.23694
return speed * 0.44704


@unit(UnitOfPressure.INHG)
Expand All @@ -56,4 +56,4 @@ def wm2_to_lux(lux: float) -> float:

@unit(UnitOfSpeed.MILES_PER_HOUR)
def ms_to_mph(speed: float) -> float:
return speed * 0.44704
return speed * 2.23694
32 changes: 29 additions & 3 deletions aiocloudweather/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class WeathercloudRawSensor:

@dataclass
class Sensor:
""" """
"""Represents a weather sensor."""

metric: float
metric_unit: str
Expand All @@ -181,7 +181,7 @@ class Sensor:
@dataclass
class WeatherStation:
"""
Weather data.
Represents a weather station with various sensor readings.
"""

station_id: str
Expand All @@ -206,6 +206,19 @@ class WeatherStation:

@staticmethod
def from_wunderground(data: WundergroundRawSensor) -> "WeatherStation":
"""
Converts raw sensor data from the Wunderground API into a WeatherStation object.
Args:
data (WundergroundRawSensor): The raw sensor data from the Wunderground API.
Returns:
WeatherStation: The converted WeatherStation object.
Raises:
TypeError: If there is an error converting the sensor data.
"""
sensor_data = {}
for field in fields(data):
if field.name == "station_id" or field.name == "station_key":
Expand Down Expand Up @@ -248,6 +261,19 @@ def from_wunderground(data: WundergroundRawSensor) -> "WeatherStation":

@staticmethod
def from_weathercloud(data: WeathercloudRawSensor) -> "WeatherStation":
"""
Converts raw sensor data from the Weathercloud.net API into a WeatherStation object.
Args:
data (WeathercloudRawSensor): The raw sensor data from the Weathercloud.net API.
Returns:
WeatherStation: The converted WeatherStation object.
Raises:
TypeError: If there is an error converting the sensor data.
"""
sensor_data = {}
for field in fields(data):
if field.name == "station_id" or field.name == "station_key":
Expand All @@ -257,11 +283,11 @@ def from_weathercloud(data: WeathercloudRawSensor) -> "WeatherStation":
continue

value = field.type(value) # No idea why this is needed
value = float(value) / 10 # All values are multiplied by 10
unit = field.metadata.get("unit")
conversion_func = metric_to_imperial.get(unit)

if conversion_func:
value = float(value) / 10 # All values are shifted by 10
try:
converted_value = conversion_func(float(value))
except TypeError as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
description="Python wrapper for Cloud Weather protocols",
long_description=README_FILE.read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
packages=find_packages(exclude=["tests.*", "tests", "misc"]),
packages=find_packages(exclude=["tests.*", "tests"]),
package_data={"aiocoudweather": ["py.typed"]},
python_requires=">=3.12",
install_requires=["aiohttp>3"],
Expand Down
100 changes: 100 additions & 0 deletions tests/data/weathercloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/v01/set/wid/12345/key/12345/bar/10101/temp/149/hum/95/wdir/265/wspd/3/dew/140/heat/149/rainrate/0/rain/6/uvi/0/solarrad/224
/v01/set/wid/12345/key/12345/bar/10168/temp/168/hum/85/wdir/277/wspd/0/dew/142/heat/168/rainrate/0/rain/0/uvi/20/solarrad/2546
/v01/set/wid/12345/key/12345/bar/10101/temp/151/hum/95/wdir/279/wspd/0/dew/142/heat/151/rainrate/0/rain/6/uvi/10/solarrad/552
/v01/set/wid/12345/key/12345/bar/10166/temp/145/hum/93/wdir/292/wspd/0/dew/133/heat/145/rainrate/0/rain/45/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10136/temp/138/hum/87/wdir/284/wspd/0/dew/116/heat/138/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10123/temp/141/hum/98/wdir/91/wspd/6/dew/137/heat/141/rainrate/41/rain/148/uvi/0/solarrad/135
/v01/set/wid/12345/key/12345/bar/10168/temp/129/hum/96/wdir/271/wspd/1/dew/122/heat/129/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10112/temp/182/hum/87/wdir/77/wspd/3/dew/159/heat/182/rainrate/0/rain/6/uvi/20/solarrad/1169
/v01/set/wid/12345/key/12345/bar/10152/temp/182/hum/85/wdir/273/wspd/0/dew/156/heat/182/rainrate/0/rain/38/uvi/20/solarrad/2268
/v01/set/wid/12345/key/12345/bar/10110/temp/203/hum/77/wdir/26/wspd/1/dew/161/heat/203/rainrate/0/rain/6/uvi/10/solarrad/977
/v01/set/wid/12345/key/12345/bar/10157/temp/194/hum/70/wdir/267/wspd/3/dew/137/heat/194/rainrate/0/rain/0/uvi/30/solarrad/3196
/v01/set/wid/12345/key/12345/bar/10152/temp/191/hum/84/wdir/299/wspd/0/dew/163/heat/191/rainrate/0/rain/38/uvi/20/solarrad/2426
/v01/set/wid/12345/key/12345/bar/10166/temp/146/hum/92/wdir/295/wspd/0/dew/133/heat/146/rainrate/0/rain/45/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10168/temp/142/hum/95/wdir/286/wspd/0/dew/133/heat/142/rainrate/0/rain/45/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10168/temp/127/hum/97/wdir/279/wspd/0/dew/122/heat/127/rainrate/0/rain/0/uvi/0/solarrad/3
/v01/set/wid/12345/key/12345/bar/10166/temp/132/hum/96/wdir/265/wspd/2/dew/125/heat/132/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10141/temp/140/hum/99/wdir/100/wspd/10/dew/138/heat/140/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10157/temp/195/hum/70/wdir/267/wspd/0/dew/138/heat/195/rainrate/0/rain/0/uvi/20/solarrad/1391
/v01/set/wid/12345/key/12345/bar/10166/temp/175/hum/82/wdir/254/wspd/8/dew/143/heat/175/rainrate/0/rain/0/uvi/30/solarrad/5263
/v01/set/wid/12345/key/12345/bar/10156/temp/226/hum/60/wdir/252/wspd/3/dew/144/heat/226/rainrate/0/rain/0/uvi/20/solarrad/1445
/v01/set/wid/12345/key/12345/bar/10106/temp/141/hum/90/wdir/301/wspd/0/dew/124/heat/141/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10141/temp/120/hum/95/wdir/272/wspd/0/dew/112/heat/120/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10157/temp/193/hum/71/wdir/324/wspd/0/dew/138/heat/193/rainrate/0/rain/0/uvi/20/solarrad/1760
/v01/set/wid/12345/key/12345/bar/10129/temp/185/hum/77/wdir/255/wspd/1/dew/143/heat/185/rainrate/0/rain/0/uvi/10/solarrad/404
/v01/set/wid/12345/key/12345/bar/10168/temp/149/hum/92/wdir/270/wspd/0/dew/136/heat/149/rainrate/0/rain/0/uvi/10/solarrad/718
/v01/set/wid/12345/key/12345/bar/10161/temp/225/hum/69/wdir/280/wspd/1/dew/165/heat/225/rainrate/0/rain/0/uvi/50/solarrad/6744
/v01/set/wid/12345/key/12345/bar/10170/temp/168/hum/86/wdir/266/wspd/1/dew/144/heat/168/rainrate/0/rain/0/uvi/20/solarrad/1656
/v01/set/wid/12345/key/12345/bar/10168/temp/126/hum/97/wdir/302/wspd/0/dew/121/heat/126/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10169/temp/202/hum/64/wdir/82/wspd/3/dew/131/heat/202/rainrate/0/rain/2/uvi/30/solarrad/2369
/v01/set/wid/12345/key/12345/bar/10160/temp/152/hum/91/wdir/274/wspd/0/dew/137/heat/152/rainrate/0/rain/45/uvi/0/solarrad/12
/v01/set/wid/12345/key/12345/bar/10097/temp/145/hum/90/wdir/257/wspd/5/dew/128/heat/145/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10101/temp/149/hum/95/wdir/242/wspd/5/dew/140/heat/149/rainrate/0/rain/6/uvi/0/solarrad/245
/v01/set/wid/12345/key/12345/bar/10157/temp/223/hum/65/wdir/252/wspd/0/dew/153/heat/223/rainrate/0/rain/0/uvi/30/solarrad/3688
/v01/set/wid/12345/key/12345/bar/10139/temp/142/hum/99/wdir/102/wspd/1/dew/140/heat/142/rainrate/0/rain/229/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10104/temp/142/hum/90/wdir/267/wspd/2/dew/125/heat/142/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10144/temp/140/hum/99/wdir/107/wspd/0/dew/138/heat/140/rainrate/0/rain/2/uvi/0/solarrad/11
/v01/set/wid/12345/key/12345/bar/10135/temp/146/hum/87/wdir/286/wspd/0/dew/124/heat/146/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10133/temp/203/hum/70/wdir/270/wspd/5/dew/146/heat/203/rainrate/0/rain/0/uvi/10/solarrad/1361
/v01/set/wid/12345/key/12345/bar/10143/temp/118/hum/97/wdir/273/wspd/0/dew/113/heat/118/rainrate/0/rain/0/uvi/0/solarrad/1
/v01/set/wid/12345/key/12345/bar/10148/temp/133/hum/96/wdir/281/wspd/0/dew/126/heat/133/rainrate/0/rain/0/uvi/10/solarrad/823
/v01/set/wid/12345/key/12345/bar/10144/temp/118/hum/97/wdir/273/wspd/0/dew/113/heat/118/rainrate/0/rain/0/uvi/0/solarrad/8
/v01/set/wid/12345/key/12345/bar/10153/temp/224/hum/60/wdir/270/wspd/1/dew/142/heat/224/rainrate/0/rain/0/uvi/20/solarrad/1579
/v01/set/wid/12345/key/12345/bar/10128/temp/193/hum/75/wdir/267/wspd/3/dew/147/heat/193/rainrate/0/rain/0/uvi/10/solarrad/738
/v01/set/wid/12345/key/12345/bar/10123/temp/142/hum/98/wdir/99/wspd/7/dew/138/heat/142/rainrate/0/rain/148/uvi/0/solarrad/133
/v01/set/wid/12345/key/12345/bar/10122/temp/154/hum/87/wdir/270/wspd/3/dew/132/heat/154/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10156/temp/169/hum/94/wdir/94/wspd/0/dew/159/heat/169/rainrate/0/rain/2/uvi/20/solarrad/1497
/v01/set/wid/12345/key/12345/bar/10136/temp/140/hum/89/wdir/270/wspd/0/dew/122/heat/140/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10156/temp/169/hum/93/wdir/85/wspd/2/dew/157/heat/169/rainrate/0/rain/2/uvi/30/solarrad/4475
/v01/set/wid/12345/key/12345/bar/10168/temp/141/hum/94/wdir/275/wspd/0/dew/131/heat/141/rainrate/0/rain/45/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10181/temp/201/hum/64/wdir/112/wspd/4/dew/130/heat/201/rainrate/0/rain/2/uvi/20/solarrad/1878
/v01/set/wid/12345/key/12345/bar/10156/temp/162/hum/89/wdir/313/wspd/1/dew/143/heat/162/rainrate/109/rain/25/uvi/0/solarrad/117
/v01/set/wid/12345/key/12345/bar/10156/temp/184/hum/77/wdir/290/wspd/0/dew/142/heat/184/rainrate/0/rain/38/uvi/10/solarrad/336
/v01/set/wid/12345/key/12345/bar/10104/temp/166/hum/92/wdir/277/wspd/0/dew/152/heat/166/rainrate/0/rain/6/uvi/10/solarrad/643
/v01/set/wid/12345/key/12345/bar/10153/temp/194/hum/81/wdir/270/wspd/0/dew/160/heat/194/rainrate/0/rain/38/uvi/10/solarrad/787
/v01/set/wid/12345/key/12345/bar/10130/temp/163/hum/81/wdir/287/wspd/0/dew/130/heat/163/rainrate/0/rain/0/uvi/0/solarrad/40
/v01/set/wid/12345/key/12345/bar/10139/temp/139/hum/90/wdir/273/wspd/0/dew/122/heat/139/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10153/temp/197/hum/82/wdir/310/wspd/0/dew/165/heat/197/rainrate/0/rain/38/uvi/10/solarrad/2163
/v01/set/wid/12345/key/12345/bar/10154/temp/205/hum/68/wdir/292/wspd/0/dew/143/heat/205/rainrate/0/rain/0/uvi/30/solarrad/4002
/v01/set/wid/12345/key/12345/bar/10136/temp/132/hum/89/wdir/284/wspd/0/dew/114/heat/132/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10152/temp/157/hum/91/wdir/274/wspd/0/dew/142/heat/157/rainrate/0/rain/38/uvi/10/solarrad/721
/v01/set/wid/12345/key/12345/bar/10169/temp/173/hum/82/wdir/257/wspd/3/dew/141/heat/173/rainrate/0/rain/0/uvi/20/solarrad/2149
/v01/set/wid/12345/key/12345/bar/10123/temp/143/hum/97/wdir/106/wspd/3/dew/138/heat/143/rainrate/68/rain/128/uvi/0/solarrad/91
/v01/set/wid/12345/key/12345/bar/10163/temp/185/hum/72/wdir/82/wspd/6/dew/133/heat/185/rainrate/0/rain/2/uvi/30/solarrad/3419
/v01/set/wid/12345/key/12345/bar/10128/temp/159/hum/85/wdir/263/wspd/4/dew/133/heat/159/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10169/temp/172/hum/82/wdir/189/wspd/5/dew/140/heat/172/rainrate/0/rain/0/uvi/20/solarrad/1298
/v01/set/wid/12345/key/12345/bar/10114/temp/144/hum/88/wdir/263/wspd/5/dew/124/heat/144/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10166/temp/128/hum/96/wdir/270/wspd/0/dew/121/heat/128/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10156/temp/168/hum/91/wdir/117/wspd/4/dew/153/heat/168/rainrate/0/rain/2/uvi/20/solarrad/2510
/v01/set/wid/12345/key/12345/bar/10149/temp/142/hum/99/wdir/107/wspd/0/dew/140/heat/142/rainrate/0/rain/2/uvi/0/solarrad/132
/v01/set/wid/12345/key/12345/bar/10160/temp/152/hum/91/wdir/297/wspd/1/dew/137/heat/152/rainrate/0/rain/45/uvi/0/solarrad/13
/v01/set/wid/12345/key/12345/bar/10138/temp/140/hum/99/wdir/111/wspd/5/dew/138/heat/140/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10172/temp/205/hum/62/wdir/91/wspd/0/dew/129/heat/205/rainrate/0/rain/2/uvi/20/solarrad/1302
/v01/set/wid/12345/key/12345/bar/10178/temp/198/hum/68/wdir/104/wspd/0/dew/137/heat/198/rainrate/0/rain/2/uvi/10/solarrad/652
/v01/set/wid/12345/key/12345/bar/10143/temp/118/hum/96/wdir/273/wspd/0/dew/111/heat/118/rainrate/0/rain/0/uvi/0/solarrad/39
/v01/set/wid/12345/key/12345/bar/10147/temp/140/hum/99/wdir/107/wspd/0/dew/138/heat/140/rainrate/0/rain/2/uvi/0/solarrad/29
/v01/set/wid/12345/key/12345/bar/10166/temp/139/hum/94/wdir/265/wspd/2/dew/129/heat/139/rainrate/0/rain/0/uvi/20/solarrad/429
/v01/set/wid/12345/key/12345/bar/10120/temp/147/hum/97/wdir/114/wspd/3/dew/142/heat/147/rainrate/54/rain/100/uvi/0/solarrad/73
/v01/set/wid/12345/key/12345/bar/10144/temp/140/hum/99/wdir/107/wspd/0/dew/138/heat/140/rainrate/0/rain/2/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10111/temp/180/hum/87/wdir/110/wspd/1/dew/157/heat/180/rainrate/0/rain/6/uvi/20/solarrad/1434
/v01/set/wid/12345/key/12345/bar/10169/temp/132/hum/96/wdir/282/wspd/1/dew/125/heat/132/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10167/temp/138/hum/96/wdir/278/wspd/0/dew/131/heat/138/rainrate/0/rain/45/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10170/temp/159/hum/89/wdir/263/wspd/0/dew/140/heat/159/rainrate/0/rain/0/uvi/20/solarrad/1431
/v01/set/wid/12345/key/12345/bar/10131/temp/202/hum/71/wdir/246/wspd/4/dew/147/heat/202/rainrate/0/rain/0/uvi/10/solarrad/1248
/v01/set/wid/12345/key/12345/bar/10166/temp/188/hum/68/wdir/134/wspd/15/dew/127/heat/188/rainrate/0/rain/2/uvi/70/solarrad/7089
/v01/set/wid/12345/key/12345/bar/10099/temp/150/hum/94/wdir/247/wspd/4/dew/140/heat/150/rainrate/13/rain/4/uvi/0/solarrad/138
/v01/set/wid/12345/key/12345/bar/10168/temp/169/hum/84/wdir/250/wspd/3/dew/141/heat/169/rainrate/0/rain/0/uvi/20/solarrad/2960
/v01/set/wid/12345/key/12345/bar/10155/temp/198/hum/78/wdir/283/wspd/1/dew/158/heat/198/rainrate/0/rain/38/uvi/10/solarrad/1082
/v01/set/wid/12345/key/12345/bar/10130/temp/167/hum/79/wdir/282/wspd/0/dew/130/heat/167/rainrate/0/rain/0/uvi/0/solarrad/75
/v01/set/wid/12345/key/12345/bar/10128/temp/159/hum/85/wdir/249/wspd/3/dew/133/heat/159/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10102/temp/166/hum/92/wdir/287/wspd/0/dew/152/heat/166/rainrate/0/rain/6/uvi/20/solarrad/1259
/v01/set/wid/12345/key/12345/bar/10111/temp/171/hum/87/wdir/94/wspd/3/dew/149/heat/171/rainrate/0/rain/6/uvi/0/solarrad/145
/v01/set/wid/12345/key/12345/bar/10114/temp/181/hum/88/wdir/164/wspd/0/dew/160/heat/181/rainrate/0/rain/6/uvi/10/solarrad/654
/v01/set/wid/12345/key/12345/bar/10168/temp/126/hum/97/wdir/286/wspd/0/dew/121/heat/126/rainrate/0/rain/0/uvi/0/solarrad/0
/v01/set/wid/12345/key/12345/bar/10166/temp/223/hum/60/wdir/65/wspd/5/dew/141/heat/223/rainrate/0/rain/2/uvi/30/solarrad/2506
/v01/set/wid/12345/key/12345/bar/10166/temp/130/hum/97/wdir/259/wspd/0/dew/125/heat/130/rainrate/0/rain/0/uvi/0/solarrad/139
/v01/set/wid/12345/key/12345/bar/10147/temp/140/hum/99/wdir/107/wspd/0/dew/138/heat/140/rainrate/0/rain/2/uvi/0/solarrad/5
/v01/set/wid/12345/key/12345/bar/10167/temp/200/hum/74/wdir/268/wspd/4/dew/152/heat/200/rainrate/0/rain/0/uvi/50/solarrad/6324
/v01/set/wid/12345/key/12345/bar/10147/temp/140/hum/99/wdir/107/wspd/0/dew/138/heat/140/rainrate/0/rain/2/uvi/0/solarrad/73
/v01/set/wid/12345/key/12345/bar/10133/temp/203/hum/70/wdir/236/wspd/17/dew/146/heat/203/rainrate/0/rain/0/uvi/20/solarrad/1514
/v01/set/wid/12345/key/12345/bar/10157/temp/223/hum/63/wdir/248/wspd/0/dew/149/heat/223/rainrate/0/rain/0/uvi/30/solarrad/3714
Loading

0 comments on commit c95d0bf

Please sign in to comment.