original_docstring: Waits for new color or returns immediately if first call
          
docstring: Waits for new color or returns immediately if first call
docstring_tokens: Waits for new color or returns immediately if first call
code: def wait_for_new_color(self):
          """Waits for new color or returns immediately if first call
          """
          self.mode(5)
          if self._old_color is None:
              self._old_color = self.get_color()
              return self._old_color
          cond = Condition()
          data = deque(maxlen=self.avg_reads)
          def cb(lst):
              data.append(lst[:4])
              if len(data) ==  self.avg_reads:
                  r, g, b, _ = self._avgrgbi(data)
                  seg = self.segment_color(r, g, b)
                  if seg != self._old_color:
                      self._old_color = seg
                      with cond:
                          cond.notify()
          self.callback(cb)
          with cond:
              cond.wait()
          self.callback(None)
          return self._old_color
code_tokens: def wait_for_new_color ( self ) : self . mode ( 5 ) if self . _old_color is None : self . _old_color = self . get_color ( ) return self . _old_color cond = Condition ( ) data = deque ( maxlen = self . avg_reads ) def cb ( lst ) : data . append ( lst [ : 4 ] ) if len ( data ) == self . avg_reads : r , g , b , _ = self . _avgrgbi ( data ) seg = self . segment_color ( r , g , b ) if seg != self . _old_color : self . _old_color = seg with cond : cond . notify ( ) self . callback ( cb ) with cond : cond . wait ( ) self . callback ( None ) return self . _old_color
short_docstring: Waits for new color or returns immediately if first call
short_docstring_tokens: Waits for new color or returns immediately if first call
comment: """Waits for new color or returns immediately if first call
          """