コード例 #1
0
 def test0_1_init_cfg(self):
     """
     Pin >0_1> check items in initial __dict__ from test1.cfg
     """
     test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin1 = SlavePin(self.opt, test1_file)
     pin1.init_pin(True)
         
     exp_items = {
         'crypt': '8c34222d580d60b98fe73a05eeca0d3d',
         'pin_nr': '1',
         'cfg_file': test1_file,
         'name': 'Front',
         'prio': '0',
         'mode': 'time',
         'groups': 'garden',
         'start': '01:00',
         'duration': '60',
         'sun_delay': '0',
         'state': '0',
         'dow': 'Wed,Sun',
         'gpio_base': "%spackaged/sys/class/gpio" % PREFIX,
         'pin_base': "%spackaged/sys/class/gpio/gpio1" % PREFIX,
     }
     self.check_dict(pin1, exp_items)
コード例 #2
0
 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())
コード例 #3
0
    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)
コード例 #4
0
 def test3_0_pin(self):
     """
     Pin >3_0> init dry-run pin
     """
     test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin1 = SlavePin(self.opt, test1_file)
     gpio_sys = "%s/packaged/sys/class/gpio/" % PREFIX
     if os.path.exists("%s/packaged/sys" % PREFIX):
         print os.system("rm -rf %s/packaged/sys" % PREFIX)
         pin1.deb("'%s' removed")
         self.assertFalse(os.path.exists(gpio_sys), "")
     pin1.init_pin()
     filed = open("%s/gpio1/value" % gpio_sys, "r")
     cont = filed.read().strip()
     self.assertTrue(cont == "0", cont)
コード例 #5
0
    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")
コード例 #6
0
    def test0_1_init_flip(self):
        """
        Web >0_1> show green status
        """

        test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        pin1 = SlavePin(self.opt, test1_file)
        pin1.init_pin(True)
        pin1.flip()

        web = Web(self.opt)
        web.add_pin(pin1)
        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_tail])
        exp[20] = "<td style='background-color:green'>"
        self.assertEqual(web.html, exp)
コード例 #7
0
    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)
コード例 #8
0
    def test0_0_init(self):
        """
        Web >0_0> fire up web class
        """
        exp = ""

        test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
        print test1_file
        pin1 = SlavePin(self.opt, test1_file)
        pin1.init_pin(True)

        web = Web(self.opt)
        web.add_pin(pin1)
        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_tail])
        exp[20] = "<td style='background-color:red'>"
        got = web.html
        self.check_web(got, exp)
コード例 #9
0
 def test3_4_flip(self):
     """
     Pin >3_4> init dry-run pin and flip twice with main-pin
     """
     test1_file = "%s/packaged/etc/raspigpioctrl/pin1.cfg" % PREFIX
     pin1 = SlavePin(self.opt, test1_file)
     test5_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % PREFIX
     pin5 = MainPin(self.opt, test5_file)
     gpio_sys = "%s/packaged/sys/class/gpio/" % PREFIX
     if os.path.exists("%s/packaged/sys" % PREFIX):
         print os.system("rm -rf %s/packaged/sys" % PREFIX)
         pin1.deb("'%s' removed")
         self.assertFalse(os.path.exists(gpio_sys), "")
     pin1.init_pin()
     pin5.init_pin()
     pin1.set_pin(0)
     pin5.set_pin(0)
     pin5.change_mode('auto')
     pin1.flip()
     filed = open("%s/gpio1/value" % gpio_sys, "r")
     cont = filed.read().strip()
     filed.close()
     self.assertTrue(cont == "1", cont)