We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dd6b956 commit a73b14eCopy full SHA for a73b14e
bl_battery.py
@@ -75,11 +75,11 @@ def main():
75
port = int(device[i+1:])
76
device = device[:i]
77
try:
78
- s = socket.socket(socket.AF_BLUETOOTH,
79
- socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
80
- s.connect((device, port))
81
- while getATCommand(s, s.recv(128), device, port):
82
- pass
+ with socket.socket(socket.AF_BLUETOOTH,
+ socket.SOCK_STREAM, socket.BTPROTO_RFCOMM) as s:
+ s.connect((device, port))
+ while getATCommand(s, s.recv(128), device, port):
+ pass
83
except OSError as e:
84
print(f"{device} is offline", e)
85
0 commit comments