diff --git a/msa_sdk/geolocation.py b/msa_sdk/geolocation.py new file mode 100644 index 0000000..cf6d6b0 --- /dev/null +++ b/msa_sdk/geolocation.py @@ -0,0 +1,66 @@ +"""Module geolocation.""" + +import json + +from msa_sdk.msa_api import MSA_API + + +class Geolocation(MSA_API): + """Class Geolocation.""" + + def __init__(self, site_id=None): + """ + Initialize. + + Parameters + ---------- + site_id: String + Site id + + Returns + ------- + None + """ + MSA_API.__init__(self) + self.site_id = site_id + self.api_path = "/device/v1/site" + + def get_geolocation(self) -> dict: + """ + Get the geolocation (latitude, longitude) of a ME. + + Parameters + ---------- + None + + Returns + ------- + latitude, longitude: Dict() + + """ + self.action = 'Get the geolocation' + self.path = f'{self.api_path}/{self.site_id}/geo-localization' + self._call_get() + + return json.loads(self.content) + + def set_geolocation(self, latitude: str, longitude: str): + """ + Set the geolocation (latitude, longitude) of a ME. + + Parameters + ---------- + latitude: String + Modified latitude + + longitude: String + Modified longitude + + Returns + ------- + None + + """ + self.action = 'Set the geolocation' + self.path = f'{self.api_path}/geo-localization?siteId={self.site_id}&latitude={latitude}&longitude={longitude}' + self._call_put() diff --git a/tests/test_geolocation.py b/tests/test_geolocation.py new file mode 100644 index 0000000..868e787 --- /dev/null +++ b/tests/test_geolocation.py @@ -0,0 +1,23 @@ +""" +Test Geolocation +""" +from unittest.mock import patch + +from msa_sdk.geolocation import Geolocation + + +def test_geolocation(): + + me_id = 125 + latitude = 45.150121 + longitude = 5.725408 + + geoloc = Geolocation(me_id) + + with patch('msa_sdk.msa_api.MSA_API._call_put') as mock_call_put: + geoloc.set_geolocation(latitude, longitude) + mock_call_put.assert_called_once() + + with patch('msa_sdk.msa_api.MSA_API._call_get') as mock_call_get: + geo_loc = geoloc.get_geolocation() + mock_call_get.assert_called_once()