Repository: akolar/ogn-lib

Issue:
Implement parser for Spot messages (OGSPOT)

Discussion:

Patch:
diff --git a/ogn_lib/parser.py b/ogn_lib/parser.py
index f43f6cb..a2ca7ea 100644
--- a/ogn_lib/parser.py
+++ b/ogn_lib/parser.py
@@ -627,3 +627,33 @@ class ServerParser(Parser):
         """
 
         return {'comment': comment}
+
+
+class Spot(Parser):
+    """
+    Parser for Spot-formatted APRS messages.
+    """
+
+    __destto__ = ['OGSPOT', 'OGSPOT-1']
+
+    @staticmethod
+    def _parse_protocol_specific(comment):
+        """
+        Parses the comment string from Spot's APRS messages.
+
+        :param str comment: comment string
+        :return: parsed comment
+        :rtype: dict
+        """
+
+        fields = comment.split(' ', maxsplit=2)
+
+        if len(fields) < 3:
+            raise exceptions.ParseError('SPOT comment incorrectly formatted: '
+                                        'received {}'.format(comment))
+
+        return {
+            'id': fields[0],
+            'model': fields[1],
+            'status': fields[2]
+        }


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index cb9b05c..bcd3247 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -440,6 +440,18 @@ class TestNaviter:
         assert data['address_type'] is constants.AddressType.naviter
 
 
+class TestSpot:
+    def test_parse_protocol_specific(self):
+        data = parser.Spot._parse_protocol_specific('id0-2860357 SPOT3 GOOD')
+        assert data['id'] == 'id0-2860357'
+        assert data['model'] == 'SPOT3'
+        assert data['status'] == 'GOOD'
+
+    def test_parse_protocol_specific_fail(self):
+        with pytest.raises(exceptions.ParseError):
+            parser.Spot._parse_protocol_specific('id0-2860357 SPOT3')
+
+
 class TestServerParser:
 
     def test_parse_message_beacon(self, mocker):