示例#1
0
def _while_did_press(on_active, pin, handler: HandleSocket, cycle_t):
    if on_active:
        handler.handle_socket(auto_on=True, auto_off=True)
        while on_active:
            did_use = pin.is_on()
            on_active = _flip(did_use)
            if did_use:
                handler.handle_socket(auto_on=True, auto_off=True)
            if get_date_now() > cycle_t:
                on_active = False
            time.sleep(0.1)
def within_delta(disable_from, enable_from, auto_on, auto_off, date_now=None):
    _date_now = date_now or get_date_now()
    _within_timedelta = within_timedelta(date_now=_date_now, delta_begin=disable_from, delta_end=enable_from)
    
    if auto_on:
        if _within_timedelta is False:
            print("outside delta")
            return True

    if auto_off:
        if _within_timedelta:
            print("within delta")
            return False
    return False
示例#3
0
def main(auto_on: bool, auto_off: bool, disable_from, enable_from,
         update_cycle, ignore_gpio):
    pin_5a = RPIG(pin=5)
    pin_6b = RPIG(pin=6)

    next_update = get_date_now() + timedelta(seconds=update_cycle)
    handle_socket = HandleSocket(on=run_on_script, off=run_off_script)
    while True:
        main_on_off_wrapper(disable_from=disable_from,
                            enable_from=enable_from,
                            auto_on=auto_on,
                            auto_off=auto_off,
                            handle_socket=handle_socket)

        print("Sleep" + str(update_cycle))
        time.sleep(update_cycle)
        print("End final")
    def test_screen_2_a(self):
        backlight_config = BacklightConfig(auto_on=True,
                                           auto_off=False,
                                           disable_from="00:00:00",
                                           enable_from="00:01:00",
                                           update_cycle=6,
                                           ignore_gpio=True,
                                           name="test")
        now = get_date_now(str_now="23:59:30")
        next_update = now + timedelta(seconds=backlight_config.update_cycle)

        mock_on = mock.Mock(return_value="mocked stuff")
        mock_off = mock.Mock(return_value="mocked stuff")
        mock_date_now = mock.Mock(return_value=now)
        main_on_off_wrapper(disable_from=backlight_config.disable_from,
                            enable_from=backlight_config.enable_from,
                            auto_on=backlight_config.auto_on,
                            auto_off=backlight_config.auto_off,
                            handle_screen=HandleScreen(on=mock_on,
                                                       off=mock_off),
                            get_now=mock_date_now)
        mock_on.assert_called()
        mock_off.assert_not_called()