Skip to content

Commit

Permalink
Merge pull request #189 from ChristianTremblay/release_200220
Browse files Browse the repository at this point in the history
Release 200220
  • Loading branch information
ChristianTremblay committed Feb 21, 2020
2 parents 7a208d4 + a1b3f8e commit f823265
Show file tree
Hide file tree
Showing 31 changed files with 1,140 additions and 153 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: python
python:
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- '3.8'

bundler_args: "--retry 3"
install:
- pip install -r requirements.txt
Expand All @@ -13,6 +14,7 @@ install:
- pip install pandas
- pip install bokeh
- pip install flask
- pip install flask_bootstrap

script:
- coverage run --source BAC0 -m pytest -v
Expand All @@ -25,6 +27,6 @@ deploy:
secure: Wgb3PCFut7RCbajytFP4IchYZ1ghA6UH0qjLtBm5qdCYesQKipo3p4Pm5N2IlyOfen1RGd0igaksQqHj19bpwoMXvvR6Rb/Q/eqON+mUWtN1BDPJFh60bWfyJ9c3ZsrCmkVChIQxOPwmyUTX23LV+1Z4nuRdlktdzIDbBZn847BesVylHP9gQ7CKZb3Fxr69ZeOtMbTwAyfK1BbMcFjXMQQGzl4W0R9CuFH7eDa8Ih/fUsvUupDNDKwl6hyKNWwtzDu/DPP0TDBgQexjntIo+MkByatmXyGCoYuHzIrjIMKHCxHGtciCnD6cNGT9meUkwjiCHITfRKCdCAZmwfCeVJuB/AsjgMj4M/dA6kMklqs4A+DEqbw+JiYxMSP1VZL5Sy864Api+7Rhm7tQNNPzjQywSlCjwKexEmSdbKy3M0A7OkORzFFsWDE5WUG1OjR8iJGnhKINmAjfvPhlZCjf/9Dgsd5EA735WiUmhTjj7Vzu3MTtMOzg95UtdDVekqZHf4Yjk6cjhqJQxKM0GZSomAdTZhpYiFFMXgpiup9hUmRujPvGMOci/vydi3rWEe4QARGdDZb/6spydyCy/9sw1O+D93hzLq09fSm3IWN/awdj0dkbhKbHSfH+Gq/436DgRdG/5GlevL3u8b/QARGu2bAXzNJJIuBcGcesTzLch30=
on:
branch: master
python: '3.7'
python: '3.8'
distributions: sdist bdist_wheel
repo: ChristianTremblay/BAC0
6 changes: 4 additions & 2 deletions BAC0/core/app/ScriptApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ def do_IAmRequest(self, apdu):

def do_WhoIsRequest(self, apdu):
"""Respond to a Who-Is request."""
self._log.debug("do_WhoIsRequest {!r}".format(apdu))

# build a key from the source and parameters
key = (
str(apdu.pduSource),
apdu.deviceInstanceRangeLowLimit,
apdu.deviceInstanceRangeHighLimit,
)
self._log.debug(
"do_WhoIsRequest from {} | {} to {}".format(key[0], key[1], key[2])
)

# count the times this has been received
self.who_is_counter[key] += 1
Expand All @@ -153,7 +155,7 @@ def do_WhoIsRequest(self, apdu):
if self.localDevice.objectIdentifier[1] > high_limit:
return
# generate an I-Am
self._log.info("Responding to Who is by a Iam")
self._log.debug("Responding to Who is by a Iam")
self.iam_req.pduDestination = apdu.pduSource
iocb = IOCB(self.iam_req) # make an IOCB
deferred(self.request_io, iocb)
Expand Down
17 changes: 12 additions & 5 deletions BAC0/core/devices/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
NoResponseFromController,
SegmentationNotSupported,
BadDeviceDefinition,
RemovedPointException,
)

# from ...bokeh.BokehRenderer import BokehPlot
Expand All @@ -68,8 +69,6 @@ def __init__(self):
self.pollDelay = None
self.objects_list = None
self.pss = ServicesSupported()
# self.serving_chart = None
# self.charts = None
self.multistates = None
self.db_name = None
self.segmentation_supported = True
Expand Down Expand Up @@ -450,12 +449,13 @@ def _init_state(self):
self._buildPointList()
self.properties.network.register_device(self)

def disconnect(self, save_on_disconnect=True):
def disconnect(self, save_on_disconnect=True, unregister=True):
self._log.info("Wait while stopping polling")
self.poll(command="stop")
if save_on_disconnect:
self.save()
self.properties.network.unregister_device(self)
if unregister:
self.properties.network.unregister_device(self)
self.new_state(DeviceFromDB)

def connect(self, *, db=None):
Expand Down Expand Up @@ -683,6 +683,10 @@ def read_property(self, prop):
# pass
if isinstance(prop, tuple):
_obj, _instance, _prop = prop
elif isinstance(prop, str):
_obj = "device"
_instance = self.properties.device_id
_prop = prop
else:
raise ValueError(
"Please provide property using tuple with object, instance and property"
Expand Down Expand Up @@ -991,7 +995,10 @@ def initialize_device_from_db(self):
self._props = self.read_dev_prop(self.properties.db_name)
self.points = []
for point in self.points_from_sql(self.properties.db_name):
self.points.append(OfflinePoint(self, point))
try:
self.points.append(OfflinePoint(self, point))
except RemovedPointException:
continue

self.properties = DeviceProperties()
self.properties.db_name = dbname
Expand Down
15 changes: 11 additions & 4 deletions BAC0/core/devices/Points.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
# --- this application's modules ---
from ...tasks.Poll import SimplePoll as Poll
from ...tasks.Match import Match, Match_Value
from ..io.IOExceptions import NoResponseFromController, UnknownPropertyError
from ..io.IOExceptions import (
NoResponseFromController,
UnknownPropertyError,
RemovedPointException,
)
from ..utils.notes import note_and_log


Expand Down Expand Up @@ -131,7 +135,7 @@ def value(self):
)
self._trend(res)
except Exception as e:
raise Exception("Problem reading : {} | {}".format(self.properties.name, e))
raise

return res

Expand Down Expand Up @@ -701,7 +705,7 @@ def value(self):
self._trend(res)

except Exception as e:
raise Exception("Problem reading : {} | {}".format(self.properties.name, e))
raise

if res == "inactive":
self._key = 0
Expand Down Expand Up @@ -903,7 +907,10 @@ def __init__(self, device, name):
self.properties = PointProperties()
self.properties.device = device
dev_name = self.properties.device.properties.db_name
props = self.properties.device.read_point_prop(dev_name, name)
try:
props = self.properties.device.read_point_prop(dev_name, name)
except RemovedPointException:
raise

self.properties.name = props["name"]
self.properties.type = props["type"]
Expand Down
11 changes: 9 additions & 2 deletions BAC0/core/devices/create_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
Property,
register_object_type,
)

from bacpypes.primitivedata import CharacterString, Date, Time, Real, Boolean
from bacpypes.constructeddata import ArrayOf
from bacpypes.basetypes import EngineeringUnits, DateTime
from bacpypes.basetypes import EngineeringUnits, DateTime, PriorityArray

from .mixins.CommandableMixin import LocalBinaryOutputObjectCmd


def _make_mutable(obj, identifier="presentValue", mutable=True):
Expand All @@ -36,6 +39,7 @@ def create_MV(
presentValue=pv,
numberOfStates=len(states),
stateText=ArrayOf(CharacterString)(states),
priorityArray=PriorityArray(),
)
msvo = _make_mutable(msvo, mutable=pv_writable)
return msvo
Expand All @@ -48,6 +52,7 @@ def create_AV(oid=1, pv=0, name="AV", units=None, pv_writable=False):
presentValue=pv,
units=units,
relinquishDefault=0,
priorityArray=PriorityArray(),
)
avo = _make_mutable(avo, mutable=pv_writable)
avo = _make_mutable(avo, identifier="relinquishDefault", mutable=pv_writable)
Expand All @@ -63,6 +68,7 @@ def create_BV(
presentValue=pv,
activeText=activeText,
inactiveText=inactiveText,
priorityArray=PriorityArray(),
)
bvo = _make_mutable(bvo, mutable=pv_writable)
return bvo
Expand Down Expand Up @@ -97,6 +103,7 @@ def create_AO(oid=1, pv=0, name="AO", units=None, pv_writable=False):
objectName=name,
presentValue=pv,
units=units,
priorityArray=PriorityArray(),
)
aoo = _make_mutable(aoo, mutable=pv_writable)
return aoo
Expand All @@ -105,7 +112,7 @@ def create_AO(oid=1, pv=0, name="AO", units=None, pv_writable=False):
def create_BO(
oid=1, pv=0, name="BO", activeText="On", inactiveText="Off", pv_writable=False
):
boo = BinaryOutputObject(
boo = LocalBinaryOutputObjectCmd(
objectIdentifier=("binaryOutput", oid),
objectName=name,
presentValue=pv,
Expand Down
Loading

0 comments on commit f823265

Please sign in to comment.