Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1fc78c6
implement base bacnet connector test
Andry925 Aug 1, 2025
d4023f2
refactor on_attribute_update method inside bacnet connector
Andry925 Aug 5, 2025
7115c62
implement functional pattern for bacnet tests
Andry925 Aug 5, 2025
d49c9ef
implement basic tests for get_device_by_name method
Andry925 Aug 5, 2025
7a3a78c
refactor bacnet on_attribute_update connector
Andry925 Aug 7, 2025
1a8be2f
basic unit-tests for on_attribute_updates
Andry925 Aug 7, 2025
c3b6922
add configuration for on_attribute_update tests
Andry925 Aug 7, 2025
74eac8f
write-unit-tests for bacnet on-attribute-updates connector
Andry925 Aug 8, 2025
d857bcb
refactor bacnet connector by adding more explicit error handling and …
Andry925 Aug 8, 2025
4578236
add more configs to test on_attribute_update bacnet
Andry925 Aug 8, 2025
4fc28f5
refactor reserved rpc methods for bacnet connector
Andry925 Aug 10, 2025
e6e2ff1
add more robust handling on ValueError
Andry925 Aug 10, 2025
1c7a754
implement unit-tests for reserved rpc
Andry925 Aug 10, 2025
cf34bec
fix errors inside bacnet connector, add better log messages and more …
Andry925 Aug 11, 2025
bfab27a
add license to tests
Andry925 Aug 11, 2025
fc63ff9
Merge branch 'master' into tests/write-unit-tests-rpc-attribute_updat…
Andry925 Aug 12, 2025
12fd27e
fix error with update attribute with rpc using readProperty requestType
Andry925 Aug 12, 2025
68d06b4
add configs for bacnet device rpc tests
Andry925 Aug 12, 2025
f79971b
implement tests for device rpc
Andry925 Aug 12, 2025
d3f4b31
update bacnet on_attribute_update tests
Andry925 Aug 12, 2025
a2f5f9c
add whitespaces at the end of each line
Andry925 Aug 12, 2025
ae09d0d
Revert "add whitespaces at the end of each line"
Andry925 Aug 12, 2025
a7b4b72
add whitespaces at the end of each line
Andry925 Aug 12, 2025
0996dba
remove unnecessary idents from bacnet connector
Andry925 Aug 12, 2025
e8c5e77
remove asyncio.run_coroutine_threadsafe, add custom task handling
Andry925 Aug 13, 2025
5686979
fix bacnet-unit server side rpc tests
Andry925 Aug 13, 2025
78947dd
fix on_attributes_update bacnet tests
Andry925 Aug 13, 2025
d7b45f1
Merge branch 'master' into tests/write-unit-tests-rpc-attribute_updat…
Andry925 Aug 14, 2025
78cfb37
Merge branch 'thingsboard:master' into tests/write-unit-tests-rpc-att…
Andry925 Aug 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions tests/unit/connectors/bacnet/bacnet_base_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2025. ThingsBoard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from asyncio import Queue, new_event_loop
from os import path
from unittest import IsolatedAsyncioTestCase
from unittest.mock import MagicMock
from bacpypes3.apdu import IAmRequest
from bacpypes3.pdu import Address
from simplejson import load
from thingsboard_gateway.connectors.bacnet.device import Device, Devices
from thingsboard_gateway.connectors.bacnet.bacnet_connector import AsyncBACnetConnector


class BacnetBaseTestCase(IsolatedAsyncioTestCase):
CONFIG_PATH = path.join(path.dirname(path.abspath(__file__)), 'data')
DEVICE_NAME = 'test emulator device'
CONNECTOR_TYPE = 'bacnet'

async def asyncSetUp(self):
self.connector: AsyncBACnetConnector = AsyncBACnetConnector.__new__(AsyncBACnetConnector)
self.connector._AsyncBACnetConnector__log = logging.getLogger('Bacnet test')
self.connector.loop = new_event_loop()
self.connector._AsyncBACnetConnector__process_device_queue = Queue(1_000_000)
self.connector._AsyncBACnetConnector__process_device_rescan_queue = Queue(1_000_000)
self.connector._AsyncBACnetConnector__devices = Devices()
self.device = self.create_fake_device(
attribute_update_config_path='attribute_updates/on_attribute_updates_bacnet_config.json')
await self.connector._AsyncBACnetConnector__devices.add(self.device)
if not hasattr(self.connector, '_AsyncBACnetConnector__gateway'):
self.connector._AsyncBACnetConnector__gateway = MagicMock()

async def asyncTearDown(self):
log = logging.getLogger('Bacnet test')
for handler in list(log.handlers):
log.removeHandler(handler)
self.connector = None
self.device = None
await super().asyncTearDown()

@staticmethod
def convert_json(config_path):
with open(config_path, 'r') as config_file:
config = load(config_file)
return config

@staticmethod
def create_fake_apdu_i_am_request(
addr: str = "192.168.1.136:47809",
device_id: int = 1234,
device_name: str = "test emulator device",
max_apdu: int = 1476,
segmentation: str = "segmentedBoth",
vendor_id: int = 15,
):
apdu = IAmRequest(
iAmDeviceIdentifier=("device", device_id),
maxAPDULengthAccepted=max_apdu,
segmentationSupported=segmentation,
vendorID=vendor_id,
)
apdu.pduSource = Address(addr)
apdu.deviceName = device_name
apdu.routerName = None
apdu.routerAddress = None
apdu.routerId = None
apdu.routerVendorId = None

return apdu

def create_fake_device(self, attribute_update_config_path):
device = Device(
connector_type=self.CONNECTOR_TYPE,
config=self.convert_json(path.join(self.CONFIG_PATH, attribute_update_config_path)),
i_am_request=self.create_fake_apdu_i_am_request(),
reading_queue=self.connector._AsyncBACnetConnector__process_device_queue,
rescan_queue=self.connector._AsyncBACnetConnector__process_device_rescan_queue,
logger=self.connector._AsyncBACnetConnector__log,
converter_logger=MagicMock(),
)
return device
Loading
Loading