Skip to content

Commit

Permalink
Merge pull request #62 from ffix/siemens-commands-fix
Browse files Browse the repository at this point in the history
Fix supportedCommands property for Teleofis modems
  • Loading branch information
babca authored Mar 11, 2019
2 parents 2afbf63 + 4abcc93 commit f446d26
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gsmmodem/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .serial_comms import SerialComms
from .exceptions import CommandError, InvalidStateException, CmeError, CmsError, InterruptedException, TimeoutException, PinRequiredError, IncorrectPinError, SmscNumberUnknownError
from .pdu import encodeSmsSubmitPdu, decodeSmsPdu, encodeGsm7, encodeTextMode
from .util import SimpleOffsetTzInfo, lineStartingWith, allLinesMatchingPattern, parseTextModeTimeStr
from .util import SimpleOffsetTzInfo, lineStartingWith, allLinesMatchingPattern, parseTextModeTimeStr, removeAtPrefix

#from . import compat # For Python 2.6 compatibility
from gsmmodem.util import lineMatching
Expand Down Expand Up @@ -555,7 +555,7 @@ def supportedCommands(self):
commands = commands[6:] # remove the +CLAC: prefix before splitting
return commands.split(',')
elif len(response) > 2: # Multi-line response
return [cmd.strip() for cmd in response[:-1]]
return [removeAtPrefix(cmd.strip()) for cmd in response[:-1]]
else:
self.log.debug('Unhandled +CLAC response: {0}'.format(response))
return None
Expand Down
14 changes: 14 additions & 0 deletions gsmmodem/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,17 @@ def allLinesMatchingPattern(pattern, lines):
if m:
result.append(m)
return result


def removeAtPrefix(string):
""" Remove AT prefix from a specified string.
:param string: An original string
:type string: str
:return: A string with AT prefix removed
:rtype: str
"""
if string.startswith('AT'):
return string[2:]
return string
2 changes: 2 additions & 0 deletions test/test_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def writeCallbackFunc(data):
(['FGH,RTY,UIO\r\n', 'OK\r\n'], ['FGH', 'RTY', 'UIO']), # nasty, but possible
# ZTE-like response: do not start with +CLAC, and use multiple lines
(['A\r\n', 'BCD\r\n', 'EFGH\r\n', 'OK\r\n'], ['A', 'BCD', 'EFGH']),
# Teleofis response: like ZTE but each command has AT prefix
(['AT&F\r\n', 'AT&V\r\n', 'AT&W\r\n', 'AT+CACM\r\n', 'OK\r\n'], ['&F', '&V', '&W', '+CACM']),
# Some Huawei modems have a ZTE-like response, but add an addition \r character at the end of each listed command
(['Q\r\r\n', 'QWERTY\r\r\n', '^DTMF\r\r\n', 'OK\r\n'], ['Q', 'QWERTY', '^DTMF']))
for responseSequence, expected in tests:
Expand Down
9 changes: 8 additions & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from . import compat # For Python 2.6 compatibility

from gsmmodem.util import allLinesMatchingPattern, lineMatching, lineStartingWith, lineMatchingPattern, SimpleOffsetTzInfo
from gsmmodem.util import allLinesMatchingPattern, lineMatching, lineStartingWith, lineMatchingPattern, SimpleOffsetTzInfo, removeAtPrefix

class TestUtil(unittest.TestCase):
""" Tests misc utilities from gsmmodem.util """
Expand Down Expand Up @@ -74,6 +74,13 @@ def test_SimpleOffsetTzInfo(self):
self.assertEqual(tz.dst(None), timedelta(0))
self.assertIsInstance(tz.__repr__(), str)

def test_removeAtPrefix(self):
""" Tests function: removeAtPrefix"""
tests = (('AT+CLAC', '+CLAC'), ('ATZ', 'Z'), ('+CLAC', '+CLAC'), ('Z', 'Z'))
for src, dst in tests:
res = removeAtPrefix(src)
self.assertEqual(res, dst)


if __name__ == "__main__":
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
Expand Down

0 comments on commit f446d26

Please sign in to comment.