Skip to content

Commit

Permalink
add delta message handler
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrfrancis committed Aug 15, 2020
1 parent f8eaa42 commit 0cc6f28
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
11 changes: 11 additions & 0 deletions GreengrassAwareConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def publishMessageOnTopic(self, message, topic, qos=0):
def isShadowConnected(self):
return self.shadowConnected

def memberDeltaHandler(self, payload, responseStatus, token):
print("\nReceived a Delta Message")

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



def connectShadow(self):
if not self.isConnected():
self.logger.warn("connect regula client first to get host and port")
Expand All @@ -168,6 +177,8 @@ def connectShadow(self):
# Create a deviceShadow with persistent subscription
self.deviceShadowHandler = self.shadowClient.createShadowHandlerWithName(self.thingName, True)

self.deviceShadowHandler.shadowRegisterDeltaCallback(self.memberDeltaHandler)

self.shadowConnected = True


Expand Down
59 changes: 58 additions & 1 deletion PentairProtocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,63 @@ def __init__(self, body):
except Exception as err:
pass

#
# A Command
#
class Command:
def __init__(self, dst, cmd, type=0x24, src=0x21):
pass

# 0x86 - Turn Circuits On and Off
#
# example:
# 24 10 20 86 2 06 01
#
# will be followed with a ACK from the dest
#
class CircuitChangeCommand(Command):
SPA = 1
AUX1 = 2
AUX2 = 3
AUX3 = 4
FEATURE1 = 5
POOL = 6
FEATURE2 = 7
FEATURE3 = 8
FEATURE4 = 9
HEAT_BOOST = 0x85

def __init__(self, ckt, onOff, dst=0x10):
super().__init__(dst, 0x86)

state = b'\x01' if onOff else b'\x00'

self.payload = ckt.to_bytes(1, byteorder='big') + state
pass

# 0x88 - Change heating parameters -- set points, enable
#
# example:
# 24 10 20 88 4 52 64 05 00
#
class HeatChangeCommand(Command):
# modes
OFF = 0x00
HEATER = 0x01
SOLAR = 0x02
SOLAR_PREF = 0x03

def __init__(self, poolSet, spaSet, spaMode, poolMode, dst=0x10):
super().__init__(dst, 0x88)

mode = (spaMode << 2) | poolMode

self.payload = poolSet.to_bytes(1, byteorder='big') + \
spaSet.to_bytes(1, byteorder='big') + \
mode.to_bytes(1, byteorder='big') + \
b'\x00'
pass


class PentairProtocol:
RECORD_SEPARATOR = b'\xFF\x00\xFF'
Expand All @@ -230,7 +287,7 @@ class PentairProtocol:

def __init__(self):
self.payloads = {
0x00: { #0x01: CommandPayload,
0x00: { #0x01: CommandPayload, # this is really an ACKnowledgement of the cmd in the payload
#0x04: PingPayload,
#0x06: PumpStatus,
0x07: PumpPayload },
Expand Down

0 comments on commit 0cc6f28

Please sign in to comment.