Skip to content

Commit

Permalink
add update observable
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis committed Aug 17, 2020
1 parent 0cc6f28 commit fd80b0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions GreengrassAwareConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GreengrassAwareConnection:
GROUP_CA_PATH = "./groupCA/"
OFFLINE_QUEUE_DEPTH = 100

def __init__(self, host, rootCA, cert, key, thingName):
def __init__(self, host, rootCA, cert, key, thingName, stateChangeQueue = None):
self.logger = logging.getLogger("GreengrassAwareConnection")
self.logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler()
Expand All @@ -47,6 +47,8 @@ def __init__(self, host, rootCA, cert, key, thingName):
self.key = key
self.thingName = thingName

self.stateChangeQueue = stateChangeQueue

self.backOffCore = ProgressiveBackOffCore()

self.discovered = False
Expand Down Expand Up @@ -151,9 +153,13 @@ def memberDeltaHandler(self, payload, responseStatus, token):
print("\nReceived a Delta Message")

payloadDict = json.loads(payload)
deltaMessage = json.dumps(payloadDict["state"])
state = payloadDict['state']
deltaMessage = json.dumps(deltaMessage)
print(deltaMessage + "\n")

if self.stateChangeQueue != None:
self.stateChangeQueue.append(state)



def connectShadow(self):
Expand Down
4 changes: 3 additions & 1 deletion pentair-control.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def update(self, objects):
frames = ObservableArray()
state = ObservableDict()

deltas = ObservableArray()


if len(inFile) > 0:
print(f'using {inFile} as source')
Expand Down Expand Up @@ -171,7 +173,7 @@ def update(self, objects):
frames.addObserver(output)

try:
iotConnection = GreengrassAwareConnection(host, rootCA, cert, key, thingName)
iotConnection = GreengrassAwareConnection(host, rootCA, cert, key, thingName, deltas)

iotConnection.deleteShadow()
except Exception as e:
Expand Down

0 comments on commit fd80b0e

Please sign in to comment.