Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ChristianTremblay/BAC0 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Dec 13, 2024
2 parents 6adec92 + f7dd263 commit 8df73d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 56 deletions.
8 changes: 5 additions & 3 deletions BAC0/core/devices/Points.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async def priority(self, priority=None):
return None
return val

def _trend(self, res: t.Union[float, int, str]) -> None:
def _trend(self, res: t.Optional[t.Union[float, int, str]]) -> None:
now = datetime.now().astimezone()
self._history.timestamp.append(now)
self._history.value.append(res)
Expand Down Expand Up @@ -853,7 +853,8 @@ def __init__(
self.properties.units_state = tuple(str(x) for x in units_state)

def _trend(self, res):
res = "1: active" if res == BinaryPV.active else "0: inactive"
if res is not None:
res = "1: active" if res == BinaryPV.active else "0: inactive"
super()._trend(res)

@property
Expand Down Expand Up @@ -989,7 +990,8 @@ def __init__(
)

def _trend(self, res):
res = f"{res}: {self.get_state(res)}"
if res is not None:
res = f"{res}: {self.get_state(res)}"
super()._trend(res)

@property
Expand Down
77 changes: 25 additions & 52 deletions BAC0/core/functions/Alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,61 +188,34 @@ async def whohas(
self,
object_id=None,
object_name=None,
instance_range_low_limit=0,
instance_range_high_limit=4194303,
low_limit=0,
high_limit=4194303,
destination=None,
global_broadcast=False,
timeout=5,
):
"""
Object ID : analogInput:1
Object Name : string
Instance Range Low Limit : 0
Instance Range High Limit : 4194303
destination (optional) : If empty, local broadcast will be used.
global_broadcast : False
Build a WhoHas request.
:param object_id: (optional) The address to send the request to, if unused object_name must be present.
:param object_name: (optional) The address to send the request to, if unused object_id must be present.
:param destination: (optional) The destination address, if empty local broadcast will be used.
:param timeout: (optional) The timeout for the WhoHas.
:returns: IAm response.
Example::
import BAC0
bacnet = BAC0.lite()
bacnet.whohas(object_name='SomeDevice')
"""
print("Not yet... come back later")
await asyncio.sleep(1)

"""
if object_name and not object_id:
obj_name = CharacterString(object_name)
obj = WhoHasObject(objectName=obj_name)
elif object_id and not object_name:
obj_id = ObjectIdentifier(object_id)
obj = WhoHasObject(objectIdentifier=obj_id)
else:
obj_id = ObjectIdentifier(object_id)
obj_name = CharacterString(object_name)
obj = WhoHasObject(objectIdentifier=obj_id, objectName=obj_name)
limits = WhoHasLimits(
deviceInstanceRangeLowLimit=instance_range_low_limit,
deviceInstanceRangeHighLimit=instance_range_high_limit,
_ihave = await self.this_application.app.who_has(
object_identifier=object_id,
object_name=object_name,
low_limit=low_limit,
high_limit=high_limit,
address=Address(destination) if destination else None,
timeout=timeout,
)
request = WhoHasRequest(object=obj, limits=limits)
if destination:
request.pduDestination = Address(destination)
else:
if global_broadcast:
request.pduDestination = GlobalBroadcast()
else:
request.pduDestination = LocalBroadcast()
iocb = IOCB(request) # make an IOCB
iocb.set_timeout(2)
deferred(self.this_application.request_io, iocb)
iocb.wait()
iocb = IOCB(request) # make an IOCB
self.this_application._last_i_have_received = []
if iocb.ioResponse: # successful response
pass
if iocb.ioError: # unsuccessful: error/reject/abort
pass
time.sleep(3)
# self.discoveredObjects = self.this_application.i_am_counter
return self.this_application._last_i_have_received
"""
return _ihave
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ include = [
namespaces = false

[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "session"
asyncio_default_fixture_loop_scope = "session"

0 comments on commit 8df73d8

Please sign in to comment.