
from calvin.runtime.south.plugins.io.sensors.distance import distance


class Distance(object):

    """
    Distance sensor
    """

    def __init__(self, node, actor):
        self._node = node
        self._actor = actor
        self._distance = distance.Distance(node, self._new_measurement)
        
    def _new_measurement(self, measurement):
        self._measurement = measurement
        self._has_data = True
        self._node.sched.trigger_loop(actor_ids=[self._actor])
        
    def start(self, frequency):
        self._distance.start(frequency)
    
    def stop(self):
        self._distance.stop()
        
    def has_data(self):
        return self._has_data
        
    def read(self):
        if self._has_data:
            self._has_data = False
            return self._measurement

def register(node=None, actor=None):
    return Distance(node, actor)


from calvin.runtime.south.plugins.io.sensors.distance import distance


class Distance(object):

    """
    Distance sensor
    """

    def __init__(self, node, actor):
        self._node = node
        self._actor = actor
        self._distance = distance.Distance(node, self._new_measurement)
        self._has_data = False
        
    def _new_measurement(self, measurement):
        self._measurement = measurement
        self._has_data = True
        self._node.sched.trigger_loop(actor_ids=[self._actor])
        
    def start(self, frequency):
        self._distance.start(frequency)
    
    def stop(self):
        self._distance.stop()
        
    def has_data(self):
        return self._has_data
        
    def read(self):
        if self._has_data:
            self._has_data = False
            return self._measurement

def register(node=None, actor=None):
    return Distance(node, actor)

Add default value to _has_data
Add default value to _has_data

  
  from calvin.runtime.south.plugins.io.sensors.distance import distance
  
  
  class Distance(object):
  
      """
      Distance sensor
      """
  
      def __init__(self, node, actor):
          self._node = node
          self._actor = actor
          self._distance = distance.Distance(node, self._new_measurement)
+         self._has_data = False
          
      def _new_measurement(self, measurement):
          self._measurement = measurement
          self._has_data = True
          self._node.sched.trigger_loop(actor_ids=[self._actor])
          
      def start(self, frequency):
          self._distance.start(frequency)
      
      def stop(self):
          self._distance.stop()
          
      def has_data(self):
          return self._has_data
          
      def read(self):
          if self._has_data:
              self._has_data = False
              return self._measurement
  
  def register(node=None, actor=None):
      return Distance(node, actor)
  
Add default value to _has_data
## Code Before:

from calvin.runtime.south.plugins.io.sensors.distance import distance


class Distance(object):

    """
    Distance sensor
    """

    def __init__(self, node, actor):
        self._node = node
        self._actor = actor
        self._distance = distance.Distance(node, self._new_measurement)
        
    def _new_measurement(self, measurement):
        self._measurement = measurement
        self._has_data = True
        self._node.sched.trigger_loop(actor_ids=[self._actor])
        
    def start(self, frequency):
        self._distance.start(frequency)
    
    def stop(self):
        self._distance.stop()
        
    def has_data(self):
        return self._has_data
        
    def read(self):
        if self._has_data:
            self._has_data = False
            return self._measurement

def register(node=None, actor=None):
    return Distance(node, actor)

## Instruction:
Add default value to _has_data
## Code After:

from calvin.runtime.south.plugins.io.sensors.distance import distance


class Distance(object):

    """
    Distance sensor
    """

    def __init__(self, node, actor):
        self._node = node
        self._actor = actor
        self._distance = distance.Distance(node, self._new_measurement)
        self._has_data = False
        
    def _new_measurement(self, measurement):
        self._measurement = measurement
        self._has_data = True
        self._node.sched.trigger_loop(actor_ids=[self._actor])
        
    def start(self, frequency):
        self._distance.start(frequency)
    
    def stop(self):
        self._distance.stop()
        
    def has_data(self):
        return self._has_data
        
    def read(self):
        if self._has_data:
            self._has_data = False
            return self._measurement

def register(node=None, actor=None):
    return Distance(node, actor)
