Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions msa_sdk/geolocation.py
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions tests/test_geolocation.py
Original file line number Diff line number Diff line change
@@ -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()