示例#1
0
def main():
    try:
        import pynotify
    except ImportError:
        print "You don't have the Python libnotify binding installed."
        sys.exit()
    
    if not pynotify.init("timernotify"):
        print "Libnotify could not be initialized."
        sys.exit()
    
    parser = OptionParser(usage="usage: python -m timernotify [options]", 
            add_help_option=False)
    parser.add_option("-h", type="string", action="store", dest="host", default="localhost",
            help="The host that the Autobus server is running on. Without this "
            "option, localhost will be used.")
    parser.add_option("-s", action="store_const", const=True, dest="state_change",
            default=False, help="If present, all state changes (instead of just "
            "when the timer beeps) will cause a notification to be shown.")
    parser.add_option("-?", "--help", action="help")
    
    options, command_line_args = parser.parse_args()
    
    bus = AutobusConnection(host=options.host)
    def beeping_listener(timer):
        pynotify.Notification("Timer " + str(timer), "is beeping.").show()
    
    def state_change_listener(timer, state):
        state_string = {1: "counting up", 2: "counting down", 3: "stopped"}[state]
        pynotify.Notification("Timer " + str(timer), "is now " + state_string + 
                ".").show()
    
    bus.add_event_listener("timer", "beeping", beeping_listener)
    if options.state_change:
        bus.add_event_listener("timer", "manual_state_change", state_change_listener)
    
    bus.connect()
    
    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        print "Interrupted, shutting down"
    finally:
        bus.shutdown()
示例#2
0
文件: homed.py 项目: giflw/afn-tools
def main():
    global bus
    global config
    global activehome
    bus = AutobusConnection()
    activehome = bus["activehome"]
    bus.add_interface("home", Interface())
    config = Configuration(bus, "configure.home", "homed.conf")
    bus.start_connecting()
    bus.interrupt_loop()
    
示例#3
0
    try:
        arguments.append(int(value))
        continue
    except: # Not an int
        pass
    if value in fixed_values:
        arguments.append(fixed_values[value])
        continue
    if value.startswith(":"):
        arguments.append(eval(value[1:]))
        continue
    arguments.append(value)    
    

from libautobus import AutobusConnection, NotConnectedException
bus = AutobusConnection(**connect_options)

# We've got everything set up thus far. Now we'll look up the mode and figure
# out what we need to do before we connect to the Autobus server.

if mode == "event":
    def event_function(*arguments):
        if len(arguments) < 0:
            print "Function fired with no arguments."
        print str(arguments)
    bus.add_event_listener(interface_name, item_name, event_function)

if mode == "object":
    printed = False
    def object_function(new_value):
        global printed
示例#4
0
def main():
    global bus
    global receive_event
    global receive_action_event
    pythoncom.CoInitialize()
    try:
        Dispatch("X10.ActiveHome") # Make sure we've got it before hand
    except:
        print_exc()
        print "You need to install the ActiveHome Scripting SDK before you"
        print "can use activehomed."
        sys.exit()
    print "Connecting to server " + str(os.getenv("AUTOBUS_SERVER"))
    bus = AutobusConnection()
    bus.add_interface("activehome", RPC())
    receive_action_event = bus.add_event("activehome", "receive_action", """\
    Fired when the CM15A receives a powerline or RF signal. This event is quite
    low-level and hence the receive event should be preferred to this one. The
    signature of this event is identical to the ActiveHome Scripting SDK's
    OnRecvAction event, except that all parameters are passed as strings and
    the last two parameters are not present (the scripting SDK doesn't make
    use of those at present, so you're not losing any information).
    """)
    receive_event = bus.add_event("activehome", "receive", """\
    receive(mode, house, unit, address, command, sequence, timestamp, repeat)
    
    Fired when the CM15A receives a powerline or RF signal. This event is more
    high-level than receive_action.
    
    mode is the mode, which will either be plc or rf.
    
    house is the house code. unit is the unit code. address is the string
    concatenation of the house and unit codes. For example, house, unit, and
    address could be "d", "2", and "d2", respectively. All three parameters are
    passed as strings.
    
    command is the command that occurred. The ActiveHome Scripting SDK contains
    a list of all valid commands, but some of the more common ones are On, Off,
    AllLightsOn, AllUnitsOff, Bright, Dim, PanLeft, CamGoPosition1, and
    DeviceStop (the latter of which occurs when the CM15A is unplugged from the
    computer).
    
    sequence is slightly command-specific, as follows:
    
    If this is an RF command, sequence will be the sequence number, which
    is 0 for the button being pressed down, 1 and upward for holding
    the button down (fired roughly six times per second), and -1 for
    letting go of the button. A word of warning: this doesn't seem to
    be hugely reliable. For example, pushing an on button on a ScanPad
    or PalmPad results in six events: three pairs of button press and button 
    release commands, despite the fact that the button was only pressed
    once. Holding the button down just repeats these pairs further. If you want
    a reliable indicator of whether or not a button press is a repeat, use the
    repeat parameter passed to this event.
    
    If this is a powerline command, sequence will be null unless the command is
    Bright or Dim, in which case it will be the bright/dim level. When a
    bright/dim button is held down on an RF controller, the result is a
    repeated firing of Bright/Dim commands. When a bright/dim button is held
    down on a powerline controller, the result is that no events are fired
    until the button is let go, and then a single Bright/Dim command is fired
    with the sequence parameter being set to the percent change in brightness
    that would have resulted had the command been directed at an actual module.
    
    The timestamp parameter is only present for RF commands. It specifies, as
    a string, the date and time at which the command was received. This
    generally won't be used since Autobus only incurs a few milliseconds'
    latency, so the date could just be detected locally.
    
    repeat is a boolean. It will be set to true if this event is most likely a
    repeat of another event. For example, if an on button on a ScanPad
    controller is pressed, the result is three pairs of button press and button
    release commands. The first command will have its repeat parameter set to
    false, and the remaining five commands will have their repeat parameters
    set to true. Another example is a bug in the CM15A: If two units were
    simultaneously turned on (for example, by A1 A2 A off going across the
    powerline), and then an AllLightsOn received on the powerline for that
    house code, the CM15A will report that as two events: A1 AllLightsOff and
    A2 AllLightsOff. The latter will be detected as a repeat when this event
    is fired. NOTE: There are currently problems with detecting RF
    bright/dim repeats, so you should generally ignore this parameter for
    RF bright/dim commands.
    """)
    bus.start_connecting()
    try:
        HTTPServer(("127.0.0.1", port), HTTPHandler).serve_forever()
    except KeyboardInterrupt:
        print "Interrupted, shutting down"
    finally:
        bus.shutdown()
示例#5
0
文件: autobus2.py 项目: hzmmzl/afn
from libautobus import AutobusConnection

server = AutobusConnection()
server.connect()

interface = server["example"]
print interface.say_hello("Alex")

server.shutdown()
示例#6
0
def init(context):
    global bus
    bus = AutobusConnection("spiro.afn")
    bus.start_connecting()
示例#7
0
from time import sleep

class ExampleInterface(object):
    """
    An example interface. It doesn't do much.
    
    Basically, all it allows you to do is say hello.
    """
    def say_hello(self, name):
        """
        Formats a "hello world"-style message greeting the specified person by
        name and returns it. The argument must be a string or an exception will
        be raised.
        """
        print "We're about to say hi to " + name
        return "Hello, " + name + ". How are you?"

server = AutobusConnection()
server.add_interface("example", ExampleInterface())
server.connect()


# That's it for the actual autobus code. The rest of the code is a hack to get
# around python not letting the application die with ctrl+c.
try:
    while True:
        sleep(1)
except KeyboardInterrupt:
    print "Shutting down"
    server.shutdown()
示例#8
0
from libautobus import AutobusConnection
from os import getpid

class ExampleInterface(object):
    def say_hello(self, name):
        return "Hello, " + name + ". How are you?"

for i in range(10):
    server = AutobusConnection()
    server.add_interface("afntest.autobus3." + str(i), ExampleInterface())
    server.connect()

print "Started up. pid is " + str(getpid()) + " which you can use to kill"
print "this once you're done with it."