def get(self): cmds = Res.init("init.json")["command"] for key in cmds: self.write("%s: " % (key, )) for cmd in cmds[key]: self.write("%s, " % (cmd, )) self.write("\n")
def _stop_callback(self, command, stop): DEBUG(" _stop_callback: %s" % command) Sound.play(Res.get_res_path("sound/com_stop"), inqueue=True) if "stop" in self._registered_callbacks: callbacks = self._registered_callbacks["stop"] if stop in callbacks: callbacks[stop](stop=stop)
def __init__(self): init_json = Res.init("init.json") self.server_ip = init_json["connection"]["sensor_server"] self.name2addr = init_json["sensors"] self._send_lock = threading.Lock() self.init_sensors()
def callback(self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new": path = "usr/memo/" try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: ERROR(exc) self._home.publish_msg(cmd, u"录音错误") return False self._home.setResume(True) filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3" record = self._global_context["recorder"] self._home.publish_msg(cmd, u"录音开始...") record(filepath) self._home.publish_msg(cmd, u"录音结束") Sound.play( Res.get_res_path("sound/com_stop") ) self._home.setResume(False) return True
def callback(self, cmd, msg): self._home.publish_msg(cmd, u"正在截图...") Sound.notice(Res.get_res_path("sound/com_shoot")) save_path="data/capture/" save_name, thumbnail_name = CameraHelper().take_a_photo(save_path) # for test # save_name = "2015_05_02_164052.jpg" if save_name is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True img_url, thumbnail_url = self._upload_image( save_path + save_name, save_path + thumbnail_name, ) if img_url is None: self._home.publish_msg(cmd, u"截图失败") INFO("upload capture faild.") return True else: self._home.publish_msg( cmd, msg=img_url, cmd_type="capture" ) return True
def callback(self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new" or pre_value == "set": if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None INFO("alarm wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play( Res.get_res_path("sound/com_bell") , True, count) self._home.setResume(False) return True
def callback(self, cmd, action, target, msg): if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) elif msg.endswith(u"秒"): t = int(Util.cn2dig(msg[:-1])) elif msg.endswith(u"分钟"): t = int(Util.cn2dig(msg[:-2]))*60 elif msg.endswith(u"小时"): t = int(Util.cn2dig(msg[:-2]))*60*60 else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None DEBUG("thread wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play( Res.get_res_path("sound/com_bell") , True, count) self._home.setResume(False) return True
def callback(self, cmd, msg): self._home.publish_msg(cmd, u"正在截图...") Sound.play(Res.get_res_path("sound/com_shoot")) save_path="data/capture/" save_name, thumbnail_name = CameraHelper().take_a_photo(save_path) # for test # save_name = "2015_05_02_164052.jpg" if save_name is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True img_url, thumbnail_url = self._upload_image( save_path + save_name, save_path + thumbnail_name, ) if img_url is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True else: self._home.publish_msg( cmd, msg=img_url, cmd_type="capture" ) return True
def callback(self, cmd, action, target, msg): if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) elif msg.endswith(u"秒"): t = int(Util.cn2dig(msg[:-1])) elif msg.endswith(u"分钟"): t = int(Util.cn2dig(msg[:-2])) * 60 elif msg.endswith(u"小时"): t = int(Util.cn2dig(msg[:-2])) * 60 * 60 else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None DEBUG("thread wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play(Res.get_res_path("sound/com_bell"), True, count) self._home.setResume(False) return True
def callback( self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new": path = "usr/message/" try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: ERROR(exc) return False self._home.setResume(True) filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3" Sound.play(Res.get_res_path("sound/com_stop")) record = self._global_context["recorder"] self._home.publish_msg(cmd, u"录音开始...") record(filepath) self._home.publish_msg(cmd, u"录音结束") self._home.setResume(False) elif pre_value == "play": self._home.setResume(True) play = self._global_context["player"] for idx, filepath in enumerate(glob.glob("usr/message/*.mp3")): # self._speaker.speak(u'第%d条留言' % (idx + 1)) INFO(u'第%d条留言:%s' % (idx + 1, filepath)) play(filepath) play(Res.get_res_path("sound/com_stop")) self._home.setResume(False) elif pre_value == "remove": filelist = glob.glob("usr/message/*.mp3") for f in filelist: os.remove(f) INFO("remove:%s" % (f, )) Sound.play( Res.get_res_path("sound/com_trash") ) return True
def __init__(self): init_json = Res.init("init.json") self.scan_ip = SwitchHelper.BOARDCAST_ADDRESS self.name2ip = init_json["switchs"] self._send_lock = threading.Lock() self.switchs = {} self._init_heartbeat()
def __init__(self): self._sock = None init_json = Res.init("init.json") try: self.place2ip = init_json["sensor"] except Exception, e: ERROR(e) ERROR("invaild SensorHelper init json.") self.place2ip = {}
def __init__(self): self.devices = {} self._queues = {} settings = Res.init("init.json") self.server_ip = "tcp://*:8005" self._device_addrs = [] addrs = settings['ping']['device'] for name in addrs: self._device_addrs.append(addrs[name])
def __init__(self, address): if not address is None: INFO("connect to server: %s " % (address)) self._home_address = address settings = Res.init("init.json") self._device_id = settings['id'] self._trigger_cmd = settings['command']['trigger'][0].encode("utf-8") self._finish_cmd = settings['command']['finish'][0].encode("utf-8") INFO("load device id:%s" % self._device_id) else: ERROR("address is empty")
def __init__(self, address): if not address is None: INFO("connect to server: %s " % (address)) self._home_address = address settings = Res.init("init.json") self._device_id = settings['id'] self._trigger_cmd = settings['command']['trigger'][0].encode( "utf-8") self._finish_cmd = settings['command']['finish'][0].encode("utf-8") INFO("load device id:%s" % self._device_id) else: ERROR("address is empty")
def callback(self, action=None, target=None, msg=None, pre_value=None): if pre_value == "play": if msg is None or not msg.endswith(u"次"): count = 1 else: count = int(Util.cn2dig(msg[:-1])) self._home.setResume(True) play = self._global_context["player"] play(Res.get_res_path("sound/com_warn"), loop=count) self._home.setResume(False) return True
def __init__(self, address): if not address is None: INFO("connect to server: %s " % (address)) context = zmq.Context() self._sock = context.socket(zmq.SUB) self._sock.connect(address) self._sock.setsockopt(zmq.SUBSCRIBE, '') self.channel = Channel(PUSH_apiKey, PUSH_secretKey) self._mipush = mipush.MIPush(MIPUSH_SECRET_KEY) self._msg_queue = Queue() settings = Res.init("init.json") self._device_id = settings['id'] else: ERROR("address is empty")
def __init__(self, address): if not address is None: INFO("connect to server: %s " % (address)) context = zmq.Context() self._sock = context.socket(zmq.SUB) self._sock.connect(address) self._sock.setsockopt(zmq.SUBSCRIBE, '') self.channel = Channel(PUSH_apiKey, PUSH_secretKey) self.xinge_app = xinge.XingeApp(XINGE_ACCESS_ID, XINGE_SECRET_KEY) self._msg_queue = Queue() settings = Res.init("init.json") self._device_id = settings['id'] else: ERROR("address is empty")
class qqfm_callback(Callback.Callback): base_url = 'http://' + Res.get('qqfm/server') channel_url = base_url + '/list' next_url = base_url + '/next' pause_url = base_url + '/pause' def init_channcels(self): self._fm_state = 0 try: INFO("init qqfm:" + qqfm_callback.channel_url) channels = urllib2.urlopen(qqfm_callback.channel_url, timeout=5).read() self.channels = [channel.decode("utf-8") for channel in channels.split('\n')] except Exception, ex: ERROR("qqfm init error.") ERROR(ex) self._home.publish_msg("init qqfm", u"连接失败") self.channels = []
def __init__(self): init_json = Res.init("init.json") self._address = init_json["ril_address"] self._send_lock = threading.Lock()