from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes

import numpy as np

class CounterController(Controller):

    def create_attributes(self):
        self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
        self.counter.set_put_function(self.counter.set_value)
        self.counter.set_value(0)
        yield self.counter

    @takes()
    def reset(self):
        self.counter.set_value(0)

    @takes()
    def increment(self):
        self.counter.set_value(self.counter.value + 1)

from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes, returns

import numpy as np

class CounterController(Controller):

    def create_attributes(self):
        self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
        self.counter.set_put_function(self.counter.set_value)
        self.counter.set_value(0)
        yield self.counter

    @takes()
    @returns()
    def reset(self, args=None):
        self.counter.set_value(0)
        return {}

    @takes()
    @returns()
    def increment(self, args=None):
        self.counter.set_value(self.counter.value + 1)
        return {}

Fix args and return of CounterController functions
Fix args and return of CounterController functions

Even though they're not used, functions to be wrapped by Methods have to
take arguments and return something (at least an empty dict).

  from malcolm.core.controller import Controller
  from malcolm.core.attribute import Attribute
  from malcolm.core.numbermeta import NumberMeta
- from malcolm.core.method import takes
+ from malcolm.core.method import takes, returns
  
  import numpy as np
  
  class CounterController(Controller):
  
      def create_attributes(self):
          self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
          self.counter.set_put_function(self.counter.set_value)
          self.counter.set_value(0)
          yield self.counter
  
      @takes()
+     @returns()
-     def reset(self):
+     def reset(self, args=None):
          self.counter.set_value(0)
+         return {}
  
      @takes()
+     @returns()
-     def increment(self):
+     def increment(self, args=None):
          self.counter.set_value(self.counter.value + 1)
+         return {}
  
Fix args and return of CounterController functions
## Code Before:
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes

import numpy as np

class CounterController(Controller):

    def create_attributes(self):
        self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
        self.counter.set_put_function(self.counter.set_value)
        self.counter.set_value(0)
        yield self.counter

    @takes()
    def reset(self):
        self.counter.set_value(0)

    @takes()
    def increment(self):
        self.counter.set_value(self.counter.value + 1)

## Instruction:
Fix args and return of CounterController functions
## Code After:
from malcolm.core.controller import Controller
from malcolm.core.attribute import Attribute
from malcolm.core.numbermeta import NumberMeta
from malcolm.core.method import takes, returns

import numpy as np

class CounterController(Controller):

    def create_attributes(self):
        self.counter = Attribute(NumberMeta("counter", "A counter", np.int32))
        self.counter.set_put_function(self.counter.set_value)
        self.counter.set_value(0)
        yield self.counter

    @takes()
    @returns()
    def reset(self, args=None):
        self.counter.set_value(0)
        return {}

    @takes()
    @returns()
    def increment(self, args=None):
        self.counter.set_value(self.counter.value + 1)
        return {}
