Skip to content

Commit

Permalink
Optimized dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Jul 20, 2020
1 parent dcd24a3 commit 0b0f336
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 80 deletions.
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@
'thingsboard_gateway.extensions.rest', 'thingsboard_gateway.extensions.snmp'
],
install_requires=[
'cffi',
'jsonpath-rw',
'regex',
'pip',
'jsonschema==3.1.1',
'lxml',
'paho-mqtt',
'pyserial',
'pytz',
'PyYAML',
'simplejson',
'pyrsistent',
'requests'
],
download_url='https://github.com/thingsboard/thingsboard-gateway/archive/%s.tar.gz' % VERSION,
Expand Down
1 change: 1 addition & 0 deletions thingsboard_gateway/connectors/modbus/modbus_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
except ImportError:
print("Modbus library not found - installing...")
TBUtility.install_package("pymodbus", ">=2.3.0")
TBUtility.install_package('pyserial')
from pymodbus.constants import Defaults

from pymodbus.client.sync import ModbusTcpClient, ModbusUdpClient, ModbusSerialClient, ModbusRtuFramer, ModbusSocketFramer
Expand Down
6 changes: 0 additions & 6 deletions thingsboard_gateway/gateway/tb_gateway_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
from simplejson import load, dumps, loads

from thingsboard_gateway.tb_utility.tb_utility import TBUtility

try:
import pyrsistent
except ImportError:
TBUtility.install_package("pyrsistent")

from thingsboard_gateway.gateway.tb_client import TBClient
from thingsboard_gateway.gateway.tb_updater import TBUpdater
from thingsboard_gateway.gateway.tb_logger import TBLoggerHandler
Expand Down
66 changes: 0 additions & 66 deletions thingsboard_gateway/tb_client/tb_device_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,9 @@
import paho.mqtt.client as paho

from simplejson import dumps
# from jsonschema import Draft7Validator
# from jsonschema import ValidationError

from thingsboard_gateway.tb_utility.tb_utility import TBUtility

#
# KV_SCHEMA = {
# "type": "object",
# "patternProperties":
# {
# ".": {"type": ["integer",
# "string",
# "boolean",
# "number"]}
# },
# "minProperties": 1,
# }
# SCHEMA_FOR_CLIENT_RPC = {
# "type": "object",
# "patternProperties":
# {
# ".": {"type": ["integer",
# "string",
# "boolean",
# "number"]}
# },
# "minProperties": 0,
# }
# TS_KV_SCHEMA = {
# "type": "object",
# "properties": {
# "ts": {
# "type": ["integer"]
# },
# "values": KV_SCHEMA
# },
# "additionalProperties": False
# }
# DEVICE_TS_KV_SCHEMA = {
# "type": "array",
# "items": TS_KV_SCHEMA
# }
# DEVICE_TS_OR_KV_SCHEMA = {
# "type": "array",
# "items": {
# "anyOf":
# [
# TS_KV_SCHEMA,
# KV_SCHEMA
# ]
# }
# }
# RPC_VALIDATOR = Draft7Validator(SCHEMA_FOR_CLIENT_RPC)
# KV_VALIDATOR = Draft7Validator(KV_SCHEMA)
# TS_KV_VALIDATOR = Draft7Validator(TS_KV_SCHEMA)
# DEVICE_TS_KV_VALIDATOR = Draft7Validator(DEVICE_TS_KV_SCHEMA)
# DEVICE_TS_OR_KV_VALIDATOR = Draft7Validator(DEVICE_TS_OR_KV_SCHEMA)

RPC_RESPONSE_TOPIC = 'v1/devices/me/rpc/response/'
RPC_REQUEST_TOPIC = 'v1/devices/me/rpc/request/'
ATTRIBUTES_TOPIC = 'v1/devices/me/attributes'
Expand Down Expand Up @@ -234,14 +179,6 @@ def _on_message(self, client, userdata, message):
content = TBUtility.decode(message)
self._on_decoded_message(content, message)

# @staticmethod
# def validate(validator, data):
# try:
# validator.validate(data)
# except ValidationError as e:
# log.error(e)
# raise e

def _on_decoded_message(self, content, message):
if message.topic.startswith(RPC_REQUEST_TOPIC):
request_id = message.topic[len(RPC_REQUEST_TOPIC):len(message.topic)]
Expand Down Expand Up @@ -305,7 +242,6 @@ def send_rpc_reply(self, req_id, resp, quality_of_service=1, wait_for_publish=Fa
info.wait_for_publish()

def send_rpc_call(self, method, params, callback):
# self.validate(RPC_VALIDATOR, params)
with self._lock:
self.__device_client_rpc_number += 1
self.__device_client_rpc_dict.update({self.__device_client_rpc_number: callback})
Expand All @@ -328,11 +264,9 @@ def publish_data(self, data, topic, qos):
def send_telemetry(self, telemetry, quality_of_service=1):
if not isinstance(telemetry, list) and not (isinstance(telemetry, dict) and telemetry.get("ts") is not None):
telemetry = [telemetry]
# self.validate(DEVICE_TS_OR_KV_VALIDATOR, telemetry)
return self.publish_data(telemetry, TELEMETRY_TOPIC, quality_of_service)

def send_attributes(self, attributes, quality_of_service=1):
# self.validate(KV_VALIDATOR, attributes)
return self.publish_data(attributes, ATTRIBUTES_TOPIC, quality_of_service)

def unsubscribe_from_attribute(self, subscription_id):
Expand Down
12 changes: 9 additions & 3 deletions thingsboard_gateway/tb_utility/tb_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ def get_value(expression, body=None, value_type="string", get_tag=False, express
@staticmethod
def install_package(package, version="upgrade"):
from sys import executable
from subprocess import check_call
from subprocess import check_call, CalledProcessError
result = False
if version.lower() == "upgrade":
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
try:
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
except CalledProcessError:
result = check_call([executable, "-m", "pip", "install", package, "--upgrade"])
else:
from pkg_resources import get_distribution
current_package_version = None
Expand All @@ -166,5 +169,8 @@ def install_package(package, version="upgrade"):
pass
if current_package_version is None or current_package_version != version:
installation_sign = "==" if ">=" not in version else ""
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "--user"])
try:
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "--user"])
except CalledProcessError:
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version])
return result

0 comments on commit 0b0f336

Please sign in to comment.