Skip to content

Commit

Permalink
Merge pull request #1097 from samson0v/feature/new-remote-configurator
Browse files Browse the repository at this point in the history
Changed Remote Configurator due to Widget Update
  • Loading branch information
imbeacon authored Sep 18, 2023
2 parents 6a903bd + 1915afd commit 729a4db
Show file tree
Hide file tree
Showing 90 changed files with 2,161 additions and 1,411 deletions.
4 changes: 2 additions & 2 deletions tests/connectors/connector_tests_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from thingsboard_gateway.gateway.tb_gateway_service import DEFAULT_CONNECTORS
from thingsboard_gateway.tb_utility.tb_loader import TBModuleLoader


logging.basicConfig(level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
Expand All @@ -32,7 +33,7 @@

class ConnectorTestBase(unittest.TestCase):
DATA_PATH = path.join(path.dirname(path.dirname(path.abspath(__file__))),
"data" + path.sep)
"data" + path.sep)

def setUp(self):
self.gateway = Mock(spec=TBGatewayService)
Expand All @@ -49,7 +50,6 @@ def _load_data_file(self, filename, connector_type):
datafile = load(required_file)
return datafile


def _create_connector(self, config_filename, connector_type=None):
if connector_type is None:
class_name = self.__class__.__name__.lower()
Expand Down
14 changes: 8 additions & 6 deletions tests/connectors/test_can_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from random import choice, randint, uniform
from string import ascii_lowercase
from time import sleep
from unittest.mock import Mock
from unittest.mock import Mock, patch

from thingsboard_gateway.gateway.tb_gateway_service import TBGatewayService
from can import Notifier, BufferedReader, Bus, Message
Expand Down Expand Up @@ -67,14 +67,16 @@ def _create_bus(self):

def _create_connector(self, config_file_name):
with open(self.CONFIG_PATH + config_file_name, 'r', encoding="UTF-8") as file:
self.config = load(file)
self.connector = CanConnector(self.gateway, self.config, "can")
self.connector.open()
sleep(1) # some time to init
try:
self.config = load(file)
self.connector = CanConnector(self.gateway, self.config, "can")
self.connector.open()
sleep(1) # some time to init
except Exception as e:
print(e)


class CanConnectorPollingTests(CanConnectorTestsBase):

def test_polling_once(self):
self._create_connector("polling_once.json")
config = self.config["devices"][0]["attributes"][0]
Expand Down
2 changes: 1 addition & 1 deletion tests/connectors/test_odbc_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


@unittest.skipIf(not IS_ODBC_DRIVER_INSTALLED,
"To run ODBC tests install " + ODBC_DRIVER_WITH_STORED_PROCEDURE + "or" +
"To run ODBC tests install " + ODBC_DRIVER_WITH_STORED_PROCEDURE + " or " +
ODBC_DRIVER_WITHOUT_STORED_PROCEDURE + " ODBC driver")
class OdbcConnectorTests(unittest.TestCase):
CONFIG_PATH = path.join(path.dirname(path.dirname(path.abspath(__file__))),
Expand Down
2 changes: 1 addition & 1 deletion tests/connectors/test_opcua_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __server_run(self, test_server):
class SubHandler(object):
def datachange_notification(self, node, val, data):
print("Python: New data change event", node, val)

def event_notification(self, event):
print("Python: New event", event)

Expand Down
3 changes: 2 additions & 1 deletion tests/converters/test_bytes_can_downlink_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import struct
import unittest
from random import randint, uniform, choice
Expand All @@ -23,7 +24,7 @@
class BytesCanDownlinkConverterTests(unittest.TestCase):

def setUp(self):
self.converter = BytesCanDownlinkConverter()
self.converter = BytesCanDownlinkConverter(logger=logging.getLogger('converter'))

def test_data_in_hex_in_conf(self):
expected_can_data = [0, 1, 2, 3]
Expand Down
3 changes: 2 additions & 1 deletion tests/converters/test_bytes_can_uplink_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import _struct
import unittest
from math import isclose
Expand All @@ -24,7 +25,7 @@
class BytesCanUplinkConverterTests(unittest.TestCase):

def setUp(self):
self.converter = BytesCanUplinkConverter()
self.converter = BytesCanUplinkConverter(logger=logging.getLogger('converter'))

def _has_no_data(self, data):
return bool(data is None or not data.get("attributes", []) and not data.get("telemetry", []))
Expand Down
3 changes: 2 additions & 1 deletion tests/converters/test_bytes_modbus_uplink_converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import unittest

from pymodbus.constants import Endian
Expand Down Expand Up @@ -175,7 +176,7 @@ def __init__(self, registers):
{tag: {"input_data": DummyResponse(builder.to_registers()), "data_sent": tag_dict[tag]}})
builder.reset()

converter = BytesModbusUplinkConverter({"deviceName": "Modbus Test", "deviceType": "default", "unitId": 1})
converter = BytesModbusUplinkConverter({"deviceName": "Modbus Test", "deviceType": "default", "unitId": 1}, logger=logging.getLogger('converter'))
result = converter.convert(test_modbus_convert_config, test_modbus_body_to_convert)
self.assertDictEqual(result, test_modbus_result)

Expand Down
17 changes: 9 additions & 8 deletions tests/converters/test_mqtt_json_uplink_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import unittest
from random import randint

Expand All @@ -25,31 +26,31 @@ class JsonMqttUplinkConverterTests(unittest.TestCase):

def test_topic_name_and_type(self):
topic, config, data = self._get_device_1_test_data()
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_data = converter.convert(topic, data)

self.assertEqual(self.DEVICE_NAME, converted_data["deviceName"])
self.assertEqual(self.DEVICE_TYPE, converted_data["deviceType"])

def test_json_name_and_type(self):
topic, config, data = self._get_device_2_test_data()
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_data = converter.convert(topic, data)

self.assertEqual(self.DEVICE_NAME, converted_data["deviceName"])
self.assertEqual(self.DEVICE_TYPE, converted_data["deviceType"])

def test_glob_matching(self):
topic, config, data = self._get_device_1_test_data()
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_data = converter.convert(topic, data)
self.assertDictEqual(data, self._convert_to_dict(converted_data.get('telemetry')))
self.assertDictEqual(data, self._convert_to_dict(converted_data.get('attributes')))

def test_array_result(self):
topic, config, single_data = self._get_device_1_test_data()
array_data = [single_data, single_data];
converter = JsonMqttUplinkConverter(config)
array_data = [single_data, single_data]
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_array_data = converter.convert(topic, array_data)

self.assertTrue(isinstance(converted_array_data, list))
Expand All @@ -59,21 +60,21 @@ def test_array_result(self):

def test_without_send_on_change_option(self):
topic, config, data = self._get_device_1_test_data()
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_array_data = converter.convert(topic, data)
self.assertIsNone(converted_array_data.get(SEND_ON_CHANGE_PARAMETER))

def test_with_send_on_change_option_disabled(self):
topic, config, data = self._get_device_1_test_data()
config["converter"][SEND_ON_CHANGE_PARAMETER] = False
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_array_data = converter.convert(topic, data)
self.assertFalse(converted_array_data.get(SEND_ON_CHANGE_PARAMETER))

def test_with_send_on_change_option_enabled(self):
topic, config, data = self._get_device_1_test_data()
config["converter"][SEND_ON_CHANGE_PARAMETER] = True
converter = JsonMqttUplinkConverter(config)
converter = JsonMqttUplinkConverter(config, logger=logging.getLogger('converter'))
converted_array_data = converter.convert(topic, data)
self.assertTrue(converted_array_data.get(SEND_ON_CHANGE_PARAMETER))

Expand Down
3 changes: 2 additions & 1 deletion tests/converters/test_odbc_uplink_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import unittest
from random import randint, uniform, choice
from string import ascii_lowercase
Expand All @@ -22,7 +23,7 @@
class OdbcUplinkConverterTests(unittest.TestCase):

def setUp(self):
self.converter = OdbcUplinkConverter()
self.converter = OdbcUplinkConverter(logger=logging.getLogger('converter'))
self.db_data = {"boolValue": True,
"intValue": randint(0, 256),
"floatValue": uniform(-3.1415926535, 3.1415926535),
Expand Down
87 changes: 0 additions & 87 deletions thingsboard_gateway/config/logs.conf

This file was deleted.

Loading

0 comments on commit 729a4db

Please sign in to comment.