2 # UCC Door Server - hardware interface server
3 # reads status of reed switches and provides a D-BUS interface to read them
5 # Released under an MIT-style license; see COPYING for details.
7 # statuses: 1 means open circuit, 0 means closed circuit, -1 means error
9 import dbus, dbus.service
12 class Door(dbus.service.Object):
14 def __init__(self, doorname, bus):
15 self.interval = 10 # seconds
16 self.service = doorname
19 # set up D-BUS service name
20 object_path = '/au/asn/ucc/doors/%s' % doorname
21 dbus.service.Object.__init__(self, bus, object_path)
31 if newstatus != self.status:
32 self.status = newstatus
36 # set up timeout again
37 gobject.timeout_add_seconds(self.interval, self.poll)
39 @dbus.service.method('au.asn.ucc.DoorInterface', in_signature='',
44 if __name__ == '__main__':
45 doors = ('uccdoor', 'unisfadoor', 'chdoor', 'mrdoor', 'uccpir')
47 from dbus.mainloop.glib import DBusGMainLoop
48 DBusGMainLoop(set_as_default=True)
50 system_bus = dbus.SystemBus()
51 system_bus.request_name('au.asn.ucc.DoorServer')
56 door_objects.append(Door(door, system_bus))
59 loop = gobject.MainLoop()
62 except KeyboardInterrupt: