Skip to content

Commit f7a4d33

Browse files
committed
ftespnow: Fix .ftespnow-client/manifest.py and .ftespnow-server/manifest.py, code formatting, and fixed spelling mistakes.
... Signed-off-by: Guilherme Schneck <guilhermeschneck@gmail.com>
1 parent 5a64472 commit f7a4d33

6 files changed

Lines changed: 118 additions & 120 deletions

File tree

micropython/ftespnow/examples/client_side_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Receive a message
1818
received_data = esp.receive_message()
19-
if received_data == None: # Check if any data was received
19+
if received_data is None: # Check if any data was received
2020
print("No message was received (timed out)")
2121
else:
2222
print(f"Here is the received data: {received_data}")
@@ -51,4 +51,4 @@
5151

5252
# Write received data to a python dictionary
5353
data_dict = esp.receive_to_dict()
54-
print(data_dict)
54+
print(data_dict)

micropython/ftespnow/examples/server_side_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Receive a message
1616
received_data = esp.receive_message()
17-
if received_data == None: # Check if any data was received
17+
if received_data is None: # Check if any data was received
1818
print("No message was received (timed out)")
1919
else:
2020
print(f"Here is the received data: {received_data}")
@@ -49,4 +49,4 @@
4949

5050
# Write received data to a python dictionary
5151
data_dict = esp.receive_to_dict() # Will return {} if no data was received
52-
print(data_dict)
52+
print(data_dict)

micropython/ftespnow/ftespnow-client/ftespnow/client.py

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class CLIENT:
55
def __init__(self, *, timeout: int=5) -> None:
66
self.esp = espnow.ESPNow()
77
self.timeout = timeout
8-
8+
99
def configure(self, *, timeout: int=5) -> None:
1010
self.timeout: int = timeout
1111

@@ -19,108 +19,108 @@ def send_message(self, data: str) -> bool:
1919
Send a string
2020
2121
Args:
22-
22+
2323
data (str): Data to be sent
2424
2525
Returns:
26-
26+
2727
bool: Confirmation flag (`True` if data was received, `False` otherwise)
2828
"""
29-
29+
3030
ack: bool = self.esp.send(self.peer, data)
3131
return ack
32-
32+
3333
def receive_message(self, recv_timeout :int= 5) -> list | None:
3434
"""
3535
Receive a string
3636
3737
Args:
38-
38+
3939
recv_timeout (int, optional): Reception timeout. Defaults to 5.
4040
4141
Returns:
42-
42+
4343
list | None: `[<sender's mac address (str)>, <message (str)>]` | `None` if no message is received
4444
"""
45-
45+
4646
received = self.esp.recv(recv_timeout)
4747
if received[0] == None: return
4848
return received
49-
49+
5050
def send_txt(self, filename: str) -> bool:
5151
"""
5252
Parse and send a `.txt` file as a `string`
5353
5454
Args:
5555
56-
filename (str): Filepath of the desired file to be sent with file name and extention
56+
filename (str): Filepath of the desired file to be sent with file name and extension
5757
5858
Returns:
59-
59+
6060
sent (bool): Confirmation flag (`True` if data was received, `False` otherwise)
6161
"""
62-
62+
6363
with open(filename, 'r') as f:
6464
data: str = str(f.readlines())
6565
sent: bool = self.send_message(data)
6666
return sent
67-
67+
6868
def send_json(self, filename: str, *, indent: int=4) -> bool:
6969
"""
7070
Parse and send a `.json` file as a `string`
7171
7272
Args:
73-
74-
filename (str): Filepath of the desired file to be sent with file name and extention
75-
73+
74+
filename (str): Filepath of the desired file to be sent with file name and extension
75+
7676
indent (int, optional): Desired indent of the resulting parsed `string` (for formatting purposes). Defaults to 4.
7777
7878
Returns:
7979
8080
sent (bool): Confirmation flag (`True` if data was received, `False` otherwise)
8181
"""
82-
82+
8383
with open(filename, 'r') as f:
8484
unparsed = json.load(f)
8585
parsed: str = json.dumps(unparsed, indent=indent)
8686
sent: bool = self.send_message(parsed)
8787
return sent
88-
88+
8989
def receive_to_txt(self, target_file: str, mode: str='a') -> bool:
9090
"""
9191
Write received `string` into a `.txt` file.
92-
92+
9393
**Will not write or create file if no data is received**
94-
94+
9595
Args:
96-
96+
9797
target_file (str): Filepath of the destination file for the received data with file name and extension.
98-
98+
9999
mode (str, optional): Editing mode
100-
100+
101101
- `r` - Read only
102-
102+
103103
- `w` - Write only (truncates file before writing)
104-
104+
105105
- `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists)
106-
106+
107107
- `a` - Append to the end of the file (default)
108-
108+
109109
- `b` - Binary mode
110-
110+
111111
- `t` - Text mode
112-
112+
113113
- `+` - Update (read and write)
114-
114+
115115
Read `open()`_ for more information
116-
116+
117117
Returns:
118118
119119
received (bool): Confirmation flag (`True` if data was received, `False` otherwise)
120-
120+
121121
.. _open(): https://docs.python.org/3/library/functions.html#open
122122
"""
123-
123+
124124
if ".txt" not in target_file: raise SyntaxError("File format must be .txt")
125125
try:
126126
received: bool = False
@@ -133,42 +133,42 @@ def receive_to_txt(self, target_file: str, mode: str='a') -> bool:
133133
return not received
134134
except SyntaxError:
135135
raise
136-
136+
137137
def receive_to_json(self, target_file: str, mode: str='a') -> bool:
138138
"""
139139
Write received `string` into a `.json` file.
140-
140+
141141
**Will not write or create file if no data is received**
142-
142+
143143
Args:
144-
144+
145145
target_file (str): Filepath of the destination file for the received data with file name and extension.
146-
146+
147147
mode (str, optional): Editing mode
148-
148+
149149
- `r` - Read only
150-
150+
151151
- `w` - Write only (truncates file before writing)
152-
152+
153153
- `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists)
154-
154+
155155
- `a` - Append to the end of the file (default)
156-
156+
157157
- `b` - Binary mode
158-
158+
159159
- `t` - Text mode
160-
160+
161161
- `+` - Update (read and write)
162-
162+
163163
Read `open()`_ for more information
164-
164+
165165
Returns:
166-
166+
167167
received (bool): Confirmation flag (`True` if data was received, `False` otherwise)
168-
168+
169169
.. _open(): https://docs.python.org/3/library/functions.html#open
170170
"""
171-
171+
172172
if ".json" not in target_file: raise SyntaxError("File format must be .json")
173173
try:
174174
received: bool = False
@@ -185,19 +185,20 @@ def receive_to_json(self, target_file: str, mode: str='a') -> bool:
185185
return not received
186186
except SyntaxError:
187187
raise
188-
188+
189189
def receive_to_dict(self) -> dict:
190190
"""
191191
Unparses received `string` into a `dict` object
192-
192+
193193
Args:
194194
195195
None:
196-
196+
197197
Returns:
198198
199199
unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json`
200200
"""
201+
201202
data: list | None = self.receive_message()
202203
if data == None: return {}
203204
mac: str = str(data[0])
@@ -206,4 +207,4 @@ def receive_to_dict(self) -> dict:
206207
"mac": mac,
207208
"message": message
208209
}
209-
return unparsed
210+
return unparsed

micropython/ftespnow/ftespnow-client/manifest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
)
55

66
require("ftespnow")
7-
require("json")
8-
require("espnow")
97
package("ftespnow")

0 commit comments

Comments
 (0)