Skip to content

Commit

Permalink
add time reporting to AlfalfaProxy device
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Mar 1, 2023
1 parent b4208d1 commit 7fe8602
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions alfalfa_bacnet_bridge/alfalfa_bacnet_bridge.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import sys
from bacpypes.app import BIPSimpleApplication
from bacpypes.core import deferred, run
Expand All @@ -10,7 +11,7 @@
from alfalfa_client.alfalfa_client import SiteID
from bacpypes.service.device import DeviceCommunicationControlServices
from bacpypes.service.object import ReadWritePropertyMultipleServices
from bacpypes.primitivedata import CharacterString
from bacpypes.primitivedata import CharacterString, Date, Time
from bacpypes.basetypes import DeviceStatus

_debug = 0
Expand All @@ -22,19 +23,29 @@ class AlfalfaBACnetApplication(BIPSimpleApplication,
DeviceCommunicationControlServices,):
pass

class AlfalfaBACnetDevice(LocalDeviceObject):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._date_time: datetime = None

def ReadProperty(self, propid, arrayIndex=None):
if propid == "localTime" and self._date_time != None:
time = Time(str(self._date_time.time()))
return time.value
if propid == "localDate" and self._date_time != None:
date = Date(str(self._date_time.date()))
return date.value
return super().ReadProperty(propid, arrayIndex)

@bacpypes_debugging
@register_object_type(vendor_id=999)
@register_object_type(vendor_id=555)
class LocalAnalogValueObject(AnalogValueCmdObject):
def __init__(self, sim_value, **kwargs):
super().__init__(**kwargs)
self._sim_value = sim_value

def ReadProperty(self, propid, arrayIndex=None):
if propid == "presentValue":
print(super().ReadProperty(propid, arrayIndex))
print(super().ReadProperty(propid, arrayIndex).__class__)
return self._sim_value
return super().ReadProperty(propid, arrayIndex)

Expand All @@ -45,7 +56,7 @@ def __init__(self, host, site_id: SiteID) -> None:

self.site_id = site_id

self.device = LocalDeviceObject(
self.device = AlfalfaBACnetDevice(
objectName="AlfalfaProxy",
objectIdentifier=int(599),
maxApduLengthAccepted=int(1024),
Expand Down Expand Up @@ -89,7 +100,6 @@ def setup_points(self):
for point in self.points.values():
self.application.add_object(point)

# self.application.add_object(AnalogInputObject(objectName="TEST", objectIdentifier=("analogInput", 1), presentValue=17))


def run(self):
Expand All @@ -99,6 +109,8 @@ def main_loop():
inputs = self.client.get_inputs(self.site_id)
outputs = self.client.get_outputs(self.site_id)

sim_time = self.client.get_sim_time(self.site_id)
self.device._date_time = sim_time

set_inputs = {}
for point, object in self.points.items():
Expand Down

0 comments on commit 7fe8602

Please sign in to comment.