def __init__(self, root, state=None): self.root = root ShetClient.__init__(self) Controller.__init__(self, state) self.add_action("set_state", self.set_state)
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) for name in self.names: self.add_action("/%s/email" % name, self.make_email_action(name)) print "Started..."
def __init__(self, root, configfile, *args, **kwargs): self.root = root ShetClient.__init__(self, *args, **kwargs) bindings = filter(None, open(configfile, "r").read().strip().split("\n")) for uri, binding in map((lambda s: s.split(" ", 1)), map(str.strip, bindings)): self.add_action(uri, self.get_binding(binding)) print "Started..."
def __init__(self, root, default_timeout=None): self.root = root self.default_timeout = default_timeout self.timer = None ShetClient.__init__(self) self.timed_out = self.add_event("timed_out") self.on_start = self.add_event("on_start")
def __init__(self, args): self.receiver = eiscp.eISCP(args.ip) ShetClient.__init__(self) self.add_action('/onkyo/volUp', self.volume_up) self.add_action('/onkyo/volDown', self.volume_down) self.add_action('/onkyo/mute', self.mute) self.add_action('/onkyo/on', self.on) self.add_action('/onkyo/standby', self.standby)
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) self.update_url = "http://cloud.tfl.gov.uk/TrackerNet/LineStatus" self.lines = {} self.update_time = 30 #TfL asks for 30 seconds between requests self.updater = LoopingCall(self.updateStatus) self.updater.start(self.update_time) print("Started")
def __init__(self): self.root = root self.rgb = (0,0,0) ShetClient.__init__(self) self.watch_event("state_change", self.on_state_change) self.watch_event("/stairs/pir_top", self.pirTrig) self.watch_event("/stairs/pir_bottom", self.pirTrig) self.routineQueue = [] reactor.callWhenRunning(self.popRoutine)
def __init__(self, root, mpd = None, *args, **kwargs): self.root = root self.mpd = mpd if mpd.endswith("/") else mpd + "/" ShetClient.__init__(self, *args, **kwargs) self.add_action("voices", self.get_voices) self.add_action("say_now", self.say_now) self.add_action("say", self.say) self.say_queue = [] print "Started..."
def __init__(self): self.root = "/bind" self.db = "bind.db" ShetClient.__init__(self) self.add_action("persistant", self.persistant_bind) self.add_action("once", self.once_bind) self.add_action("ls", self.ls) self.add_action("rm", self.rm) self.bindings = {} self.load_bindings()
def __init__(self, root, controllers, default_state=False): self.root = root self.controllers = [] self.default_state = default_state self.controller_states = {} self.watches = [] ShetClient.__init__(self) # Default to off. Controller.__init__(self, False) # Do all the normal stuff when changing the controllers. self.set_controllers(controllers)
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) # Aliases self.add_property("lounge", self.get_lounge, self.set_lounge) self.add_property("kitchen", self.get_kitchen, self.set_kitchen) self.add_action("toggle", self.toggle) self.add_action("on", self.on) self.add_action("off", self.off) self.add_action("mood", self.mood) print "Started..."
def __init__(self, db, root): self.db = db self.root = root ShetClient.__init__(self) # Add a SHET action that calls the corresponding mongo function. def add_mongo_action(f_name): self.add_action( f_name, lambda collection, *args: deferToThread( getattr(self.db.SHET[collection], f_name), *map(to_bson, args)).addCallback(to_json)) for f_name in COLLECTION_ACTIONS: add_mongo_action(f_name)
class LircToShet(LircProtocolFactory): def __init__(self, root, remote): self.shet = ShetClient() self.shet.root = root self.shet.install() self.remote = remote self.events = {} def on_connect(self): self.list(self.remote).addCallback(self.recv_keys) def recv_keys(self, keys): self.shet.reset() for key in keys: code, name = key.split() self.shet.add_action(join("send", name), partial(self.send, name)) on_command = self.shet.add_event(join("on_command", name)) on_first_command = self.shet.add_event(join("on_first_command", name)) self.events[name] = (on_command, on_first_command) def on_command(self, seq, code, remote): if remote == self.remote: self.events[code][0](seq) def on_first_command(self, code, remote): if remote == self.remote: self.events[code][1]() def send(self, name): return self.send_once(self.remote, name)
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) self.watch_event(self.raw_root + "btn_pressed", self.on_btn_pressed) self.watch_event(self.raw_root + "btn_mode_changed", self.on_mode_changed) self.pressed_evt = self.add_event("pressed") self.mode_changed_evt = self.add_event("mode_changed") self.add_property("mode", self.get_mode, self.set_mode) self.add_action("set_led", self.set_led) self.add_action("set_led_instant", self.set_led_instant) print "Started..."
def __init__(self): self.root = "/util/alias" self.db = "alias.db" ShetClient.__init__(self) self.add_action("create", self.create_alias) self.add_action("ls", self.ls) self.add_action("rm", self.rm) self.watch_event("/meta/on_tree_change", self.on_tree_change) self.aliases = [] self.alias_shet = {} self.load_aliases()
def __init__(self, root, lat, long, leeway = 30*60): self.root = root self.lat = lat self.long = long # How long before sunset/after sunrise should the lights still turn on self.leeway = leeway ShetClient.__init__(self) Controller.__init__(self, None) # Allow overriding self.add_action("override_state", self.set_state) # Start the process self.update_state()
def __init__(self, db, root): self.db = db self.root = root ShetClient.__init__(self) # Add a SHET action that calls the corresponding mongo function. def add_mongo_action(f_name): self.add_action(f_name, lambda collection, *args: deferToThread( getattr(self.db.SHET[collection], f_name), *map(to_bson, args) ).addCallback(to_json) ) for f_name in COLLECTION_ACTIONS: add_mongo_action(f_name)
def __init__(self, bindings_dir, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) self.bindings_dir = bindings_dir self.bindings = [] self.load_bindings() # Setup inotify self.notifier = inotify.INotify() self.notifier.startReading() self.notifier.watch(filepath.FilePath(self.bindings_dir), callbacks = [self.notify]) self.watch_event("/lounge/panel/pressed", self.on_btn_pressed) print "Button monitor started..."
def __init__(self, dir): self.root = dir ShetClient.__init__(self) commands = """next prev pause play toggle stop clear seek move volume repeat random single consume findadd update""".split() # Because closures in python are... a bit nutty. def make_command(name): def f(*args): return threads.deferToThread(subprocess.call, ["mpc", name] + map(str, args)) return f for command in commands: self.add_action(command, make_command(command)) self.mpd_client = mpd.MPDClient()
def __init__(self, root, device_names, *args, **kwargs): self.root = root ShetClient.__init__(self, *args, **kwargs) # Turn the user's mixer list and the system mixer list into (mixer-name, # display-name) pairs. user_mixers = map((lambda s: s.split(":", 1)), device_names) sys_mixers = map(lambda m: (m, str(m).replace(" ", "_")), alsaaudio.mixers()) for mixer_name, name in user_mixers or sys_mixers: mixer = MixerControl(mixer_name) self.add_property("%s/volume" % name, mixer.get_vol, mixer.set_vol) self.add_property("%s/mute" % name, mixer.get_mute, mixer.set_mute) self.add_action("%s/mute_toggle" % name, mixer.mute_toggle) self.add_action("%s/vol_inc" % name, mixer.vol_inc) self.add_action("%s/vol_dec" % name, mixer.vol_dec) print "Started..."
def __init__(self, pir_event, pres_property, delay_property, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) self.pir_event = pir_event self.pres_property = pres_property self.delay_property = delay_property self.watch_event(pir_event, self.pir_fired) self.add_property(pres_property, self.get_presence, self.set_presence) self.add_property(delay_property, self.get_delay, self.set_delay) self.timeout_delay = DEFAULT_DELAY # DelayedCall object for timeout self.timeout = None self.presence = False print "Started..."
def __init__(self, root, timeout, override_timeout=60): self.root = root ShetClient.__init__(self) self.on_change = self.add_event("on_change") self.timer_path = join(root, "timer") self.override_timer_path = join(root, "override") Timer(self.timer_path, timeout).install() Timer(self.override_timer_path, override_timeout).install() EventToAction(join(root, "timer", "timed_out"), join(root, "timer", "turn_off")).install() self.watch_event("override/timed_out", self.finish_override) self.override = False self.state = False self.saved_state = False self.timer_turn_on()
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) # Aliases self.add_property("state", self.get_washing, self.set_washing) self.finished_evt = self.add_event("finished") self.finished_notification_evt = self.add_event("finished_notification") self.started_evt = self.add_event("started") self.watch_event(self.raw_root + "washing_finished", self.finished_evt) self.watch_event(self.raw_root + "washing_finished", self.notify_on_finish) self.watch_event(self.raw_root + "washing_started", self.on_start) self.watch_event("/lounge/panel/mode_changed", self.mode_changed) self.go_back_timer = None print "Started..."
def __init__(self, root, tts, *args, **kwargs): self.root = root if root.endswith("/") else root + "/" self.tts = tts if tts.endswith("/") else tts + "/" ShetClient.__init__(self, *args, **kwargs) self.add_action("washing_reminder_booked", self.wasing_reminder_booked) self.add_action("washing_reminder_removed", self.wasing_reminder_removed) self.add_action("all_washing_bookings", self.all_washing_bookings) self.add_action("/matt/wank_start_announce", self.wank_start_announce) self.add_action("/matt/wank_stop_announce", self.wank_stop_announce) self.irc_announce = "addressed" self.add_property("irc_announcements", self.get_irc_announcements, self.set_irc_announcements) self.watch_event("/irc/on_say", self.irc_announce_all) self.watch_event("/irc/on_action", self.irc_announce_all_action) self.watch_event("/shelf/irc/on_address", self.irc_announce_addressed) print "Started..."
def __init__(self, server): ShetClient.__init__(self) self.server = server # Various meta events. self.server.fs.on_change = self.add_event("on_tree_change") self.server.fs.on_raise = self.add_event("on_raise") self.server.fs.on_eventcreated = self.add_event("on_eventcreated") self.server.fs.on_eventdeleted = self.add_event("on_eventdeleted") self.server.fs.on_set = self.add_event("on_set") self.server.fs.on_get = self.add_event("on_get") self.server.fs.on_call = self.add_event("on_call") # Add an event that aggregates the above events. on_activity = self.add_event("on_activity") self.watch_event("on_tree_change", partial(on_activity, "tree_change")) self.watch_event("on_raise", partial(on_activity, "raise")) self.watch_event("on_eventcreated", partial(on_activity, "eventcreated")) self.watch_event("on_eventdeleted", partial(on_activity, "eventdeleted")) self.watch_event("on_set", partial(on_activity, "set")) self.watch_event("on_get", partial(on_activity, "get")) self.watch_event("on_call", partial(on_activity, "call"))
def connectionMade(self): IRCClient.connectionMade(self) self.shet = ShetClient() self.shet.install() self.shet.root = self.root # Channel monitoring actions self.on_action = self.shet.add_event("on_action") self.on_say = self.shet.add_event("on_say") self.on_join = self.shet.add_event("on_join") self.on_quit = self.shet.add_event("on_quit") # This bot can be controlled over SHET self.shet.add_action(self.bot_path + "say", self.shet_say) self.shet.add_action(self.bot_path + "say_to", self.shet_say_to) self.shet.add_action(self.bot_path + "action", self.shet_describe) self.shet.add_action(self.bot_path + "pm", self.shet_pm) self.shet.add_action(self.bot_path + "pm_action", self.shet_pm_describe) # Can listen to bot's PMs self.on_bot_pm = self.shet.add_event(self.bot_path + "on_pm") self.on_bot_pm_action = self.shet.add_event(self.bot_path + "on_pm_action") # User monitoring/contacting for user in self.user_paths: path = self.user_paths[user] user_events = {} self.user_events[user] = user_events # Ways to contact the user (via the bot) self.shet.add_action(path + "bot_say_to", self.get_say_to_fn(user)) self.shet.add_action(path + "bot_pm_to", self.get_pm_to_fn(user)) # User's channel events user_events["on_join"] = self.shet.add_event(path + "on_join") user_events["on_quit"] = self.shet.add_event(path + "on_quit") user_events["on_say"] = self.shet.add_event(path + "on_say") user_events["on_action"] = self.shet.add_event(path + "on_action") # Events other can people trigger related to the user user_events["on_mention"] = self.shet.add_event(path + "on_mention") user_events["on_address"] = self.shet.add_event(path + "on_address") # User interractions with the bot user_events["on_mention_bot"] = self.shet.add_event(path + "on_mention_bot") user_events["on_address_bot"] = self.shet.add_event(path + "on_address_bot") user_events["on_pm_bot"] = self.shet.add_event(path + "on_pm_bot") user_events["on_pm_action_bot"] = self.shet.add_event(path + "on_pm_action_bot")
def __init__(self): ShetClient.__init__(self)
def get_args(): import argparse parser = argparse.ArgumentParser(description="SHETSource router.") parser.add_argument("device", default="/dev/arduino", nargs="?", help="The /dev device of the arduino. default=/dev/arduino") return parser.parse_args() class StoppingGateway(Gateway): """A gateway that stops the reactor when the connection is lost.""" def connectionLost(self, reason): Gateway.connectionLost(self, reason) reactor.stop() if __name__ == "__main__": args = get_args() # Connect to SHET. shet = ShetClient() shet.install() # Connect a gateway to shet gateway = StoppingGateway(shet) # ...and finally connect the gateway to the serial port. SerialPort(gateway, args.device, reactor, baudrate=115200) reactor.run()
def __init__(self, *args, **kwargs): ShetClient.__init__(self, *args, **kwargs) self.add_action("load_playlist", self.load_playlist)
def __init__(self, name): self.root = root+"/"+name ShetClient.__init__(self) Controller.__init__(self, None) self.add_action("standby", self.standby) self.add_action("run", self.run)
def __init__(self): ShetClient.__init__(self) self.events = {}