示例#1
0
    def setUp(self):
        injection.configure()
        settings.use_base({
            'log_to_console': True,
            'single_light_discover': True,
            'use_fakes': True
        }).configure()
        fake_lifx.configure()
        light_set.configure()

        self._group0 = 'Group 0'
        self._group1 = 'Group 1'
        self._group2 = 'Group 2'

        self._location0 = 'Location 0'
        self._location1 = 'Location 1'
        self._location2 = 'Location 2'

        self._light0 = 'Light 0'
        self._light1 = 'Light 1'
        self._light2 = 'Light 2'
        self._light3 = 'Light 3'

        self._color = [1, 2, 3, 4]
        lifx = injection.provide(i_controller.Lifx)
        lifx.init_from([
            (self._light0, self._group0, self._location0, self._color, False),
            (self._light1, self._group0, self._location1, self._color, False),
            (self._light2, self._group1, self._location0, self._color, False),
            (self._light3, self._group1, self._location1, self._color, False)
        ])
示例#2
0
 def __init__(self):
     self._pc = 0
     self._cue_time = 0
     self._clock = provide(Clock)
     self._variables = {}
     self._program = []
     self._reg = Registers()
     self._call_stack = CallStack()
     self._vm_math = VmMath(self._call_stack, self._reg)
     self._enable_pause = True
     self._keep_running = True
     self._fn_table = {}
     for opcode in (OpCode.COLOR,
                    OpCode.CONSTANT,
                    OpCode.END,
                    OpCode.END_LOOP,
                    OpCode.GET_COLOR,
                    OpCode.JSR,
                    OpCode.JUMP,
                    OpCode.LOOP,
                    OpCode.MOVE,
                    OpCode.MOVEQ,
                    OpCode.NOP,
                    OpCode.OP,
                    OpCode.PARAM,
                    OpCode.PAUSE,
                    OpCode.PUSH,
                    OpCode.PUSHQ,
                    OpCode.POP,
                    OpCode.POWER,
                    OpCode.TIME_PATTERN,
                    OpCode.WAIT):
         name = '_' + opcode.name.lower()
         self._fn_table[opcode] = getattr(self, name)
     self._fn_table[OpCode.STOP] = self.stop
示例#3
0
    def test_refresh(self):
        tested_set = light_set.LightSet()
        tested_set.discover()

        lifx = injection.provide(i_controller.Lifx)
        lifx.init_from([
            (self._light0, self._group0, self._location0, self._color, False),
            (self._light1, self._group0, self._location1, self._color, False),
            (self._light2, self._group0, self._location1, self._color, False),
            (self._light3, self._group2, self._location0, self._color, False)
        ])

        tested_set.refresh()
        self.assertEqual(len(tested_set.light_names), 4)
        self.assertEqual(len(tested_set.group_names), 2)
        self.assertEqual(len(tested_set.location_names), 2)

        group = tested_set.get_group(self._group0)
        self._assert_names_equal(group, self._light0, self._light1,
                                 self._light2)
        self.assertIsNone(tested_set.get_group(self._group1))
        group = tested_set.get_group(self._group2)
        self._assert_names_equal(group, self._light3)

        location = tested_set.get_location(self._location0)
        self._assert_names_equal(location, self._light0, self._light3)
        location = tested_set.get_location(self._location1)
        self._assert_names_equal(location, self._light1, self._light2)
示例#4
0
 def check_no_others(self, *allowed):
     """
     Assert that only the lights in the list got any calls.
     """
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         if light.get_label() not in allowed:
             self._test_case.assertEqual(len(light.get_call_list()), 0)
示例#5
0
 def test_and(self):
     script = """
         units raw hue 1 saturation 2 brightness 3 kelvin 4 duration 5
         set "Bottom" and "Top" and "Middle"
     """
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     self._runner.check_call_list(('Bottom', 'Top', 'Middle'),
                                  (Action.SET_COLOR, ([1, 2, 3, 4], 5)))
示例#6
0
 def index(self, title='Lights'):
     a_class = FrontEnd.get_agent_class()
     web_app = provide(WebApp)
     return render_template('index.html',
                            agent_class=a_class,
                            icon='switch',
                            scripts=web_app.get_script_list(),
                            title=title,
                            path_root=web_app.get_path_root())
示例#7
0
 def test_script(self):
     agent = ls_module.queue_script("on all time 2 off all")
     tries_left = 500
     while agent.is_running():
         time.sleep(0.1)
         tries_left -= 1
         self.assertGreater(tries_left, 0)
     lifx = provide(i_controller.Lifx)
     self.assertListEqual(lifx.get_call_list(),
         [(Action.SET_POWER, (65535, 0)), (Action.SET_POWER, (0, 0))])
示例#8
0
 def test_script(self):
     script = """
         repeat while {brightness < 50.0} begin
             brightness {brightness + 5}
             set all
         end
     """
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         print(light.get_label(), light.call_list())
示例#9
0
    def test_set_single_color(self):
        color = [1, 2, 3, 4]
        name = self._names[0]

        program = MachineTest.code_for_set(name, Operand.LIGHT, color)
        machine = Machine()
        machine.run(program)
        self.assertListEqual(machine.color_from_reg(), color)
        light_set = provide(i_controller.LightSet)
        light = light_set.get_light(name)._impl
        self.assertTrue(light.was_set(color))
示例#10
0
 def test_power(self):
     script = 'on "Top" off "Bottom"'
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         if light.get_label() == "Top":
             expected = [(Action.SET_POWER, (65535, 0))]
         elif light.get_label() == "Bottom":
             expected = [(Action.SET_POWER, (0, 0))]
         else:
             expected = []
         self.assertListEqual(light.get_call_list(), expected)
示例#11
0
 def test_individual(self):
     script = """
         units raw
         hue 11 saturation 22 brightness 33 kelvin 2500 set "Top"
         hue 44 saturation 55 brightness 66 set "Bottom"
     """
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     self._runner.check_call_list('Top', (Action.SET_COLOR,
                                          ([11, 22, 33, 2500], 0)))
     self._runner.check_call_list('Bottom', (Action.SET_COLOR,
                                             ([44, 55, 66, 2500], 0)))
示例#12
0
 def test_and(self):
     script = """
         units raw hue 1 saturation 2 brightness 3 kelvin 4
         duration 5 set "Bottom" and "Top" and "Middle"
     """
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         if light.get_label() in ('Bottom', 'Middle', 'Top'):
             expected = [(Action.SET_COLOR, ([1, 2, 3, 4], 5))]
         else:
             expected = []
         self.assertListEqual(light.get_call_list(), expected)
示例#13
0
    def setUp(self):
        test_module.configure()

        self._group0 = 'Group 0'
        self._group1 = 'Group 1'

        self._location0 = 'Location 0'
        self._location1 = 'Location 1'

        self._colors = [[4, 8, 12, 16], [24, 28, 32, 36], [44, 48, 52, 56],
                        [64, 68, 72, 76]]
        self._names = ["Test g1 l1", "Test g1 l2", "Test g2 l1", "Test g2 l2"]

        lifx = provide(i_controller.Lifx)
        lifx.init_from([
            (self._names[0], self._group0, self._location0, self._colors[0]),
            (self._names[1], self._group0, self._location1, self._colors[1]),
            (self._names[2], self._group1, self._location0, self._colors[2]),
            (self._names[3], self._group1, self._location1, self._colors[3])
        ])
        light_set = provide(i_controller.LightSet)
        light_set.discover()
示例#14
0
def configure():
    """ Assumes injection and settings are already initialized. """
    log_config.configure()
    clock.configure()

    settings = provide(Settings)
    if settings.get_value('use_fakes'):
        from ..fakes import fake_lifx
        fake_lifx.configure()
    else:
        from . import lifx
        lifx.configure()

    light_set.configure()
示例#15
0
 def test_individual(self):
     script = """
         units raw
         hue 11 saturation 22 brightness 33 kelvin 2500 set "Top"
         hue 44 saturation 55 brightness 66 set "Bottom"
     """
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         if light.get_label() == 'Top':
             expected = [(Action.SET_COLOR, ([11, 22, 33, 2500], 0))]
         elif light.get_label() == 'Bottom':
             expected = [(Action.SET_COLOR, ([44, 55, 66, 2500], 0))]
         else:
             expected = []
         self.assertListEqual(light.get_call_list(), expected)
示例#16
0
 def __init__(self):
     self._cue_time = 0
     self._clock = provide(Clock)
     self._routines = {}
     self._program = []
     self._reg = Registers()
     self._call_stack = CallStack()
     self._vm_io = VmIo(self._call_stack, self._reg)
     self._vm_math = VmMath(self._call_stack, self._reg)
     self._vm_discover = VmDiscover(self._call_stack, self._reg)
     self._enable_pause = True
     self._keep_running = True
     excluded = (OpCode.STOP, OpCode.ROUTINE)
     op_codes = [code for code in OpCode
                 if not str(code.name).startswith('_')
                 and code not in excluded]
     self._fn_table = {
         op_code: getattr(self, '_' + op_code.name.lower())
         for op_code in (op_codes)}
     self._fn_table[OpCode.STOP] = self.stop
示例#17
0
 def print_all_call_lists():
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         print(light.get_label(), light.get_call_list())
示例#18
0
 def test_script(self):
     script = 'if {1 and 2 < 3} set all'
     self._runner.run_script(script)
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         print(light.get_label(), light.call_list())
示例#19
0
def create_app():
    return injection.provide(Flask)
示例#20
0
 def check_call_list(self, light_names, expected):
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         if light.get_label() in light_names:
             self._test.assertListEqual(light.get_call_list(), expected)
示例#21
0
 def check_all_call_lists(self, expected):
     # Calls that were made to all lights, each one individually.
     lifx = provide(i_controller.Lifx)
     for light in lifx.get_lights():
         self._test.assertListEqual(light.get_call_list(), expected)
示例#22
0
 def check_global_call_list(self, expected):
     # Calls made to LightSet as opposed to individual lights.
     lifx = provide(i_controller.Lifx)
     self._test.assertListEqual(lifx.get_call_list(), expected)
示例#23
0
def call_impl_provided():
    intf = injection.provide(Interface)
    return intf.f()