Example #1
0
 def update(self):
     try:
         value = ts = None
         result = SM.poll_all(self._sid)
         if result is not None:
             value = result[self._nid]['value']
             ts = result[self._nid]['timestamp']
         self._history_lock.acquire()
         try:
             if value is None or isinstance(value, MpxException):
                 # there were problems collecting during this period, 
                 # our calculation should not proceed
                 self._history.clear()
                 if not self._poll_failure:
                     # log the failure, but don't spam the msglog
                     self._poll_failure = True
                     msglog.log('Kwh2Kw', msglog.types.WARN, 
                                'Failed to retrieve data from %s' % self.link)
             else:
                 self._poll_failure = False
                 self._history.add(value, ts)
         finally:
             self._history_lock.release()
     except:
         msglog.exception()
     self._scheduled = scheduler.seconds_from_now_do(self.sample_period, self.run_update)
     return
Example #2
0
 def _proxy_get_link(self, skip_cache=0):
     try:
         if self._proxy_start_exception:  #if there was an exception during start, repeat it now
             self._start_proxy_get() #try again until it starts ok
         answer = None
         if self.use_subscription:
             if (self._proxy_sid is None):
                 self._proxy_sid = SM.create_polled(
                     {1:self._proxy_linked_node()}, timeout=None
                     )
             answer = SM.poll_all(self._proxy_sid)[1]
             if isinstance(answer, dict):
                 answer = answer['value']
                 if isinstance(answer, Exception):
                     raise answer
         else:
             answer = self._proxy_linked_node().get() # @fixme skip_cache) how to use gets that dont have skip cache
         self._proxy_set_exception(None)
         return answer
     except Exception, e: #transfer any exception over to the proxy
         if hasattr(self, 'error_response'): 
             if self.error_response != '%ERROR%':   #default error response is to pass exception up
                 if self.error_response == '%NONE%': return None
                 return self.error_response  #return specific desired value when an error occurs
         self._proxy_set_exception(e)
         raise # reraise the exception
Example #3
0
 def start(self):
     super(Kwh2Kw, self).start()
     self.running = True
     self._history = KwList(self._window_size)
     self._sid = SM.create_polled({self._nid: self.link})
     # retrieve an initial value to start things off
     value = ts = None
     result = SM.poll_all(self._sid)
     if result is None:
         # still waiting
         try:
             value = as_node(self.link).get()
             ts = time.time()
         except:
             pass
     else:
         try:
             value = result[self._nid]['value']
             ts = result[self._nid]['timestamp']
         except:
             pass
         if isinstance(value, MpxException):
             value = None
     if value and ts:
         self._history.add(value, ts)
     self._scheduled = scheduler.seconds_from_now_do(
         self.sample_period, self.run_update)
     return
Example #4
0
 def start(self):
     super(Kwh2Kw, self).start()
     self.running = True
     self._history = KwList(self._window_size)
     self._sid = SM.create_polled({self._nid:self.link})
     # retrieve an initial value to start things off 
     value = ts = None
     result = SM.poll_all(self._sid)
     if result is None:
         # still waiting
         try:
             value = as_node(self.link).get()
             ts = time.time()
         except:
             pass
     else:
         try:
             value = result[self._nid]['value']
             ts = result[self._nid]['timestamp']
         except:
             pass
         if isinstance(value, MpxException):
             value = None
     if value and ts:
         self._history.add(value, ts)
     self._scheduled = scheduler.seconds_from_now_do(self.sample_period, self.run_update)
     return
Example #5
0
 def update(self):
     try:
         value = ts = None
         result = SM.poll_all(self._sid)
         if result is not None:
             value = result[self._nid]['value']
             ts = result[self._nid]['timestamp']
         self._history_lock.acquire()
         try:
             if value is None or isinstance(value, MpxException):
                 # there were problems collecting during this period,
                 # our calculation should not proceed
                 self._history.clear()
                 if not self._poll_failure:
                     # log the failure, but don't spam the msglog
                     self._poll_failure = True
                     msglog.log(
                         'Kwh2Kw', msglog.types.WARN,
                         'Failed to retrieve data from %s' % self.link)
             else:
                 self._poll_failure = False
                 self._history.add(value, ts)
         finally:
             self._history_lock.release()
     except:
         msglog.exception()
     self._scheduled = scheduler.seconds_from_now_do(
         self.sample_period, self.run_update)
     return
Example #6
0
 def _proxy_get_link(self, skip_cache=0):
     try:
         if self._proxy_start_exception:  #if there was an exception during start, repeat it now
             self._start_proxy_get()  #try again until it starts ok
         answer = None
         if self.use_subscription:
             if (self._proxy_sid is None):
                 self._proxy_sid = SM.create_polled(
                     {1: self._proxy_linked_node()}, timeout=None)
             answer = SM.poll_all(self._proxy_sid)[1]
             if isinstance(answer, dict):
                 answer = answer['value']
                 if isinstance(answer, Exception):
                     raise answer
         else:
             answer = self._proxy_linked_node().get(
             )  # @fixme skip_cache) how to use gets that dont have skip cache
         self._proxy_set_exception(None)
         return answer
     except Exception, e:  #transfer any exception over to the proxy
         if hasattr(self, 'error_response'):
             if self.error_response != '%ERROR%':  #default error response is to pass exception up
                 if self.error_response == '%NONE%': return None
                 return self.error_response  #return specific desired value when an error occurs
         self._proxy_set_exception(e)
         raise  # reraise the exception
Example #7
0
aipv=as_node('interfaces/eth0/BACnetIP/2/AnalogInput_01/present_value')
ain=as_node('interfaces/eth0/BACnetIP/2/AnalogInput_01/object_name')
sid = SM.create_polled({1:aipv, 2:ain})

from mpx.service.subscription_manager._manager import SUBSCRIPTION_MANAGER as SM
from mpx.lib.node import as_node
aipv=as_node('services/network/BACnet/internetwork1/Devices/1/8/1/77')
ain =as_node('services/network/BACnet/internetwork1/Devices/1/8/1/79')
pcm1=as_node('services/network/BACnet/internetwork1/Devices/1/151/1/85')
pcm2=as_node('services/network/BACnet/internetwork1/Devices/1/151/1/79')
up = as_node('services/network/BACnet/internetwork1/Devices/1/151/1/10209')
mdd= as_node('services/network/BACnet/internetwork1/Devices/1/151/1/10210')

sid = SM.create_polled({1:aipv, 2:ain, 3:pcm1, 4:pcm2, 5:up, 6:mdd})
sid = SM.create_polled({5:up,6:mdd})
SM.poll_all(sid)

SM.destroy(sid)

from mpx.service.subscription_manager._manager import SUBSCRIPTION_MANAGER as SM
from mpx.lib.node import as_node
pcm1 = as_node('services/network/BACnet/internetwork1/Devices/1/8/1')
ns1 = pcm1.children_names()
cp1 = {}
for n in ns1:
    cp1[n] = pcm1.get_child(n)

sid1 = SM.create_polled(cp1)
SM.poll_changed(sid1)

pcm2 = as_node('services/network/BACnet/internetwork1/Devices/1/151/1')
Example #8
0
 def poll_all(self, sid):
     return SM.poll_all(sid)
Example #9
0
 def poll_all(self, poll_id):
     return SM.poll_all(poll_id)
Example #10
0
 def poll_all(self, sid):
     return SM.poll_all(sid)
Example #11
0
 def poll_all(self, poll_id):
     return SM.poll_all(poll_id)