class Vesiohjelmat(Group): vesivahinko_ohjelma = Program( active_condition=And( Or('valutusputki', 'ala_altaat_ylaraja', 'vetta_yli_altaan', 'palkit', 'lattiasensori_1', 'lattiasensori_2', 'kaapin_ulkosuodatin', 'vesivahinko_kytkin'), Not('testimoodi'), Not('vedenvaihtomoodi')), on_activate=Run( SetStatus('vesivahinko_kytkin', 1), SetStatus('co2pump', 0), SetStatus('pumput', 0), #SetStatus('lammitin', 0), SetStatus('co2', 0), SetStatus('alarmtrigger', 1), Run('push_sender_emergency')), on_deactivate=Run('push_sender'), priority=5, ) vedenvaihtomoodi = UserBoolSensor('vedenvaihtomoodi', tags='quick') alaraja_saavutettu = UserBoolSensor('alaraja_saavutettu', tags='quick') waterchange1 = Program( active_condition=And( 'vedenvaihtomoodi', Or('alaraja_saavutettu', 'ala_altaat_alaraja')), on_activate=Run(SetStatus('pumput', 0), SetStatus("co2pump", 0), SetStatus('alaraja_saavutettu', 1), 'push_sender'), priority=5, )
class mysys2(System): class joku(object): joku = 2.0 s = UserFloatSensor(default=3.0) a = FloatActuator() p = Program(active_condition=Attrib(joku, 'joku')) p2 = Program(active_condition=Attrib(p, 'active')) p3 = Program(active_condition=Value(True), on_activate=SetStatus(a, Attrib(s, 'status', no_eval=True)))
class group2(Group): slaveprog = Program(active_condition=Value('s1'), on_update=SetStatus('slaveact', 's2')) p2 = Program( active_condition=Value('s1'), on_activate=SetStatus('act', HIGH), priority=2, ) prog = Program( active_condition=Value('sens'), on_activate=SetStatus('act', HIGH), )
class Out(Group): launchtime = UserBoolSensor( ) #at launchtime, this is used to set out_buffer to 1, before playback can start gmediarender_pid = UserIntSensor(default=0, user_editable=False) out_hardware = RpioActuator(port=17, slave=True) out_actual = BoolActuator( active_condition=Value('out_actual'), on_activate=Run( SetStatus(out_hardware, 1), SetStatus('gmediarender_pid', Shell('gmediarender -f raspi2', no_wait=True))), on_deactivate=Run( If( 'gmediarender_pid', Run(Func(os.kill, gmediarender_pid, signal.SIGTERM), SetStatus('gmediarender_pid', 0))), Shell('amixer sset Master mute'), SetStatus('out_hardware', 0))) out_buf_prog = Program(on_update=SetStatus( 'out_buffer', Or('launchtime', 'playback_active', 'piano_on', 'manual_mode'))) out_buffer = BoolActuator( safety_mode='both', change_delay=900.0, change_mode='falling', on_update=SetStatus(out_actual, 'out_buffer'), )
class _mysys(System): act = FloatActuator(default=ORIGVAL) a2 = FloatActuator(default=ORIGVAL) sens = UserBoolSensor(default=False) prog = Program(active_condition=OfType(FloatActuator), ) prog2 = Program(active_condition=And(sens, 'all_floatactuators'), ) prog3 = Program(active_condition=And( sens, OfType(FloatActuator, exclude=[a2])), ) prog4 = Program( priority=2.0, active_condition=Value(sens), on_activate=SetStatus(OfType(FloatActuator, type='targets'), 3.0), ) all_floatactuators = OfType(AbstractActuator) prog5 = Program(on_activate=Run( SetStatus(all_floatactuators, all_floatactuators)), )
class ms(System): reset_mplayer = (If( Not('out_actual'), Run( SetStatus('launchtime', 1), WaitUntil( 'soundcard_ready', SetStatus('volume', 0), SetStatus('volume', 10), SetStatus('launchtime', 0), ), ))) start = UserBoolSensor(active_condition=Value('start'), on_activate=Run( 'reset_mplayer', WaitUntil( And('soundcard_ready', Not('launchtime')), Func(start_playback, 'volume'), SetStatus('start', 0)))) volume = UserIntSensor() out_actual = BoolActuator(active_condition=Value('out_actual'), on_activate=SetStatus('soundcard_ready', 1)) launchtime = UserBoolSensor() out_buf_prog = Program(on_update=SetStatus('out_buffer', 'launchtime')) out_buffer = BoolActuator(on_update=SetStatus(out_actual, 'out_buffer'), ) soundcard_ready = UserBoolSensor()
class grp(Group): p = Program( priority=2.0, active_condition=And(Or('s', 's2')), on_activate=Run(Run(SetStatus('a', 's'))), update_condition=Run(Run(SetStatus('a', 's'))), )
def test_namespace(): sys = System(exclude_services=['TextUIService'], name='test') ns = sys.namespace # AutomateNamespace(sys) # ns.set_system() s = AbstractSensor() ns['sens'] = s assert s in ns.reverse assert 'sens' in ns #assert ns.sens is s assert s in sys.sensors ns['one'] = 1 assert 1 not in ns.reverse a = AbstractActuator() ns['act'] = a with pytest.raises(ValueError): ns['act'] = a assert a in sys.actuators assert a not in sys.sensors p = Program() ns['prg'] = p assert p in sys.programs #assert 'sensors' in ns #assert 'programs' in ns #assert 'actuators' in ns del ns['prg'] assert not p in sys.programs del ns['act'] assert not a in sys.actuators sys.cleanup()
class _mysys(System): act = FloatActuator(default=ORIGVAL) a2 = FloatActuator(default=ORIGVAL) sens = UserBoolSensor(default=False) prog = Program( active_condition=Value(sens), on_activate=SetStatus(act, NEWVAL), )
class mysys(System): s1 = UserBoolSensor() s2 = UserBoolSensor() s3 = UserBoolSensor() s4 = UserBoolSensor() a = UserIntSensor() p = Program(active_condition=Or(s1, s2, s3, s4), on_update=If(Equal(TriggeredBy(), s1), SetStatus(a, 1)))
class sysclass(System): mysensor = UserFloatSensor() myactuator = FloatActuator() prog = Program( active_condition=Value(mysensor if request.param else 'mysensor'), on_update=Run( SetStatus(myactuator if request.param else 'myactuator', 1), Debug("Hello World!")), )
class _mysys(System): act = FloatActuator(default=LOW) slaveact = FloatActuator(default=LOW, slave=True) slavebinact = BoolActuator(default=False, slave=True) sens = UserBoolSensor(default=False) s1 = UserBoolSensor(default=False) s2 = UserFloatSensor(default=HIGH) slaveprog = Program(active_condition=Value(s1), on_update=SetStatus(slaveact, s2)) p2 = Program( active_condition=Value(s1), on_activate=SetStatus(act, HIGH), priority=2, ) prog = Program( active_condition=Value(sens), on_activate=SetStatus(act, HIGH), )
class sys(System): s1 = UserBoolSensor() a1 = BoolActuator() a2 = BoolActuator() p1 = Program(update_condition=Or(s1, a1), on_activate=Run( SetStatus(a1, s1), SetStatus(a2, a1), SetStatus(a1, s1), SetStatus(a2, a1), ))
class mysys(System): sensori = UserFloatSensor() slave1 = FloatActuator(slave=True, default=0.0) targetti = ConstantTimeActuator(change_time=5.0, change_frequency=10., slave_actuator=slave1) slave2 = FloatActuator(slave=True, default=0.0) targetti2 = ConstantSpeedActuator(speed=1.0, change_frequency=10., slave_actuator=slave2) prog = Program( on_update=Run(Log("Test!"), SetStatus(targetti, sensori), SetStatus(targetti2, sensori)) )
class mysys2(System): mysensor2 = UserFloatSensor() myactuator2 = FloatActuator() # timers have cron syntax timer = CronTimerSensor(timer_on="30 15 * * mon-thu;1 16 * * fri-sat,sun", timer_off="30 8 * * mon-thu;0 10 * * fri-sat,sun") prog2 = Program(active_condition=Value(mysensor2), on_update=Run( SetStatus(myactuator2, 1), Debug("Hello World!"), ))
class In(Group): soundcard_ready = UserBoolSensor( active_condition=Value('soundcard_ready'), on_activate=SetStatus( 'volume', IfElse('piano_on', 'piano_volume', 'normal_volume')), ) playback_active = UserBoolSensor() set_piano_volume = Program( active_condition=And('piano_on', 'soundcard_ready'), on_activate=SetStatus('volume', 'piano_volume'), on_deactivate=SetStatus('volume', 'normal_volume'))
class LCD(Group): lcd_act = ArduinoLCDActuator(log_level=logging.WARNING) lcd_program = Program( on_activate=SetStatus('lcd_act', 'Hello from\nAquarium!'), on_update=SetStatus( 'lcd_act', ToStr('pH:{0:.2f} A:{1:.1f}\nP:{2:.1f} U:{3:.1f}', 'ph', 'aqua_temperature', 'parvekkeen_lampo', 'ulko_lampo'))) lcd_backlight = UserBoolSensor( active_condition=Value('lcd_backlight'), on_activate=LCDSetBacklight(True), on_deactivate=LCDSetBacklight(False), )
class _mysys(System): class group1(Group): s1 = UserFloatSensor(default=HIGH) class group2(Group): s2 = UserFloatSensor(default=HIGH) class group3(Group): s3 = UserFloatSensor() act = FloatActuator(default=LOW) p2 = Program( active_condition=Value('s1'), on_activate=SetStatus('act', HIGH), priority=2, )
class Out(Group): launchtime = UserBoolSensor() piano_on = UserBoolSensor() gmediarender_pid = UserIntSensor(default=0, user_editable=False) out_actual = BoolActuator( active_condition=Value('out_actual'), on_activate=SetStatus('gmediarender_pid', 1), on_deactivate=If( 'gmediarender_pid', Run(Empty(), SetStatus('gmediarender_pid', 0))), ) out_buf_prog = Program(on_update=SetStatus( 'out_buffer', Or('launchtime', 'playback_active', 'piano_on', 'manual_mode'))) out_buffer = BoolActuator( safety_mode='both', change_delay=900.0, change_mode='falling', on_update=SetStatus(out_actual, 'out_buffer'), )
class mysys(System): class mygroup(Group): class mygrp2(Group): mysensor = UserBoolSensor(tags='web') act2 = FloatActuator(priorities={'myactuator': -1}) myactuator = FloatActuator( on_update=Run(Log('hep hep'), SetStatus(mygroup.act2), Log('jep %s', ToStr('myactuator'))) ) # timers have cron syntax timer = CronTimerSensor( timer_on="30 15 * * mon-thu;1 16 * * fri-sat,sun", timer_off="30 8 * * mon-thu;0 10 * * fri-sat,sun" ) prog = Program(active_condition=Value(mygroup.mygrp2.mysensor), on_update=Run( SetStatus(myactuator, 1), Debug("Hello World!"), ) )
def new(self, progname): prog = Program(self.cleaned_data.pop('name')) prog.setup_system(self.system) return prog
class mysys(System): s1 = UserBoolSensor() s2 = UserBoolSensor() s3 = UserIntSensor() p = Program(active_condition=Or(s1, s2), on_update=If(TriggeredBy(s1), SetStatus(s3, 1)))
class sys(System): testact = TstActuator(default=0.0) sens = UserFloatSensor(default=0.0) prog = Program(on_update=SetStatus(testact, sens))
class sys(System): after_reset = Program( update_condition=Value(False), on_update=Func(func), )
class Ajastimet(Group): co2_ajastin = CronTimerSensor( tags='co2', timer_on="30 12 * * *", # oli 5:30 mutta muutan turvallisemmaksi... timer_off="0 16 * * *") co2_ajastin_loma = CronTimerSensor(tags='co2, holiday', timer_on="55 15 * * *", timer_off="0 18 * * *") co2_pumppu_ajastin = CronTimerSensor(tags='co2', timer_on="55 15 * * *", timer_off="0 22 * * *") co2_pumppu_ajastin_loma = CronTimerSensor(tags='co2, holiday', timer_on="55 15 * * *", timer_off="0 22 * * *") # Muista: tämä kontrolloi (myös) UVC:ta! lamput_ajastin = CronTimerSensor(timer_on="0 14 * * *", timer_off="0 22 * * *") lamppu1_ajastin = CronTimerSensor( timer_on="0 13,15,18 * * *", timer_off="0 21 * * *;2 14,17 * * *", active_condition=And('lamput_ajastin2_k', 'lamppu1_ajastin'), on_activate=SetStatus('lamppu1', 1), ) lamppu2_ajastin = CronTimerSensor( timer_on="2 13 * * *;0 16 * * *", timer_off="3 21 * * *;2 15 * * *", active_condition=And('lamput_ajastin2_k', 'lamppu2_ajastin'), on_activate=SetStatus('lamppu2', 1), ) lamppu3_ajastin = CronTimerSensor( timer_on="0 14,17 * * *", timer_off="6 21 * * *;2 16 * * *", active_condition=And('lamput_ajastin2_k', 'lamppu3_ajastin'), on_activate=SetStatus('lamppu3', 1), ) dimmer_ajastin = CronTimerSensor( timer_on="5 21 * * *", timer_off="10 21 * * *", active_condition=Value('dimmer_ajastin'), on_activate=If( 'lamput_ajastin2_k', Delay(50, RemoteFunc(raspi2host, 'set_status', 'akvadimmer', 1)))) lamput_ajastin_loma = CronTimerSensor(timer_on="0 16 * * *", timer_off="0 22 * * *", tags="holiday") ajastinohjelma = Program( on_update=IfElse( 'lomamoodi', Run(SetStatus('co2pump', co2_pumppu_ajastin), SetStatus('lamput', lamput_ajastin_loma), SetStatus('co2', co2_ajastin_loma), Delay(30, SetStatus('uvc', lamput_ajastin_loma))), Run(SetStatus('co2pump', co2_pumppu_ajastin), SetStatus('lamput', lamput_ajastin), SetStatus('co2', co2_ajastin), Delay(30, SetStatus('uvc', lamput_ajastin)))), priority=1.5, triggers=['lomamoodi'], tags='co2', )
class sys(System): s1 = UserBoolSensor() p1 = Program(active_condition=Value(s1), on_activate=SetStatus(s1, 1))
class sys(System): s = request.param() p = Program(on_update=SetStatus(s, 1), triggers=[s])