Skip to content

Commit

Permalink
Final - ED & pricing working
Browse files Browse the repository at this point in the history
  • Loading branch information
sambabug committed Apr 21, 2017
1 parent 2e7ec68 commit 9c76f15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions applications/iiit/SmartHub/smarthub/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,8 @@ def onDsEd(self, peer, sender, bus, topic, headers, message):
def _get_ds_device_idx(self, deviceID):
if deviceID not in self._ds_deviceId:
self._ds_deviceId.append(deviceID)
idx = self._ds_deviceId.index(deviceID)
self._ds_ed.insert(idx, 0.0)
return self._ds_deviceId.index(deviceID)

def main(argv=sys.argv):
Expand Down
24 changes: 17 additions & 7 deletions applications/iiit/SmartStrip/smartstrip/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class SmartStrip(Agent):
_newTagId2 = ''
_newTagId3 = ''
_newTagId4 = ''

#smartstrip total energy demand
_ted = SMARTSTRIP_BASE_ENERGY


def __init__(self, config_path, **kwargs):
super(SmartStrip, self).__init__(**kwargs)
Expand All @@ -137,7 +141,7 @@ def setup(self, sender, **kwargs):

@Core.receiver('onstart')
def startup(self, sender, **kwargs):
self.runSmartStripTest()
#self.runSmartStripTest()
self.switchLedDebug(LED_ON)

#perodically read the meter data & connected tag ids from h/w
Expand Down Expand Up @@ -808,20 +812,26 @@ def processMessage(self, message):

#calculate the total energy demand (TED)
def _calculateTed(self):
_log.debug('_calculateLocalEd()')
#_log.debug('_calculateTed()')

ed = SMARTSTRIP_BASE_ENERGY
for idx, plugState in enumerate(_plugRelayState):
ted = SMARTSTRIP_BASE_ENERGY
for idx, plugState in enumerate(self._plugRelayState):
if plugState == RELAY_ON:
ed = ed + _plugActivePwr[idx]
ted = ted + self._plugActivePwr[idx]

return ed
return ted

def publishTed(self):
_log.debug('publishTed()')
#_log.debug('publishTed()')

ted = self._calculateTed()

#only publish if change in ted
if self._ted == ted:
return

self._ted = ted
_log.debug ( "*** New TED: {0:.2f}, publishing to bus ***".format(ted))
pubTopic = self.energyDemand_topic
pubMsg = [ted,
{'units': 'W', 'tz': 'UTC', 'type': 'float'}]
Expand Down

0 comments on commit 9c76f15

Please sign in to comment.