def test0_3_init(self):
     """
     Pin >0_3> change cfg of init_pin
     """
     pin = SlavePin(self.opt)
     exp_items = {
         'crypt': None,
         'pin_nr': '0',
         'cfg_file': None,
         'name': 'None',
         'prio': '0',
         'mode': 'off',
         'groups': '',
         'start': '00:00',
         'duration': '0',
         'sun_delay': '0',
         'state': '0',
         'dow': 'Mon,Tue,Wed,Thu,Fr,Sat,Sun',
         'gpio_base': "%spackaged/sys/class/gpio" % PREFIX,
         'pin_base': "%spackaged/sys/class/gpio/gpio0" % PREFIX,
     }
     exp1 = exp_items.copy()
     self.check_dict(pin, exp1)
     cfg = {
         'pin_nr': '1',
         'name': 'Front',
     }
     pin.set_cfg(cfg)
     pin.change_mode('time')
     exp_items['name'] = 'Front'
     exp_items['mode'] = 'time'
     pin_base = "%spackaged/sys/class/gpio/gpio1" % PREFIX
     exp_items['pin_base'] = pin_base
     exp_items['pin_nr'] = '1'
     self.check_dict(pin, exp_items)
Esempio n. 2
0
 def run_scenario(self):
     """
     run scenario w/o config files
     """
     if self.opt['--test'] == 'test1':
         pin1 = SlavePin(self.opt)
         cfg = {
             'dow': 'Mon,Tue,Wed,Thu,Fri,Sat,Sun',
             'duration': '60',
             'groups': 'grpA',
             'name': 'TestPin1',
             'pin_nr': '1',
             'start': '01:00',
         }
         pin1.set_cfg(cfg)
         pin1.set_pin(0)
         pin1.change_mode('time')
         pin1.val_path = "%s/gpio%s/value" % (pin1.gpio_base, 1)
         self.add_pin(pin1)
         pin5 = MainPin(self.opt)
         cfg = {
             'groups': 'grpA',
             'name': 'MainPin5',
             'pin_nr': '5',
             'crypt': 'eaa491247883b9b1cd0760bae439a253'
             }
         pin5.set_cfg(cfg, True)
         pin5.val_path = "%s/gpio%s/value" % (pin1.gpio_base, 5)
         pin5.cfg_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % (os.environ["WORKSPACE"])
         pin5.change_mode('off')
         pin5.set_pin(0)
         self.add_pin(pin5)
 def test8_0_trigger(self):
     """
     Pin >8_0> trigger off
     """
     pin = SlavePin(self.opt)
     now = datetime.datetime.now()
     delay = datetime.timedelta(seconds=600)
     temp_on = now - delay
     cfg = {
         'start': temp_on.strftime("%H:%M"),
         'duration': '5',
         'pin_nr': '1',
     }
     pin.set_cfg(cfg)
     pin.change_mode('time')
     pin.init_pin()
     pin.set_pin(1)
     self.assertTrue("1" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
     pin.set_pin(1)
     self.assertTrue("1" == pin.read_real_life())
     pin.trigger_off()
     self.assertTrue("0" == pin.read_real_life())
    def test0_3_flip(self):
        """
        Web >0_3> press flip button
        """
        test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        pin1 = SlavePin(self.opt, test1_file)
        pin1.init_pin(True)
        pin1.set_cfg({"dow": "Mon,Tue,Wed,Fri,Sat,Sun"})

        web = Web(self.opt)
        web.add_pin(pin1)
        web.update_slave(send="flip", gpio="1")
        exp = [line for line in self.exp_head]
        exp.extend([line for line in self.exp_pin1])
        exp.extend([line for line in self.exp_tail])
        exp[36] = "<input type='checkbox' name='dow_Mon' value='Mon' checked>Mon"
        exp[37] = "<input type='checkbox' name='dow_Tue' value='Tue' checked>Tue"
        exp[39] = "<input type='checkbox' name='dow_Thu' value='Thu'>Thu"
        exp[40] = "<input type='checkbox' name='dow_Fri' value='Fri' checked>Fri"
        exp[41] = "<input type='checkbox' name='dow_Sat' value='Sat' checked>Sat"
        exp[42] = "<input type='checkbox' name='dow_Sun' value='Sun' checked>Sun"
        self.check_web(web.html, exp)
        web.update_slave(send="flip", gpio="1")
        exp[20] = "<td style='background-color:red'>"
        self.check_web(web.html, exp)
 def test7_4_gt(self):
     """
     Pin >7_4> self.__gt__(other)
     """
     lst = []
     pin0 = SlavePin(self.opt)
     pin0.set_cfg({
         'groups':'garden',
         'pin_nr': '4',
         'start': '00:00',
         'prio': '0',
         'duration': '10',
     })
     pin1 = SlavePin(self.opt)
     pin1.set_cfg({
         'groups':'garden',
         'pin_nr': '3',
         'start': '00:10',
         'prio': '0',
         'duration': '10',
     })
     pin2 = SlavePin(self.opt)
     pin2.set_cfg({
         'groups':'garden',
         'pin_nr': '3',
         'start': '00:00',
         'prio': '1',
         'duration': '10',
     })
     pin3 = SlavePin(self.opt)
     pin3.set_cfg({
         'groups':'garden',
         'pin_nr': '3',
         'start': '00:00',
         'prio': '0',
         'duration': '20',
     })
     pin4 = SlavePin(self.opt)
     pin4.set_cfg({
         'groups':'garden',
         'pin_nr': '4',
         'start': '00:00',
         'prio': '1',
         'duration': '20',
     })
     amsg = "\n%s\n>\n%s" % (pin1.get_json(), pin0.get_json())
     self.assertTrue(pin1.__gt__(pin0), amsg)
     amsg = "\n%s\n>\n%s" % (pin2.get_json(), pin0.get_json())
     self.assertTrue(pin2.__gt__(pin0), amsg)
     amsg = "\n%s\n>\n%s" % (pin0.get_json(), pin0.get_json())
     self.assertTrue(pin3.__gt__(pin0), amsg)
     amsg = "\n%s\n<\n%s" % (pin0.get_json(), pin1.get_json())
     self.assertFalse(pin0.__gt__(pin1), amsg)
     amsg = "\n%s\n<\n%s" % (pin0.get_json(), pin0.get_json())
     self.assertFalse(pin0.__gt__(pin0), amsg)
     amsg = "\n%s\n<\n%s" % (pin0.get_json(), pin1.get_json())
     self.assertFalse(pin0.__gt__(pin1), amsg)
     amsg = "\n%s\n!__gt__\n%s" % (pin3.get_json(), pin4.get_json())
     self.assertFalse(pin3.__gt__(pin4), amsg)
 def test3_0_check_arrangement(self):
     """
     GpioCtrl >3_0> Pins are not grouped
     """
     ctrl = GpioCtrl(self.opt)
     ctrl.read_cfg()
     ctrl.set_pin_cfg('1', {'groups':'grp1'})
     ctrl.set_pin_cfg('2', {'groups':'grp2'})
     ctrl.set_pin_cfg('3', {'groups':'grp3'})
     ctrl.set_pin_cfg('4', {'groups':'grp4'})
     pincfg_path = "%s/%s/etc/raspigpioctrl/" % (PREFIX, self.opt['-r'])
     pin1 = SlavePin(self.opt, "%s/pin1.cfg" % pincfg_path)
     pin1.set_cfg({'groups':'grp1'})
     pin2 = SlavePin(self.opt, "%s/pin2.cfg" % pincfg_path)
     pin2.set_cfg({'groups':'grp2'})
     pin3 = SlavePin(self.opt, "%s/pin3.cfg" % pincfg_path)
     pin3.set_cfg({'groups':'grp3'})
     pin4 = SlavePin(self.opt, "%s/pin4.cfg" % pincfg_path)
     pin4.set_cfg({'groups':'grp4'})
     exp_items = {
         'gpio_pins': {
             '1': pin1,
             '2': pin2,
             '3': pin3,
             '4': pin4,
         }
     }
     self.check(ctrl, exp_items)
    def test0_4_sun(self):
        """
        Web >0_4> change mod to sun
        """
        exp = ""

        test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        pin1 = SlavePin(self.opt, test1_file)
        pin1.init_pin(True)
        pin1.set_cfg({"dow": "Mon,Tue,Wed,Thu,Fri,Sat,Sun"})

        web = Web(self.opt)
        web.add_pin(pin1)
        web.update_slave(send="change", mode="sun", gpio="1")
        self.assertTrue(web.gctrl.gpio_pins["1"].get_json()["mode"] == "sun")
 def test4_1_datetime(self):
     """
     Pin >4_1> check datetime for runtime including midnight
     """
     pin = SlavePin(self.opt)
     pin.set_cfg({'start': '23:30', 'duration': '60'})
     now = datetime.datetime.now()
     exp_on = datetime.datetime(year=now.year,
                     month=now.month,
                     day=now.day,
                     hour=23,
                     minute=30)
     exp_off = datetime.datetime(year=now.year,
                     month=now.month,
                     day=now.day+1,
                     hour=0,
                     minute=30)
     self.assertTrue(exp_on == pin.get_dt_on())
     self.assertTrue(exp_off == pin.get_dt_off())
    def test1_0_main(self):
        """
        Web >1_0> main pin plus pin1
        """
        pin1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        pin1 = SlavePin(self.opt, pin1_file)
        pin1.init_pin(True)
        pin1.set_pin(0)
        pin1.set_cfg({"dow": "Mon,Tue,Wed,Thu,Fri,Sat,Sun"})
        self.assertTrue(pin1.isstate(0))
        pin5_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % PREFIX
        pin5 = MainPin(self.opt, pin5_file)
        pin5.init_pin(True)
        pin5.set_cfg({"groups": "garden"})
        pprint(pin5.get_json())
        pin5.change_mode("off")
        pin5.set_pin(0)
        self.assertTrue(pin5.isstate(0))

        web = Web(self.opt)
        web.add_pin(pin1)
        web.add_pin(pin5)
        web.index()
        exp = [line for line in self.exp_head]
        exp.extend([line for line in self.exp_pin1])
        exp.extend([line for line in self.exp_main5])
        exp.extend([line for line in self.exp_tail])
        exp[20] = "<td style='background-color:red'>"
        exp[36] = "<input type='checkbox' name='dow_Mon' value='Mon' checked>Mon"
        exp[37] = "<input type='checkbox' name='dow_Tue' value='Tue' checked>Tue"
        exp[39] = "<input type='checkbox' name='dow_Thu' value='Thu' checked>Thu"
        exp[40] = "<input type='checkbox' name='dow_Fri' value='Fri' checked>Fri"
        exp[41] = "<input type='checkbox' name='dow_Sat' value='Sat' checked>Sat"
        exp[42] = "<input type='checkbox' name='dow_Sun' value='Sun' checked>Sun"
        exp[52] = "<td><b>MainPin5</b></td>"
        got = web.html
        self.check_web(got, exp)
        pin5.change_mode("auto")
        web.index()
        exp[55] = "<td style='background-color:red'>"
        exp[57] = "<td style='background-color:green'>"
        got = web.html
        self.check_web(got, exp)
 def test7_1_ne(self):
     """
     Pin >7_1> self.__ne__(other) True
     """
     lst = []
     pin0 = SlavePin(self.opt)
     pin0.set_cfg({
         'groups':'garden',
         'pin_nr': '4',
         'start': '00:10',
         'prio': '0',
         'duration': '10',
     })
     pin1 = SlavePin(self.opt)
     pin1.set_cfg({
         'groups':'garden',
         'pin_nr': '3',
         'start': '00:10',
         'prio': '0',
         'duration': '10',
     })
     pin2 = SlavePin(self.opt)
     pin2.set_cfg({
         'groups':'garden',
         'pin_nr': '3',
         'start': '00:20',
         'prio': '0',
         'duration': '10',
     })
     amsg = "\n%s\n!=\n%s" % (pin0.get_json(), pin1.get_json())
     self.assertFalse(pin0.__ne__(pin1), amsg)
     amsg = "\n%s\n==\n%s" % (pin0.get_json(), pin2.get_json())
     self.assertTrue(pin0.__ne__(pin2))
 def test2_2_failed_save_cfg(self):
     """
     Pin >2_2> Write cfg with changed cfg-file in background (IOError)
     """
     test1_cfg = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin = SlavePin(self.opt, test1_cfg)
     cfg = {
         'start': "10:00",
         'duration': "30",
         'dow': "Fri,Sat,Sun"
     }
     pin.set_cfg(cfg)
     cfg_file = '%s/misc/tmp_test.cfg' % PREFIX
     if os.path.exists(cfg_file):
         os.remove(cfg_file)
     pin.write_cfg(cfg_file)
     self.assertTrue(pin.crypt == '80a913b6297d386cd72b9f9fd9172c34',
                     "CRYPT: %s" % pin.crypt)
     
     cfg = {'start': "10:30"}
     pin.set_cfg(cfg)
     os.system("echo FooBar >> %s" % cfg_file)
     self.assertRaises(IOError, pin.write_cfg, (cfg_file))
     os.remove(cfg_file)
 def test3_1_check_arrangement_group_collision(self):
     """
     GpioCtrl >3_1> Pins are grouped, times are equal, rpio differ
     """
     ctrl = GpioCtrl(self.opt)
     ctrl.read_cfg()
     ctrl.set_pin_cfg('1', {'groups':'a',
                   'start':'00:00',
                   'prio':'0',
                   'duration':'10',
                   })
     ctrl.set_pin_cfg('2', {'groups':'a',
                   'start':'00:00',
                   'prio':'1',
                   'duration':'10',
                   })
     ctrl.set_pin_cfg('3', {'groups':'a',
                   'start':'00:00',
                   'prio':'2',
                   'duration':'10',
                   })
     ctrl.set_pin_cfg('4', {'groups':'b',
                   'start':'00:00',
                   'prio':'0',
                   'duration':'10',
                   })
     ctrl.set_pin_cfg('5', {'groups':'b'})
     pincfg_path = "%s/%s/etc/raspigpioctrl/" % (PREFIX, self.opt['-r'])
     pin1 = SlavePin(self.opt, "%s/pin1.cfg" % pincfg_path)
     pin1.set_cfg({'groups':'a',
                   'start':'00:00',
                   'prio':'0',
                   'duration':'10',
                   })
     pin2 = SlavePin(self.opt, "%s/pin2.cfg" % pincfg_path)
     pin2.set_cfg({'groups':'a',
                   'start':'00:10',
                   'prio':'1',
                   'duration':'10',
                   })
     pin3 = SlavePin(self.opt, "%s/pin3.cfg" % pincfg_path)
     pin3.set_cfg({'groups':'a',
                   'start':'00:20',
                   'prio':'2',
                   'duration':'10',
                   })
     pin4 = SlavePin(self.opt, "%s/pin4.cfg" % pincfg_path)
     pin4.set_cfg({'groups':'b',
                   'start':'00:00',
                   'prio':'0',
                   'duration':'10',
                   })
     pin5 = MainPin(self.opt, "%s/main5.cfg" % pincfg_path)
     pin5.set_cfg({'groups':'b'})
     exp_items = {
         'gpio_pins': {
             '1': pin1,
             '2': pin2,
             '3': pin3,
             '4': pin4,
             '5': pin5,
         }
     }
     ctrl.arrange_pins()
     self.check(ctrl, exp_items)