code: def process_stream(self, tree):
          
          try:
              etype = SENSOR_MAP[tree.find(
                  self.element_query('eventType')).text.lower()]
              estate = tree.find(
                  self.element_query('eventState')).text
              echid = tree.find(
                  self.element_query('channelID'))
              if echid is None:
                  # Some devices use a different key
                  echid = tree.find(
                      self.element_query('dynChannelID'))
              echid = int(echid.text)
              ecount = tree.find(
                  self.element_query('activePostCount')).text
          except (AttributeError, KeyError, IndexError) as err:
              _LOGGING.error('Problem finding attribute: %s', err)
              return
  
          # Take care of keep-alive
          if len(etype) > 0 and etype == 'Video Loss':
              self.watchdog.pet()
  
          # Track state if it's in the event list.
          if len(etype) > 0:
              state = self.fetch_attributes(etype, echid)
              if state:
                  # Determine if state has changed
                  # If so, publish, otherwise do nothing
                  estate = (estate == 'active')
                  old_state = state[0]
                  attr = [estate, echid, int(ecount),
                          datetime.datetime.now()]
                  self.update_attributes(etype, echid, attr)
  
                  if estate != old_state:
                      self.publish_changes(etype, echid)
                  self.watchdog.pet()
docs: Process incoming event stream packets.