Skip to content

Commit

Permalink
style: format code with Autopep8, Black, ClangFormat, dotnet-format, …
Browse files Browse the repository at this point in the history
…Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf

This commit fixes the style issues introduced in 1b214fb according to the output
from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java
Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt,
Scalafmt, StandardJS, StandardRB, swift-format and Yapf.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Aug 27, 2024
1 parent 48b63c4 commit cd07be6
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions iot-integration/iot_devices/smart_home.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import os
import json
import os
import socket
import threading

from cryptography.fernet import Fernet


class SmartHome:

def __init__(self, home_id, home_secret, devices=None):
self.home_id = home_id
self.home_secret = home_secret
self.devices = devices if devices else []
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(('localhost', 8080))
self.socket.bind(("localhost", 8080))
self.socket.listen(5)
self.threads = []

Expand All @@ -22,14 +25,14 @@ def remove_device(self, device):

def send_command(self, device_id, command):
for device in self.devices:
if device['id'] == device_id:
device['socket'].send(command.encode())
if device["id"] == device_id:
device["socket"].send(command.encode())
break

def receive_data(self, device_id):
for device in self.devices:
if device['id'] == device_id:
data = device['socket'].recv(1024)
if device["id"] == device_id:
data = device["socket"].recv(1024)
return data.decode()

def start_listening(self):
Expand All @@ -38,16 +41,20 @@ def start_listening(self):
device_id = client_socket.recv(1024).decode()
device_secret = client_socket.recv(1024).decode()
if self.authenticate_device(device_id, device_secret):
self.devices.append({'id': device_id, 'socket': client_socket})
thread = threading.Thread(target=self.handle_device, args=(client_socket,))
self.devices.append({"id": device_id, "socket": client_socket})
thread = threading.Thread(
target=self.handle_device, args=(client_socket,)
)
thread.start()
self.threads.append(thread)

def handle_device(self, client_socket):
while True:
data = client_socket.recv(1024)
if data:
print(f'Received data from device {client_socket.getpeername()}: {data.decode()}')
print(
f"Received data from device {client_socket.getpeername()}: {data.decode()}"
)
else:
break

Expand All @@ -65,8 +72,9 @@ def stop(self):
for thread in self.threads:
thread.join()

if __name__ == '__main__':
home_id = 'home123'
home_secret = 'secret123'

if __name__ == "__main__":
home_id = "home123"
home_secret = "secret123"
smart_home = SmartHome(home_id, home_secret)
smart_home.start()

0 comments on commit cd07be6

Please sign in to comment.