Skip to content

Commit

Permalink
swap prints for debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Jan 30, 2024
1 parent 6888c17 commit a6532cb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions alfalfa_bacnet_bridge/alfalfa_bacnet_bridge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
import logging
import math
import sys
import os
Expand All @@ -19,6 +20,21 @@
_debug = 0
_log = ModuleLogger(globals())

logger = logging.getLogger("AlfalfaBACnetBridge")
logger.setLevel(logging.DEBUG)
log_formatter = logging.Formatter('%(asctime)s - %(threadName)s - %(levelname)s - %(message)s')

stdout_handler = logging.StreamHandler()
stdout_handler.setLevel(logging.DEBUG)
stdout_handler.setFormatter(log_formatter)

file_handler = logging.FileHandler('bridge.log')
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(log_formatter)

logger.addHandler(stdout_handler)
logger.addHandler(file_handler)

@bacpypes_debugging
class AlfalfaBACnetApplication(BIPSimpleApplication,
ReadWritePropertyMultipleServices,
Expand Down Expand Up @@ -89,18 +105,18 @@ def setup_points(self):
for input in inputs:
if input in outputs:
self.points[input] = LocalAnalogValueObject(objectName=input, objectIdentifier=("analogValue", index), sim_value=outputs[input])
print(f"Creating BIDIRECTIONAL point: '{input}'")
logger.debug(f"Creating BIDIRECTIONAL point: '{input}'")
else:
self.points[input] = AnalogValueCmdObject(objectName=input, objectIdentifier=("analogValue", index))
print(f"Creating INPUT point: '{input}'")
logger.debug(f"Creating INPUT point: '{input}'")
self.points[input]._had_value = False
index += 1

for output in output_names:
if output in self.points:
continue
self.points[output] = AnalogInputObject(objectName=output, objectIdentifier=("analogInput", index), presentValue=outputs[output])
print(f"Creating OUTPUT point: '{output}'")
logger.debug(f"Creating OUTPUT point: '{output}'")
index += 1

for point in self.points.values():
Expand All @@ -118,7 +134,7 @@ def main_loop():

sim_time = self.client.get_sim_time(self.site_id)
except Exception as e:
print(e)
logger.debug(e)
return
self.device._date_time = sim_time

Expand All @@ -136,15 +152,15 @@ def main_loop():
set_inputs[point] = current_value
object._had_value = True
else:
print(f"Got non-finite value {current_value} for point {point}")
logger.debug(f"Got non-finite value {current_value} for point {point}")
elif object._had_value:
set_inputs[point] = None
object._had_value = False
if len(set_inputs) > 0:
try:
self.client.set_inputs(self.site_id, set_inputs)
except Exception as e:
print(e)
logger.debug(e)


deferred(main_loop)
Expand Down

0 comments on commit a6532cb

Please sign in to comment.