Repository: akolar/ogn-lib

Issue:
 Implement parser for Skylines messages (OGSKYL)

Discussion:

Patch:
diff --git a/ogn_lib/parser.py b/ogn_lib/parser.py
index abbe761..4df961f 100644
--- a/ogn_lib/parser.py
+++ b/ogn_lib/parser.py
@@ -686,3 +686,31 @@ class Spider(Parser):
             'spider_id': fields[2],
             'gps_status': fields[3]
         }
+
+
+class Skylines(Parser):
+    """
+    Parser for Spider-formatted APRS messages.
+    """
+
+    __destto__ = ['OGSKYL', 'OGSKYL-1']
+
+    @staticmethod
+    def _parse_protocol_specific(comment):
+        """
+        Parses the comment string from Spider's APRS messages.
+        :param str comment: comment string
+        :return: parsed comment
+        :rtype: dict
+        """
+
+        fields = comment.split(' ', maxsplit=1)
+
+        if len(fields) < 2:
+            raise exceptions.ParseError('Skylines comment incorrectly formatted:'
+                                        ' received {}'.format(comment))
+
+        return {
+            'id': fields[0],
+            'vertical_speed': int(fields[1][:3]) * FEET_TO_METERS
+        }


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 8fd96a5..fa7c7cd 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -466,6 +466,21 @@ class TestSpider:
             parser.Spider._parse_protocol_specific('id300234010617040 +19dB')
 
 
+class TestSkylines:
+    def test_parse_protocol_specific(self):
+        data = parser.Skylines._parse_protocol_specific('id2816 +000fpm')
+        assert data['id'] == 'id2816'
+        assert data['vertical_speed'] == 0
+
+        data = parser.Skylines._parse_protocol_specific('id2816 +159fpm')
+        assert data['id'] == 'id2816'
+        assert abs(data['vertical_speed'] - 4.57) < 0.1
+
+    def test_parse_protocol_specific_fail(self):
+        with pytest.raises(exceptions.ParseError):
+            parser.Skylines._parse_protocol_specific('id1111')
+
+
 class TestServerParser:
 
     def test_parse_message_beacon(self, mocker):