sms_functions: added unlock_and_enable_modem
This commit is contained in:
parent
fa27b99970
commit
e7e855049a
@ -68,12 +68,8 @@ def unlock_sim(modem):
|
|||||||
remaining_attempts = modem.UnlockRetries
|
remaining_attempts = modem.UnlockRetries
|
||||||
raise SIMError('Failed to unlock PIN, remaining attempts: {}'.format(remaining_attempts)) from exc
|
raise SIMError('Failed to unlock PIN, remaining attempts: {}'.format(remaining_attempts)) from exc
|
||||||
|
|
||||||
|
def unlock_and_enable_modem():
|
||||||
|
|
||||||
def send_sms(recipients, smsstring):
|
|
||||||
|
|
||||||
# Assemble SMS
|
|
||||||
logger.info("Sending SMS: %s", smsstring)
|
|
||||||
|
|
||||||
retries = 0
|
retries = 0
|
||||||
# Retry the whole block, because once pydbus fetches the properties
|
# Retry the whole block, because once pydbus fetches the properties
|
||||||
# it does not really refresh them, including modems
|
# it does not really refresh them, including modems
|
||||||
@ -82,18 +78,31 @@ def send_sms(recipients, smsstring):
|
|||||||
# enable the modem
|
# enable the modem
|
||||||
# Get modem, unlock SIM
|
# Get modem, unlock SIM
|
||||||
modem = get_modem()
|
modem = get_modem()
|
||||||
|
|
||||||
|
logger.debug("Unlocking SIM (if needed)")
|
||||||
unlock_sim(modem)
|
unlock_sim(modem)
|
||||||
|
|
||||||
|
logger.debug("Enabling modem")
|
||||||
modem.Enable(True)
|
modem.Enable(True)
|
||||||
break
|
return modem
|
||||||
|
|
||||||
except SIMError:
|
except SIMError:
|
||||||
# cannot continue with this one (could be a wrong PIN
|
# cannot continue with this one (could be a wrong PIN
|
||||||
# and then we waste our attempts)
|
# and then we waste our attempts)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except:
|
||||||
retries += 1
|
retries += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if retries > 15:
|
if retries > 15:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def send_sms(recipients, smsstring):
|
||||||
|
|
||||||
|
# Assemble SMS
|
||||||
|
logger.info("Sending SMS: %s", smsstring)
|
||||||
|
|
||||||
|
unlock_and_enable_modem()
|
||||||
|
|
||||||
# test sending SMS
|
# test sending SMS
|
||||||
modem_msg = modem['org.freedesktop.ModemManager1.Modem.Messaging']
|
modem_msg = modem['org.freedesktop.ModemManager1.Modem.Messaging']
|
||||||
|
Loading…
Reference in New Issue
Block a user