Skip to content

Commit

Permalink
Merge pull request #351 from ChristianTremblay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ChristianTremblay authored Sep 22, 2022
2 parents 11a4cb4 + 2ec60ae commit 8e2f62b
Show file tree
Hide file tree
Showing 24 changed files with 394 additions and 179 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ tests/manual_test_bokeh.py
.env
samples/pascal_stlouis.py
samples/johnhensen.py
/samples/Climatic-chamber-.ipynb
samples/bartinglmqtt.py
samples/bartling2.py
samples/ferkelcode.py
15 changes: 9 additions & 6 deletions BAC0/core/devices/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,11 @@ def ping(self):
self.properties.ping_failures += 1
return False
except NoResponseFromController as e:
self._log.error("Error in ping : {}".format(e))
self._log.error(
"{} ({})| Ping failure ({}).".format(
self.properties.name, self.properties.address, e
)
)
self.properties.ping_failures += 1
return False

Expand Down Expand Up @@ -883,11 +887,10 @@ def connect(self, *, db=None):
else:
segmentation_supported = True

if name:
if segmentation_supported:
self.new_state(RPMDeviceConnected)
else:
self.new_state(RPDeviceConnected)
if segmentation_supported:
self.new_state(RPMDeviceConnected)
else:
self.new_state(RPDeviceConnected)

except SegmentationNotSupported:
self.segmentation_supported = False
Expand Down
10 changes: 6 additions & 4 deletions BAC0/core/devices/Trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ def update_properties(self):
raise Exception("Problem reading trendLog informations: {}".format(error))

def _total_record_count(self):
self.properties.total_record_count = self.properties.device.properties.network.read(
"{addr} trendLog {oid} totalRecordCount".format(
addr=self.properties.device.properties.address,
oid=str(self.properties.oid),
self.properties.total_record_count = (
self.properties.device.properties.network.read(
"{addr} trendLog {oid} totalRecordCount".format(
addr=self.properties.device.properties.address,
oid=str(self.properties.oid),
)
)
)
return self.properties.total_record_count
Expand Down
12 changes: 10 additions & 2 deletions BAC0/core/devices/local/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from ...utils.notes import note_and_log
from ....scripts.Base import Base
from ...app.ScriptApplication import BAC0Application, BAC0BBMDDeviceApplication, BAC0ForeignDeviceApplication
from ...app.ScriptApplication import (
BAC0Application,
BAC0BBMDDeviceApplication,
BAC0ForeignDeviceApplication,
)

from bacpypes.object import (
AnalogInputObject,
Expand Down Expand Up @@ -182,7 +186,11 @@ def clear_objects():
def add_objects_to_application(self, app):
if isinstance(app, Base):
app = app.this_application
if not (isinstance(app, BAC0Application) or isinstance(app, BAC0ForeignDeviceApplication) or isinstance(app, BAC0BBMDDeviceApplication)):
if not (
isinstance(app, BAC0Application)
or isinstance(app, BAC0ForeignDeviceApplication)
or isinstance(app, BAC0BBMDDeviceApplication)
):
raise TypeError("Provide BAC0Application object or BAC0 Base instance")
for k, v in self.objects.items():
try:
Expand Down
17 changes: 14 additions & 3 deletions BAC0/core/devices/mixins/read_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Licensed under LGPLv3, see file LICENSE in this source tree.
#
"""
read_mixin.py - Add ReadProperty and ReadPropertyMultiple to a device
read_mixin.py - Add ReadProperty and ReadPropertyMultiple to a device
"""
# --- standard Python modules ---

Expand Down Expand Up @@ -203,6 +203,11 @@ def _discoverPoints(self, custom_object_list=None):
obj_cls=EnumPoint, obj_type="multi", objList=objList
)
)
points.extend(
self._process_new_objects(
obj_cls=NumericPoint, obj_type="loop", objList=objList
)
)
points.extend(
self._process_new_objects(
obj_cls=StringPoint, obj_type="characterstringValue", objList=objList
Expand Down Expand Up @@ -259,6 +264,8 @@ def _process_new_objects(
prop_list = "objectName presentValue inactiveText activeText description"
elif obj_type == "multi":
prop_list = "objectName presentValue stateText description"
elif obj_type == "loop":
prop_list = "objectName presentValue description"
elif obj_type == "characterstringValue":
prop_list = "objectName presentValue"
elif obj_type == "datetimeValue":
Expand Down Expand Up @@ -296,7 +303,7 @@ def _find_propid_index(key):
pointName = point_infos[_find_propid_index("objectName")]
presentValue = point_infos[_find_propid_index("presentValue")]
if presentValue != None:
if obj_type == "analog":
if obj_type == "analog" or obj_type == "loop":
presentValue = float(presentValue)
elif obj_type == "multi":
presentValue = int(presentValue)
Expand Down Expand Up @@ -362,6 +369,10 @@ def _process_new_objects(
units_state = self.read_single(
"{} {} stateText ".format(point_type, point_address)
)
elif obj_type == "loop":
units_state = self.read_single(
"{} {} units ".format(point_type, point_address)
)
elif obj_type == "binary":
units_state = (
(
Expand All @@ -381,7 +392,7 @@ def _process_new_objects(
presentValue = self.read_single(
"{} {} presentValue ".format(point_type, point_address)
)
if obj_type == "analog":
if (obj_type == "analog" or obj_type == "loop") and presentValue:
presentValue = float(presentValue)

_newpoints.append(
Expand Down
6 changes: 3 additions & 3 deletions BAC0/core/functions/DeviceCommunicationControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def dcc(self, address=None, duration=None, password=None, state=None):

# build a request
request = DeviceCommunicationControlRequest()
request.enableDisable = DeviceCommunicationControlRequestEnableDisable.enumerations[
state
]
request.enableDisable = (
DeviceCommunicationControlRequestEnableDisable.enumerations[state]
)
request.pduDestination = Address(address)
if duration:
request.duration = Unsigned16(duration)
Expand Down
6 changes: 3 additions & 3 deletions BAC0/core/functions/Reinitialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def reinitialize(self, address=None, password=None, state="coldstart"):

# build a request
request = ReinitializeDeviceRequest()
request.reinitializedStateOfDevice = ReinitializeDeviceRequestReinitializedStateOfDevice.enumerations[
state
]
request.reinitializedStateOfDevice = (
ReinitializeDeviceRequestReinitializedStateOfDevice.enumerations[state]
)
request.pduDestination = Address(address)
request.password = CharacterString(password)

Expand Down
19 changes: 11 additions & 8 deletions BAC0/core/functions/Schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _set_value(v):
if dict_schedule["states"] == ["inactive", "active"]:
return Integer(dict_schedule["states"][v])
else:
return Integer(dict_schedule["states"][v] - 1)
return Enumerated(dict_schedule["states"][v] - 1)

daily_schedules = []
for day in Schedule.days:
Expand Down Expand Up @@ -261,7 +261,8 @@ def _read(prop):
presentValue = presentValue.value
else:
schedule["states"] = _state_text
presentValue = "{}".format(presentValue.value)
if presentValue is not None:
presentValue = "{}".format(presentValue.value)
schedule["reliability"] = reliability
schedule["priority"] = priority
schedule["presentValue"] = presentValue
Expand All @@ -281,12 +282,14 @@ def decode_dailySchedule(self, dailySchedule, states, offset_MV):
hour, minute, second, hundreth = each.time
_time = dt_time(hour, minute, second, hundreth).strftime("%H:%M")
try:
if states == ["inactive", "active"]:
_value = states[int(each.value.value)]
elif states == "analog":
_value = float(each.value.value)
else:
_value = states[int(each.value.value) - offset_MV]
_value = None
if each.value.value is not None:
if states == ["inactive", "active"]:
_value = states[int(each.value.value)]
elif states == "analog":
_value = float(each.value.value)
else:
_value = states[int(each.value.value) - offset_MV]
events.append((_time, _value))
except IndexError:
events.append((_time, "??? ({})".format(each.value.value)))
Expand Down
2 changes: 1 addition & 1 deletion BAC0/core/functions/TimeSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def local_date(self):

def utcOffset(self):
"Returns UTC offset in minutes"
return self.now.astimezone().utcoffset().total_seconds() / 60
return round(self.now.astimezone().utcoffset().total_seconds() / 60)

def is_dst(self):
return self.timezone.dst(self.now) != dt.timedelta(0)
Expand Down
Loading

0 comments on commit 8e2f62b

Please sign in to comment.