Skip to content

Commit

Permalink
Merge pull request #303 from ChristianTremblay/develop
Browse files Browse the repository at this point in the history
Adding a real lot of things
  • Loading branch information
ChristianTremblay authored Dec 3, 2021
2 parents d5aed21 + ff3a980 commit 11a4cb4
Show file tree
Hide file tree
Showing 56 changed files with 1,727 additions and 1,526 deletions.
10 changes: 10 additions & 0 deletions .env~
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# InfluxDB Params Example .env file
INFLUXDB_V2_URL=http://192.168.1.10:8086
INFLUXDB_V2_ORG=my-org
INFLUXDB_V2_TOKEN=123456789abcdefg
# INFLUXDB_V2_TIMEOUT=
# INFLUXDB_V2_VERIFY_SSL=
# INFLUXDB_V2_SSL_CA_CERT=
# INFLUXDB_V2_CONNECTION_POOL_MAXSIZE=
# INFLUXDB_V2_AUTH_BASIC=
# INFLUXDB_V2_PROFILERS=
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
pip install flask_bootstrap
pip install colorama
pip install netifaces
pip install python-dotenv
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install .
- name: Lint with flake8
Expand Down Expand Up @@ -68,4 +69,4 @@ jobs:
# env:
# GITHUB_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
# COVERALLS_FLAG_NAME: ${{ matrix.test-name }}
# COVERALLS_PARALLEL: true
# COVERALLS_PARALLEL: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ obj300.bin
wily-report.html
make_doc.bat
tests/manual_test_bokeh.py
.env
samples/pascal_stlouis.py
samples/johnhensen.py
11 changes: 11 additions & 0 deletions BAC0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
except ImportError:
_COMPLETE = False

try:
#
import os

if os.path.isfile("{}/.env".format(os.getcwd())):
from dotenv import load_dotenv

load_dotenv(os.path.join(os.getcwd(), ".env"))
except ImportError:
print("You need to pip install python-dotenv to use your .env file")

from .scripts.Lite import Lite as lite

if _COMPLETE:
Expand Down
4 changes: 2 additions & 2 deletions BAC0/core/app/ScriptApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

class common_mixin:
"""
They take message coming from the network that are not generated from
They take message coming from the network that are not generated from
a request we made.
"""

Expand Down Expand Up @@ -415,7 +415,7 @@ def __init__(
# on the UDP multiplexer
self.bip = BIPBBMD(self.localAddress)
self.annexj = AnnexJCodec()
self.mux = UDPMultiplexer(self.localAddress, noBroadcast=True)
self.mux = UDPMultiplexer(self.localAddress, noBroadcast=False)

# bind the bottom layers
# bind(self.bip, self.annexj, self.mux.annexJ)
Expand Down
50 changes: 37 additions & 13 deletions BAC0/core/devices/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

import os.path

# --- 3rd party modules ---
import sqlite3

try:
import pandas as pd

Expand Down Expand Up @@ -49,7 +46,7 @@
)

# from ...bokeh.BokehRenderer import BokehPlot
from ...sql.sql import SQLMixin
from ...db.sql import SQLMixin
from ...tasks.DoOnce import DoOnce
from .mixins.read_mixin import ReadPropertyMultiple, ReadProperty
from .Virtuals import VirtualPoint
Expand Down Expand Up @@ -77,7 +74,13 @@ def __init__(self):
self.db_name = None
self.segmentation_supported = True
self.history_size = None
self.save_resampling = "1s"
self.clear_history_on_save = None
self.bacnet_properties = {}
self.auto_save = None
self.fast_polling = False
self.vendor_id = 0
self.ping_failures = 0

def __repr__(self):
return "{}".format(self.asdict)
Expand Down Expand Up @@ -156,7 +159,7 @@ def __init__(
self.properties.auto_save = auto_save
self.properties.save_resampling = save_resampling
self.properties.clear_history_on_save = clear_history_on_save
self.properties.default_history_size = history_size
self.properties.history_size = history_size
self._reconnect_on_failure = reconnect_on_failure

self.segmentation_supported = segmentation_supported
Expand Down Expand Up @@ -531,12 +534,14 @@ def _buildPointList(self):
)
)
try:
self.properties.objects_list, self.points, self._list_of_trendlogs = self._discoverPoints(
self.custom_object_list
)
(
self.properties.objects_list,
self.points,
self._list_of_trendlogs,
) = self._discoverPoints(self.custom_object_list)
if self.properties.pollDelay > 0:
self.poll(delay=self.properties.pollDelay)
self.update_history_size(size=self.properties.default_history_size)
self.update_history_size(size=self.properties.history_size)
# self.clear_histories()
except NoResponseFromController as error:
self._log.error("Cannot retrieve object list, disconnecting...")
Expand Down Expand Up @@ -726,7 +731,9 @@ def read_property(self, prop):
request = "{} {} {} {}".format(
self.properties.address, _obj, _instance, _prop
)
val = self.properties.network.read(request, vendor_id=0)
val = self.properties.network.read(
request, vendor_id=self.properties.vendor_id
)
except KeyError as error:
raise Exception("Unknown property : {}".format(error))
return val
Expand Down Expand Up @@ -757,15 +764,15 @@ def write_property(self, prop, value, priority=None):
def update_bacnet_properties(self):
"""
Retrieve bacnet properties for this device
To retrieve something general, forcing vendor id 0
"""
try:
res = self.properties.network.readMultiple(
"{} device {} all".format(
self.properties.address, str(self.properties.device_id)
),
vendor_id=0,
prop_id_required=True,
vendor_id=self.properties.vendor_id,
show_property_name=True,
)
for each in res:
if not each:
Expand Down Expand Up @@ -795,6 +802,19 @@ def update_description(self, value):
)
self.properties.description = self.read_property("description")

def ping(self):
try:
if self.read_property("objectName") == self.properties.name:
self.properties.ping_failures = 0
return True
else:
self.properties.ping_failures += 1
return False
except NoResponseFromController as e:
self._log.error("Error in ping : {}".format(e))
self.properties.ping_failures += 1
return False

def __repr__(self):
return "{} / Connected".format(self.properties.name)

Expand Down Expand Up @@ -1061,6 +1081,10 @@ def initialize_device_from_db(self):
self.properties.serving_chart = {}
self.properties.charts = []
self.properties.multistates = self._props["multistates"]
self.properties.auto_save = self._props["auto_save"]
self.properties.save_resampling = self._props["save_resampling"]
self.properties.clear_history_on_save = self._props["clear_history_on_save"]
self.properties.default_history_size = self._props["history_size"]
self._log.info("Device restored from db")
self._log.info(
'You can reconnect to network using : "device.connect(network=bacnet)"'
Expand Down
Loading

0 comments on commit 11a4cb4

Please sign in to comment.