Skip to content

Commit

Permalink
Merge pull request #17 from KOSASIH/deepsource-transform-d9d5a9e5
Browse files Browse the repository at this point in the history
style: format code with 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
  • Loading branch information
KOSASIH authored May 11, 2024
2 parents 4fdfc00 + 15e0843 commit 5d37d51
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions models/device_drivers/device_communication.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Import necessary libraries
import paho.mqtt.client as mqtt
import coapthon.client as coap
import paho.mqtt.client as mqtt
import requests

# Define a class for device communication


class DeviceCommunication:
def __init__(self, device_config):
# Initialize device communication protocol
self.protocol = device_config['protocol']
self.host = device_config['host']
self.port = device_config['port']
self.topic = device_config['topic']
self.protocol = device_config["protocol"]
self.host = device_config["host"]
self.port = device_config["port"]
self.topic = device_config["topic"]

def mqtt_publish(self, message):
# Publish a message using MQTT protocol
Expand All @@ -36,14 +38,18 @@ def on_message(client, userdata, msg):
def coap_get(self, resource):
# Get a resource using CoAP protocol
client = coap.Client()
client.uri_format = 'coap://{host}:{port}/{resource}'.format(host=self.host, port=self.port, resource=resource)
client.uri_format = "coap://{host}:{port}/{resource}".format(
host=self.host, port=self.port, resource=resource
)
response = client.get()
return response.payload

def coap_put(self, resource, payload):
# Put a payload to a resource using CoAP protocol
client = coap.Client()
client.uri_format = 'coap://{host}:{port}/{resource}'.format(host=self.host, port=self.port, resource=resource)
client.uri_format = "coap://{host}:{port}/{resource}".format(
host=self.host, port=self.port, resource=resource
)
response = client.put(payload)
return response.payload

Expand Down

0 comments on commit 5d37d51

Please sign in to comment.