-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1607 from samson0v/issues/iotgw-376
Added Async BACnet Connector
- Loading branch information
Showing
28 changed files
with
1,251 additions
and
400 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
for_build/etc/thingsboard-gateway/extensions/bacnet_old/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2022. 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. |
13 changes: 13 additions & 0 deletions
13
for_build/etc/thingsboard-gateway/extensions/modbus_old/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2022. 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2024. 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. | ||
|
||
from bacpypes3.ipv4.app import NormalApplication as App | ||
from bacpypes3.local.device import DeviceObject | ||
from bacpypes3.pdu import Address | ||
|
||
from thingsboard_gateway.connectors.bacnet.entities.device_object_config import DeviceObjectConfig | ||
|
||
|
||
class Application(App): | ||
def __init__(self, device_object_config: DeviceObjectConfig, indication_callback, logger): | ||
self.__device_object_config = device_object_config | ||
self.__device_object = DeviceObject(**self.__device_object_config.device_object_config) | ||
super().__init__(self.__device_object, Address(self.__device_object_config.address)) | ||
|
||
self.__log = logger | ||
self.__indication_callback = indication_callback | ||
|
||
async def indication(self, apdu) -> None: | ||
self.__log.debug(f"(indication) Received APDU: {apdu}") | ||
await super().indication(apdu) | ||
self.__indication_callback(apdu) | ||
|
||
async def do_who_is(self, device_address): | ||
devices = await self.who_is(address=Address(device_address), | ||
timeout=self.__device_object_config.device_discovery_timeout) | ||
if len(devices): | ||
return devices[0] |
73 changes: 73 additions & 0 deletions
73
thingsboard_gateway/connectors/bacnet/backward_compatibility_adapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2024. 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. | ||
|
||
from copy import deepcopy | ||
|
||
|
||
class BackwardCompatibilityAdapter: | ||
def __init__(self, config, logger): | ||
self.__log = logger | ||
self.__config = deepcopy(config) | ||
|
||
def convert(self): | ||
try: | ||
self.__convert_application_section() | ||
self.__convert_device_section() | ||
except Exception as e: | ||
self.__log.error('Error converting old config: %s', e) | ||
|
||
return self.__config | ||
|
||
|
||
def __convert_application_section(self): | ||
general_section = self.__config.pop('general', {}) | ||
self.__config['application'] = general_section | ||
|
||
def __convert_device_section(self): | ||
for device in self.__config.get('devices', []): | ||
self.__convert_device_info_section(device) | ||
|
||
for section in ('attributes', 'timeseries'): | ||
for item_config in device.get(section, []): | ||
self.__convert_object_id(item_config) | ||
|
||
for attr_update_config in device.get('attributeUpdates', []): | ||
self.__convert_object_id(attr_update_config) | ||
|
||
for rpc_config in device.get('rpc', []): | ||
self.__convert_object_id(rpc_config) | ||
|
||
@staticmethod | ||
def __convert_device_info_section(old_device_config): | ||
device_name = old_device_config.pop('deviceName') | ||
device_type = old_device_config.pop('deviceType', 'default') | ||
|
||
old_device_config['deviceInfo'] = { | ||
'deviceNameExpressionSource': 'expression', | ||
'deviceProfileExpressionSource': 'expression', | ||
'deviceNameExpression': device_name, | ||
'deviceProfileExpression': device_type | ||
} | ||
|
||
@staticmethod | ||
def __convert_object_id(old_item_config): | ||
old_object_id = old_item_config.pop('objectId') | ||
(object_type, object_id) = old_object_id.split(':') | ||
old_item_config['objectType'] = object_type | ||
old_item_config['objectId'] = object_id | ||
|
||
@staticmethod | ||
def is_old_config(config): | ||
if config.get('general'): | ||
return True |
Oops, something went wrong.