Beispiel #1
0
    def __init__(self, destination, *args):
        if self._cmdval is None:
            raise NotImplementedError

        if self._hasparam:
            if len(args) != 1:
                raise TypeError(
                    "%s.__init__() takes exactly 3 arguments (%d given)" %
                    (self.__class__.__name__, len(args) + 2))

            param = args[0]

            if not isinstance(param, int):
                raise ValueError("param must be an integer")

            if param < 0 or param > 15:
                raise ValueError("param must be in the range 0..15")

            self.param = param

        else:
            if len(args) != 0:
                raise TypeError(
                    "%s.__init__() takes exactly 2 arguments (%d given)" %
                    (self.__class__.__name__, len(args) + 2))
            param = 0

        self.destination = self._check_destination(destination)

        f = frame.ForwardFrame(16, 0x100 | self._cmdval | param)
        self.destination.add_to_frame(f)

        super().__init__(f)
Beispiel #2
0
 def frame(self):
     if self.broadcast:
         b = 0
     elif self.address is None:
         b = 0xff
     else:
         b = (self.address << 1) | 1
     return frame.ForwardFrame(16, (self._cmdval, b))
Beispiel #3
0
 def test_unicode(self):
     """command objects return unicode from their __unicode__ method"""
     # Python 2 only
     if sys.version_info[0] == 2:
         for fs, d, dt in _test_pattern():
             f = frame.ForwardFrame(fs, d)
             self.assertIsInstance(
                 command.from_frame(f, dt).__unicode__(), unicode)
Beispiel #4
0
 def test_response(self):
     """responses act sensibly"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c.response:
             self.assertRaises(TypeError, lambda: c.response('wibble'))
             self.assertHasAttr(c.response(None), 'raw_value')
Beispiel #5
0
 def test_roundtrip(self):
     "all frames survive command.from_frame()"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, "frame {} failed command round-trip; command {} "
             "became {}".format(unicode(f), unicode(c), unicode(nf)))
Beispiel #6
0
 def test_roundtrip(self):
     """all frames survive command.from_frame()"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         nf = c.frame
         self.assertEqual(
             f, nf, 'frame {} failed command round-trip; command {} '
             'became {}'.format(str(f), str(c), str(nf)))
Beispiel #7
0
 def test_unicode(self):
     "command objects return unicode from their __unicode__ method"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertTrue(
             isinstance(command.from_frame(f, dt).__unicode__(),
                        unicode),
             "command {} unicode method didn't return unicode".\
             format(unicode(f)))
Beispiel #8
0
    def __init__(self, device):
        if self._opcode is None:
            raise NotImplementedError

        self.destination = self._check_destination(device)

        f = frame.ForwardFrame(24, 0x1fe00 | self._opcode)
        self.destination.add_to_frame(f)

        _DeviceCommand.__init__(self, f)
Beispiel #9
0
 def test_test_coverage(self):
     """all command classes are covered by test pattern"""
     seen = {}
     for fs, d, dt in _test_pattern():
         c = command.from_frame(frame.ForwardFrame(fs, d), devicetype=dt)
         seen[c.__class__] = True
     for cls in command.Command._commands:
         self.assertTrue(
             cls in seen,
             'class {} not covered by tests'.format(cls.__name__))
Beispiel #10
0
    def __init__(self, device, instance):
        if self._opcode is None:
            raise NotImplementedError

        self.destination = self._check_destination(device)
        if not isinstance(instance, address.Instance):
            raise ValueError("instance must be a dali.address.Instance object")
        self.instance = instance

        f = frame.ForwardFrame(24, 0x10000 | self._opcode)
        self.destination.add_to_frame(f)
        self.instance.add_to_frame(f)

        _DeviceCommand.__init__(self, f)
Beispiel #11
0
 def test_response(self):
     """responses act sensibly"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             if sys.version_info[0] == 2:
                 self.assertIsInstance(
                     c._response(None).__unicode__(), unicode)
             self.assertRaises(TypeError, lambda: c._response('wibble'))
             if sys.version_info[0] == 2:
                 self.assertIsInstance(
                     c._response(frame.BackwardFrame(0xff)).__unicode__(),
                     unicode)
Beispiel #12
0
 def test_response(self):
     "responses act sensibly"
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         c = command.from_frame(f, dt)
         if c._response:
             self.assertTrue(
                 isinstance(c._response(None).__unicode__(), unicode),
                 "cmd {} unicode(response(None)) didn't return unicode".\
                 format(unicode(f)))
             self.assertRaises(TypeError, lambda: c._response("wibble"))
             self.assertTrue(
                 isinstance(c._response(frame.BackwardFrame(0xff)).\
                            __unicode__(), unicode),
                 "cmd {} unicode(response(0xff)) didn't return unicode".\
                 format(unicode(f)))
Beispiel #13
0
    def __init__(self, destination, power):
        if power == "OFF":
            power = 0

        if power == "MASK":
            power = 255

        if not isinstance(power, int):
            raise ValueError("power must be an integer or string")

        if power < 0 or power > 255:
            raise ValueError("power must be in the range 0..255")

        self.destination = self._check_destination(destination)
        self.power = power

        f = frame.ForwardFrame(16, power)
        self.destination.add_to_frame(f)
        super().__init__(f)
Beispiel #14
0
 def __init__(self, *args):
     if self._hasparam:
         if len(args) != 1:
             raise TypeError(
                 "{}.__init__() takes exactly 2 arguments ({} given)".
                 format(self.__class__.__name__,
                        len(args) + 1))
         param = args[0]
         if not isinstance(param, int):
             raise ValueError("param must be an int")
         if param < 0 or param > 255:
             raise ValueError("param must be in range 0..255")
     else:
         if len(args) != 0:
             raise TypeError(
                 "{}.__init__() takes exactly 1 arguments ({} given)".
                 format(self.__class__.__name__,
                        len(args) + 1))
         param = 0
     self.param = param
     super().__init__(frame.ForwardFrame(16, (self._cmdval, self.param)))
Beispiel #15
0
 def __init__(self):
     if self._addr is None or self._instance is None:
         raise NotImplementedError
     _DeviceCommand.__init__(
         self,
         frame.ForwardFrame(24, (self._addr, self._instance, self._opcode)))
Beispiel #16
0
 def test_str(self):
     """command objects can be converted to strings"""
     for fs, d, dt in _test_pattern():
         f = frame.ForwardFrame(fs, d)
         self.assertIsInstance(str(command.from_frame(f, dt)), str)
Beispiel #17
0
 def frame(self):
     return frame.ForwardFrame(16, (self._cmdval, self.param))
Beispiel #18
0
 def frame(self):
     data = 0xff if self.address == "MASK" else ((self.address << 1) | 1)
     return frame.ForwardFrame(16, (self._cmdval, data))
Beispiel #19
0
 def __init__(self):
     if self._addr is None or self._instance is None:
         raise NotImplementedError
     super().__init__(
         frame.ForwardFrame(24, (
             self._addr, self._instance, self._opcode)))