Issues (158)

doorpi/sipphone/from_dummy.py (8 issues)

1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import logging
5
logger = logging.getLogger(__name__)
6
logger.debug("%s loaded", __name__)
7
8
from time import sleep
9
10
logger.warning('No sipphone in config - use dummy sipphone without functionality')
11
12
import datetime
13
14
from AbstractBaseClass import SipphoneAbstractBaseClass, RecorderAbstractBaseClass, PlayerAbstractBaseClass
15
from doorpi import DoorPi
16
17
def get(*args, **kwargs): return DummyPhone(*args, **kwargs)
18
class DummyPhone(SipphoneAbstractBaseClass):
19
20
    @property
21
    def name(self): return 'dummy phone'
22
23
    @property
24
    def lib(self): return None
25
    @property
26
    def core(self): return None
27
28
    @property
29
    def recorder(self): return self.__recorder
30
    __recorder = None
31
32
    @property
33
    def player(self): return self.__player
34
    __player = None
35
36
    @property
37
    def current_call(self): return None
38
39
    @property
40
    def current_call_duration(self): return 0
41
42
    def __init__(self, whitelist = [], *args, **kwargs):
43
        logger.debug("__init__")
44
        DoorPi().event_handler.register_action('OnShutdown', self.destroy)
45
        DoorPi().event_handler.register_event('OnSipPhoneCreate', __name__)
46
        DoorPi().event_handler.register_event('OnSipPhoneStart', __name__)
47
        DoorPi().event_handler.register_event('OnSipPhoneDestroy', __name__)
48
        self.__recorder = DummyRecorder()
49
    def start(self):
50
        DoorPi().event_handler('OnSipPhoneCreate', __name__)
51
        DoorPi().event_handler('OnSipPhoneStart', __name__)
52
    def destroy(self):
53
        DoorPi().event_handler.fire_event_synchron('OnSipPhoneDestroy', __name__)
54
        DoorPi().event_handler.unregister_source(__name__, True)
55
    def self_check(self, *args, **kwargs):
56
        return
57
    def call(self, number):
58
        DoorPi().event_handler('OnSipPhoneMakeCall', __name__)
59
    def is_admin_number(self, remote_uri):
60
        return False
61
    def hangup(self):
62
        pass
63
64
class DummyRecorder(RecorderAbstractBaseClass):
65
    @property
66
    def record_filename(self): return ''
67
    @property
68
    def parsed_record_filename(self): return ''
69
    @property
70
    def last_record_filename(self): return ''
71
    def __init__(self):
72
        DoorPi().event_handler.register_action('OnSipPhoneDestroy', self.destroy)
73
        DoorPi().event_handler.register_event('OnRecorderStarted', __name__)
74
        DoorPi().event_handler.register_event('OnRecorderStopped', __name__)
75
        DoorPi().event_handler.register_event('OnRecorderCreated', __name__)
76
        DoorPi().event_handler('OnRecorderCreated', __name__)
77
    def start(self):
78
        return False
79
    def stop(self):
80
        return False
81
    def destroy(self):
82
        try: self.stop()
83
        except: pass
84
        DoorPi().event_handler.unregister_source(__name__, True)
85
86
class DummyPlayer(PlayerAbstractBaseClass):
87
    @property
88
    def player_filename(self): return ''
89
    def __init__(self):
90
        doorpi.DoorPi().event_handler.register_action('OnSipPhoneDestroy', self.destroy)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
91
        doorpi.DoorPi().event_handler.register_event('OnPlayerStarted', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
92
        doorpi.DoorPi().event_handler.register_event('OnPlayerStopped', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
93
        doorpi.DoorPi().event_handler.register_event('OnPlayerCreated', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
94
        doorpi.DoorPi().event_handler('OnPlayerCreated', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
95
96
    def start(self): doorpi.DoorPi().event_handler('OnPlayerStarted', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
97
    def stop(self):  doorpi.DoorPi().event_handler('OnPlayerStopped', __name__)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
98
    def destroy(self):
99
        self.stop()
100
        doorpi.DoorPi().event_handler.unregister_source(__name__, True)
0 ignored issues
show
Comprehensibility Best Practice introduced by Thomas
Undefined variable 'doorpi'
Loading history...
101