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 read_cfg(self, force_init=False): """ read cfg file and update gpio_pins dict """ path = "%s/%s" % (PREFIX, self.gpio_cfg_path) for root, dirs, files in os.walk(path): for file_path in files: if file_path.startswith("main"): pin = MainPin(self.opt, "%s/%s" % (root, file_path)) else: pin = SlavePin(self.opt, "%s/%s" % (root, file_path)) pin.init_pin(force_init) self.add_pin(pin)
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)
def test3_0_1_pin(self): """ Pin >3_0_1> init main pin """ test_file = "%s/packaged/etc/raspigpioctrl/main5.cfg" % PREFIX pin = MainPin(self.opt, test_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) pin.deb("'%s' removed") self.assertFalse(os.path.exists(gpio_sys), "") pin.init_pin() filed = open("%s/gpio5/value" % gpio_sys, "r") cont = filed.read().strip() self.assertTrue(cont == "0", cont) pin.flip() filed = open("%s/gpio5/value" % gpio_sys, "r") cont = filed.read().strip() self.assertTrue(cont == "1", cont) pin.flip() filed = open("%s/gpio5/value" % gpio_sys, "r") cont = filed.read().strip() self.assertTrue(cont == "0", cont) pin.change_mode('auto') pin.flip() filed = open("%s/gpio5/value" % gpio_sys, "r") cont = filed.read().strip() self.assertTrue(cont == "1", cont) pprint(pin.get_json()) self.assertTrue(pin.ismode('off'))
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)
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)