Example #1
0
def test_call_state_refuse():
    received_events = set()

    def listener(event, call_state):
        received_events.add(call_state.get_current_state())

    c = CallState()
    c.add_listener(listener)
    assert c.is_disconnected

    # disconnected -> refusing
    c.refuse()
    assert c.is_refusing
    assert 'refusing' in received_events

    try:
        # refusing -> connected is not possible
        c.answer()
        raise AssertionError('can not trannsition from refusing to connected')
    except:
        pass
    assert c.is_refusing
    assert 'connected' not in received_events

    # refusing -> disconnected
    c.hangup()
    assert c.is_disconnected
    assert 'disconnected' in received_events
Example #2
0
File: ui.py Project: synox/telewall
def start():
    """  start running the ui. GPIO must only be loaded when it is stared, as the library is not available on the
         build computer.
    """
    from RPi import GPIO
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)  # use pin numbers as written on the board

    main_led.start()
    button_led.start()
    display.start()
    button.start()

    CallState.add_listener(on_call_state_change)

    main_led.queue(Startup())
    button_led.queue(StartupButton())
    display.show(10, 'Telewall')
Example #3
0
    def __init__(self, ari_client, channel, handset_endpoint, asterisk_app_name):
        """
        :param ari_client: the ari client instance
        :param channel: the active channel with the handset_endpoint
        """
        super(IncomingCall, self).__init__(ari_client, channel, asterisk_app_name)
        self.handset_endpoint = handset_endpoint
        self.call_state = CallState.instance()

        self.state_machine = None
        self.setup_state_machine()
Example #4
0
def test_call_state_permit():
    received_events = set()

    def listener(event, call_state):
        received_events.add(call_state.get_current_state())

    c = CallState()
    c.add_listener(listener)
    assert c.is_disconnected

    # disconnected -> ringing
    c.permit()
    assert c.is_ringing
    assert 'ringing' in received_events

    # ringing -> connected
    c.answer()
    assert c.is_connected
    assert 'connected' in received_events

    # connected -> disconnected
    c.hangup()
    assert c.is_disconnected
    assert 'disconnected' in received_events
Example #5
0
File: ui.py Project: synox/telewall
def on_button_press():
    """ Callback function the call on button press. try to block a caller.  """

    with AsteriskPersistence(Config.ASTERISK_DATABASE_PATH) as asterisk:
        asterisk_anruf = asterisk.get_last_cdr_callerid()
        LOG.info('last caller in asterisk : %s', asterisk_anruf)

    call_state = CallState.instance()
    if call_state.is_ringing or call_state.is_connected:
        _block_caller(call_state.caller)
        show_callerid_blocked(call_state.caller)
        call_state.refuse_if_connected()

    elif asterisk_anruf:
        caller_phone_number = TelephoneNumber(asterisk_anruf.src)
        _block_caller(caller_phone_number)
        show_callerid_blocked(caller_phone_number)
        call_state.refuse_if_connected()

    else:
        LOG.info('nothing to block')
        main_led.queue(NoAction())
        display.show(8, 'Keine Anrufe', 'innert 15min.', centered=True)
Example #6
0
def test_callstate_variables():
    c = CallState()
    c.set_caller(TelephoneNumber('+41315080000'))
    assert_equals('0315080000', c.caller.local)