class Intercom(object): def __init__(self, led_red_channel, led_green_channel, doors_channel, btn_call_channel, snd_dev_capture="default", snd_dev_playback="default"): self.selected_sipid = "sip:localhost" self.led_red = OnOffDevice(led_red_channel) self.led_green = OnOffDevice(led_green_channel) self.doors = OnOffDevice(doors_channel) self.caller = Caller(snd_dev_capture, snd_dev_playback, simple_callback_factory=self._callback_factory) self.buttonCall = Button(btn_call_channel, self.call) def _callback_factory(self): intercom = self class _IntercomCallCallback(SimpleCallCallback): def on_connecting(self): intercom.led_green.start_blinking(0.5) def on_connected(self): intercom.led_green.set(True) def on_disconnected(self): intercom.led_green.set(False) return _IntercomCallCallback() def call(self): self.caller.call(self.selected_sipid) def cancel_call(self): self.caller.cancel_call() def open_door(self, duration=5): self.doors.set(True) time.sleep(duration) self.doors.set(False)
#!/usr/bin/env python # encoding: utf-8 import sys from caller import Caller if __name__ == "__main__": caller = Caller() while True: sys.stdout.write("Provide sip id: or q to exit") line = sys.stdin.readline().strip() if line == "q": break caller.call(line) sys.stdout.write("enter to end the call") sys.stdin.readline() caller.cancel_call() sys.exit(0)