Skip to content

Commit 0343cb5

Browse files
authored
Merge pull request #7 from brentru/update-property-docstrings
Rewrite properties documentation
2 parents 405fbb7 + 13fc2f6 commit 0343cb5

File tree

6 files changed

+38
-53
lines changed

6 files changed

+38
-53
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
__version__ = "0.0.0-auto.0"
4545
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FONA.git"
4646

47-
# pylint: disable=bad-whitespace
4847
FONA_DEFAULT_TIMEOUT_MS = 500 # TODO: Check this against arduino...
4948

5049
# Commands
@@ -67,7 +66,6 @@
6766
# FONA preferred SMS storage
6867
FONA_SMS_STORAGE_SIM = b'"SM"' # Storage on the SIM
6968
FONA_SMS_STORAGE_INTERNAL = b'"ME"' # Internal storage on the FONA
70-
# pylint: enable=bad-whitespace
7169

7270

7371
# pylint: disable=too-many-instance-attributes, too-many-public-methods
@@ -177,12 +175,14 @@ def reset(self):
177175
@property
178176
# pylint: disable=too-many-return-statements
179177
def version(self):
180-
"""Returns FONA Version."""
178+
"""The version of the FONA module. Can be FONA_800_L,
179+
FONA_800_H, FONA_808_V1, FONA_808_V2, FONA_3G_A, FONA3G_E.
180+
"""
181181
return self._fona_type
182182

183183
@property
184184
def iemi(self):
185-
"""Returns FONA module's IEMI number."""
185+
"""FONA Module's IEMI (International Mobile Equipment Identity) number."""
186186
if self._debug:
187187
print("FONA IEMI")
188188
self._uart.reset_input_buffer()
@@ -194,18 +194,18 @@ def iemi(self):
194194

195195
@property
196196
def local_ip(self):
197-
"""Returns the local IP Address, False if not set."""
197+
"""Module's local IP address, None if not set."""
198198
self._uart_write(b"AT+CIFSR\r\n")
199199
self._read_line()
200200
try:
201201
ip_addr = self.pretty_ip(self._buf)
202202
except ValueError:
203-
return False
203+
return None
204204
return ip_addr
205205

206206
@property
207207
def iccid(self):
208-
"""Returns SIM Card's ICCID number as a string."""
208+
"""SIM Card's unique ICCID (Integrated Circuit Card Identifier)."""
209209
if self._debug:
210210
print("ICCID")
211211
self._uart_write(b"AT+CCID\r\n")
@@ -215,7 +215,7 @@ def iccid(self):
215215

216216
@property
217217
def gprs(self):
218-
"""Returns module's GPRS state."""
218+
"""GPRS (General Packet Radio Services) power status."""
219219
if not self._send_parse_reply(b"AT+CGATT?", b"+CGATT: ", ":"):
220220
return False
221221
if not self._buf:
@@ -311,7 +311,7 @@ def set_gprs(self, apn=None, enable=True):
311311

312312
@property
313313
def network_status(self):
314-
"""Returns cellular network status"""
314+
"""The status of the cellular network."""
315315
self._read_line()
316316
if self._debug:
317317
print("Network status")
@@ -324,7 +324,9 @@ def network_status(self):
324324

325325
@property
326326
def rssi(self):
327-
"""Returns cellular network's Received Signal Strength Indicator (RSSI)."""
327+
"""The received signal strength indicator for the cellular network
328+
we are connected to.
329+
"""
328330
if self._debug:
329331
print("RSSI")
330332
if not self._send_parse_reply(b"AT+CSQ", b"+CSQ: "):
@@ -347,7 +349,7 @@ def rssi(self):
347349

348350
@property
349351
def gps(self):
350-
"""Returns the GPS fix."""
352+
"""Module's GPS status."""
351353
if self._debug:
352354
print("GPS Fix")
353355
if self._fona_type == FONA_808_V2:
@@ -370,10 +372,6 @@ def gps(self):
370372

371373
@gps.setter
372374
def gps(self, gps_on=False):
373-
"""Sets GPS module power, parses returned buffer.
374-
:param bool gps_on: Enables the GPS module, disabled by default.
375-
376-
"""
377375
if not (
378376
self._fona_type == FONA_3G_A
379377
or self._fona_type == FONA_3G_E
@@ -422,14 +420,13 @@ def unpretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name
422420

423421
@property
424422
def enable_sms_notification(self):
425-
"""Returns status of new SMS message notifications"""
423+
"""Checks if SMS notifications are enabled."""
426424
if not self._send_parse_reply(b"AT+CNMI?\r\n", b"+CNMI:", idx=1):
427425
return False
428426
return self._buf
429427

430428
@enable_sms_notification.setter
431429
def enable_sms_notification(self, enable=True):
432-
"""Enables or disables new SMS message notifications."""
433430
if enable:
434431
if not self._send_check_reply(b"AT+CNMI=2,1\r\n", reply=REPLY_OK):
435432
return False
@@ -442,8 +439,7 @@ def receive_sms(self):
442439
"""Checks for a message notification from the FONA module,
443440
replies back with the a tuple containing (sender, message).
444441
NOTE: This method needs to be polled consistently due to the lack
445-
of hw-based interrupts in CircuitPython. Adding time.sleep delays
446-
may cause missed messages if using the RI pin instead of UART.
442+
of hw-based interrupts in CircuitPython.
447443
448444
"""
449445
if self._ri is not None: # poll the RI pin
@@ -501,12 +497,12 @@ def send_sms(self, phone_number, message):
501497
return True
502498

503499
def num_sms(self, sim_storage=True):
504-
"""Returns the number of SMS messages stored in memory, False if none stored.
500+
"""Returns the number of SMS messages stored in memory.
505501
:param bool sim_storage: SMS storage on the SIM, otherwise internal storage on FONA chip.
506502
507503
"""
508504
if not self._send_check_reply(b"AT+CMGF=1", reply=REPLY_OK):
509-
return False
505+
raise RuntimeError("Operating mode not supported by FONA module.")
510506

511507
if sim_storage: # ask how many SMS are stored
512508
if self._send_parse_reply(b"AT+CPMS?", FONA_SMS_STORAGE_SIM + b",", idx=1):
@@ -524,10 +520,10 @@ def num_sms(self, sim_storage=True):
524520
self._read_line() # eat OK
525521
if self._send_parse_reply(b"AT+CPMS?", b'"SM_P",', idx=1):
526522
return self._buf
527-
return False
523+
return 0
528524

529525
def delete_sms(self, sms_slot):
530-
"""Deletes a SMS message in the provided SMS slot.
526+
"""Deletes a SMS message from a storage (internal or sim) slot
531527
:param int sms_slot: SMS SIM or FONA memory slot number.
532528
533529
"""
@@ -597,7 +593,6 @@ def read_sms(self, sms_slot):
597593

598594
def get_host_by_name(self, hostname):
599595
"""Converts a hostname to a packed 4-byte IP address.
600-
Returns a 4 bytearray.
601596
:param str hostname: Destination server.
602597
603598
"""
@@ -618,9 +613,7 @@ def get_host_by_name(self, hostname):
618613
return self._buf
619614

620615
def get_socket(self):
621-
"""Returns an avaliable socket (INITIAL or CLOSED state).
622-
623-
"""
616+
"""Obtains a socket, if available."""
624617
if self._debug:
625618
print("*** Get socket")
626619

@@ -643,7 +636,7 @@ def get_socket(self):
643636
return allocated_socket
644637

645638
def remote_ip(self, sock_num):
646-
"""Returns the IP address of the host who sent the current incoming packet.
639+
"""Returns the IP address of the remote server.
647640
:param int sock_num: Desired socket.
648641
649642
"""
@@ -658,7 +651,7 @@ def remote_ip(self, sock_num):
658651
return self._buf
659652

660653
def socket_status(self, sock_num):
661-
"""Returns if socket is connected.
654+
"""Returns the socket connection status, False if not connected.
662655
:param int sock_num: Desired socket number.
663656
664657
"""
@@ -688,7 +681,7 @@ def socket_status(self, sock_num):
688681
return True
689682

690683
def socket_available(self, sock_num):
691-
"""Returns the amount of bytes to be read from the socket.
684+
"""Returns the amount of bytes available to be read from the socket.
692685
:param int sock_num: Desired socket to return bytes available from.
693686
694687
"""

adafruit_fona/adafruit_fona_socket.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ def htons(x):
5757
return (((x) << 8) & 0xFF00) | (((x) >> 8) & 0xFF)
5858

5959

60-
# pylint: disable=bad-whitespace
6160
SOCK_STREAM = const(0x00) # TCP
6261
TCP_MODE = 80
6362
SOCK_DGRAM = const(0x01) # UDP
6463
AF_INET = const(3)
6564
NO_SOCKET_AVAIL = const(255)
66-
# pylint: enable=bad-whitespace
6765

6866
# keep track of sockets we allocate
6967
SOCKETS = []

adafruit_fona/fona_3g.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FONA3G(FONA):
5858

5959
def __init__(self, uart, rst, ri=None, debug=False):
6060
uart.baudrate = 4800
61-
super(FONA3G, self).__init__(uart, rst, ri, debug)
61+
super().__init__(uart, rst, ri, debug)
6262

6363
def set_baudrate(self, baudrate):
6464
"""Sets the FONA's UART baudrate."""
@@ -70,17 +70,13 @@ def set_baudrate(self, baudrate):
7070

7171
@property
7272
def gps(self):
73-
"""Returns True if the GPS session is active, False if it's stopped.."""
73+
"""Module's GPS status."""
7474
if not self._send_check_reply(b"AT+CGPS?", reply=b"+CGPS: 1,1"):
7575
return False
7676
return True
7777

7878
@gps.setter
7979
def gps(self, gps_on=False):
80-
"""Sets GPS module power, parses returned buffer.
81-
:param bool gps_on: Enables the GPS module, disabled by default.
82-
83-
"""
8480
# check if GPS is already enabled
8581
if not self._send_parse_reply(b"AT+CGPS?", b"+CGPS: "):
8682
return False
@@ -99,17 +95,17 @@ def gps(self, gps_on=False):
9995

10096
@property
10197
def ue_system_info(self):
102-
"""Returns True if UE system is online, otherwise False."""
98+
"""UE System status."""
10399
self._send_parse_reply(b"AT+CPSI?\r\n", b"+CPSI: ")
104100
if not self._buf == "GSM" or self._buf == "WCDMA": # 5.15
105101
return False
106102
return True
107103

108104
@property
109105
def local_ip(self):
110-
"""Returns the IP address of the current active socket."""
106+
"""Module's local IP address, None if not set."""
111107
if not self._send_parse_reply(b"AT+IPADDR", b"+IPADDR:"):
112-
return False
108+
return None
113109
return self._buf
114110

115111
# pylint: disable=too-many-return-statements
@@ -164,15 +160,14 @@ def set_gprs(self, apn=None, enable=True):
164160

165161
@property
166162
def tx_timeout(self):
167-
"""Returns CIPSEND timeout, in milliseconds."""
163+
"""CIPSEND timeout, in milliseconds."""
168164
self._read_line()
169165
if not self._send_parse_reply(b"AT+CIPTIMEOUT?", b"+CIPTIMEOUT:", idx=2):
170166
return False
171167
return True
172168

173169
@tx_timeout.setter
174170
def tx_timeout(self, timeout):
175-
"""Sets CIPSEND timeout."""
176171
self._read_line()
177172
if not self._send_check_reply(
178173
b"AT+CIPTIMEOUT=" + str(timeout).encode(), reply=REPLY_OK
@@ -259,7 +254,8 @@ def socket_connect(self, sock_num, dest, port, conn_mode=0):
259254
return True
260255

261256
def remote_ip(self, sock_num):
262-
"""Returns the IP address of sender."""
257+
"""Returns the IP address of the remote connection.
258+
"""
263259
self._read_line()
264260
assert (
265261
sock_num < FONA_MAX_SOCKETS
@@ -277,7 +273,7 @@ def remote_ip(self, sock_num):
277273
return ip_addr
278274

279275
def socket_write(self, sock_num, buffer, timeout=120000):
280-
"""Writes bytes to the socket.
276+
"""Writes len(buffer) bytes to the socket.
281277
:param int sock_num: Desired socket number to write to.
282278
:param bytes buffer: Bytes to write to socket.
283279
:param int timeout: Socket write timeout, in milliseconds. Defaults to 120000ms.
@@ -318,7 +314,7 @@ def socket_write(self, sock_num, buffer, timeout=120000):
318314
return True
319315

320316
def socket_status(self, sock_num):
321-
"""Returns True if socket is connected, False otherwise.
317+
"""Returns socket status, True if connected. False otherwise.
322318
:param int sock_num: Desired socket number.
323319
324320
"""

examples/fona_aio_post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import board
44
import busio
55
import digitalio
6+
import adafruit_requests as requests
67
from adafruit_fona.adafruit_fona import FONA
78
from adafruit_fona.fona_3g import FONA3G
89
import adafruit_fona.adafruit_fona_network as network
910
import adafruit_fona.adafruit_fona_socket as cellular_socket
10-
import adafruit_requests as requests
1111

1212
# Get GPRS details and more from a secrets.py file
1313
try:

examples/fona_cheerlights.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import board
44
import busio
55
import digitalio
6+
import neopixel
7+
import adafruit_requests as requests
8+
import adafruit_fancyled.adafruit_fancyled as fancy
69
from adafruit_fona.adafruit_fona import FONA
710
from adafruit_fona.fona_3g import FONA3G
811
import adafruit_fona.adafruit_fona_network as network
912
import adafruit_fona.adafruit_fona_socket as cellular_socket
10-
import adafruit_requests as requests
11-
12-
import neopixel
13-
import adafruit_fancyled.adafruit_fancyled as fancy
14-
1513

1614
# Get GPRS details and more from a secrets.py file
1715
try:

examples/fona_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import board
44
import busio
55
import digitalio
6+
import adafruit_requests as requests
67
from adafruit_fona.adafruit_fona import FONA
78
from adafruit_fona.fona_3g import FONA3G
89
import adafruit_fona.adafruit_fona_network as network
910
import adafruit_fona.adafruit_fona_socket as cellular_socket
10-
import adafruit_requests as requests
1111

1212
print("FONA Webclient Test")
1313

0 commit comments

Comments
 (0)