From dc66940fb81719ad8a82a250e28b94a38df88848 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 9 Jan 2016 14:53:31 +0000 Subject: [PATCH] added parsing of positionless wx reports + tests --- aprslib/parsing.py | 24 +++- ..._weather.py => test_parse_weather_data.py} | 114 ++++++++++-------- 2 files changed, 86 insertions(+), 52 deletions(-) rename tests/{test_parse_comment_weather.py => test_parse_weather_data.py} (62%) diff --git a/aprslib/parsing.py b/aprslib/parsing.py index 5171f2d..d63d93a 100644 --- a/aprslib/parsing.py +++ b/aprslib/parsing.py @@ -162,10 +162,9 @@ def parse(packet): # \ - unused # ] - unused # ^ - unused - # _ - positionless weather report # { - user defined # } - 3rd party traffic - if packet_type in '#$%)*,B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW', + 'to': 'B', + 'via': '', + 'wx_raw_timestamp': '10090556', + "weather": { + "pressure": 990.0, + "humidity": 50, + "rain_1h": float(010.0 * mm_multiplier), + "rain_24h": float(020.0 * mm_multiplier), + "rain_since_midnight": float(030.0 * mm_multiplier), + "snow": float(5.5 * 25.4), + "temperature": float((77.0 - 32) / 1.8), + "wind_direction": 220, + "wind_gust": 5.0 * wind_multiplier, + "wind_speed": 4.0 * wind_multiplier + } } - result = _parse_comment_weather("10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW") - self.assertEqual(expected, result) + packet = "A>B:_10090556c220s004g005t077r010p020P030h50b09900s5.5wRSW" - expected = "10090556wRSW", { + self.assertEqual(expected, parse(packet)) + + packet2 = "A>B:_10090556c220s112g t r h b wRSW" + expected['raw'] = packet2 + expected['weather'] = { "wind_direction": 220, "wind_speed": 112 * wind_multiplier } - result = _parse_comment_weather("10090556c220s112g t r p P h b wRSW") - self.assertEqual(expected, result) + self.assertEqual(expected, parse(packet2)) - expected = "10090556wRSW", { + packet3 = "A>B:_10090556c220s112g...t...r...p...P...b.....wRSW" + expected['raw'] = packet3 + expected['weather'] = { "wind_direction": 220, "wind_speed": 112 * wind_multiplier } - result = _parse_comment_weather("10090556c220s112g...t...r...p...P...h..b.....wRSW") - self.assertEqual(expected, result) + + self.assertEqual(expected, parse(packet3)) def test_position_packet(self): expected = "eCumulusWMR100", { @@ -235,7 +253,7 @@ class ParseCommentWeather(unittest.TestCase): "wind_speed": 1 * wind_multiplier } - result = _parse_comment_weather("319/001g004t048r...p P000h19b10294eCumulusWMR100") + result = _parse_weather_data("319/001g004t048r...p P000h19b10294eCumulusWMR100") self.assertEqual(expected, result) if __name__ == '__main__':