本文整理汇总了Python中mycroft.messagebus.client.ws.WebsocketClient.once方法的典型用法代码示例。如果您正苦于以下问题:Python WebsocketClient.once方法的具体用法?Python WebsocketClient.once怎么用?Python WebsocketClient.once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mycroft.messagebus.client.ws.WebsocketClient
的用法示例。
在下文中一共展示了WebsocketClient.once方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
def main():
global ws
lock = Lock('skills') # prevent multiple instances of this service
# Connect this Skill management process to the websocket
ws = WebsocketClient()
ConfigurationManager.init(ws)
ignore_logs = ConfigurationManager.instance().get("ignore_logs")
# Listen for messages and echo them for logging
def _echo(message):
try:
_message = json.loads(message)
if _message.get("type") in ignore_logs:
return
if _message.get("type") == "registration":
# do not log tokens from registration messages
_message["data"]["token"] = None
message = json.dumps(_message)
except:
pass
logger.debug(message)
ws.on('message', _echo)
# Startup will be called after websocket is full live
ws.once('open', _starting_up)
ws.run_forever()
示例2: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
def main():
global ws
global config
ws = WebsocketClient()
Configuration.init(ws)
config = Configuration.get()
speech.init(ws)
# Setup control of pulse audio
setup_pulseaudio_handlers(config.get('Audio').get('pulseaudio'))
def echo(message):
try:
_message = json.loads(message)
if 'mycroft.audio.service' not in _message.get('type'):
return
message = json.dumps(_message)
except:
pass
LOG.debug(message)
LOG.info("Staring Audio Services")
ws.on('message', echo)
ws.once('open', load_services_callback)
try:
ws.run_forever()
except KeyboardInterrupt, e:
LOG.exception(e)
speech.shutdown()
sys.exit()
示例3: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
def main():
global bus
reset_sigint_handler()
# Create PID file, prevent multiple instancesof this service
mycroft.lock.Lock('skills')
# Connect this Skill management process to the Mycroft Messagebus
bus = WebsocketClient()
Configuration.init(bus)
bus.on('message', create_echo_function('SKILLS'))
# Startup will be called after the connection with the Messagebus is done
bus.once('open', _starting_up)
create_daemon(bus.run_forever)
wait_for_exit_signal()
shutdown()
示例4: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
def main():
global client
client = WebsocketClient()
def echo(message):
try:
_message = json.loads(message)
if _message.get("message_type") == "registration":
# do not log tokens from registration messages
_message["metadata"]["token"] = None
message = json.dumps(_message)
except:
pass
logger.debug(message)
client.on('message', echo)
client.once('open', load_skills_callback)
client.run_forever()
示例5: main
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
def main():
global ws
ws = WebsocketClient()
ConfigurationManager.init(ws)
def echo(message):
try:
_message = json.loads(message)
if _message.get("type") == "registration":
# do not log tokens from registration messages
_message["data"]["token"] = None
message = json.dumps(_message)
except:
pass
logger.debug(message)
ws.on('message', echo)
ws.once('open', load_skills_callback)
ws.run_forever()
示例6: Enclosure
# 需要导入模块: from mycroft.messagebus.client.ws import WebsocketClient [as 别名]
# 或者: from mycroft.messagebus.client.ws.WebsocketClient import once [as 别名]
#.........这里部分代码省略.........
self.mouth.talk)
self.ws.remove('recognizer_loop:audio_output_end',
self.mouth.reset)
def __reset(self, event=None):
# Reset both the mouth and the eye elements to indicate the unit is
# ready for input.
self.writer.write("eyes.reset")
self.writer.write("mouth.reset")
def speak(self, text):
self.ws.emit(Message("speak", {'utterance': text}))
def run(self):
try:
self.ws.run_forever()
except Exception as e:
LOG.error("Error: {0}".format(e))
self.stop()
def check_for_response(self):
if not self.arduino_responded:
# There is nothing on the other end of the serial port
# close these serial-port readers and this process
self.writer.stop()
self.reader.stop()
self.serial.close()
self.ws.close()
def _handle_pairing_complete(self, Message):
"""
Handler for 'mycroft.paired', unmutes the mic after the pairing is
complete.
"""
self.ws.emit(Message("mycroft.mic.unmute"))
def _do_net_check(self):
# TODO: This should live in the derived Enclosure, e.g. Enclosure_Mark1
LOG.info("Checking internet connection")
if not connected(): # and self.conn_monitor is None:
if has_been_paired():
# TODO: Enclosure/localization
self.speak("This unit is not connected to the Internet. "
"Either plug in a network cable or hold the "
"button on top for two seconds, then select "
"wifi from the menu")
else:
# Begin the unit startup process, this is the first time it
# is being run with factory defaults.
# TODO: This logic should be in Enclosure_Mark1
# TODO: Enclosure/localization
# Don't listen to mic during this out-of-box experience
self.ws.emit(Message("mycroft.mic.mute"))
# Setup handler to unmute mic at the end of on boarding
# i.e. after pairing is complete
self.ws.once('mycroft.paired', self._handle_pairing_complete)
self.speak(mycroft.dialog.get('mycroft.intro'))
wait_while_speaking()
time.sleep(2) # a pause sounds better than just jumping in
# Kick off wifi-setup automatically
data = {'allow_timeout': False, 'lang': self.lang}
self.ws.emit(Message('system.wifi.setup', data))
def _hack_check_for_duplicates(self):
# TEMPORARY HACK: Look for multiple instance of the
# mycroft-speech-client and/or mycroft-skills services, which could
# happen when upgrading a shipping Mark 1 from release 0.8.17 or
# before. When found, force the unit to reboot.
import psutil
LOG.info("Hack to check for duplicate service instances")
count_instances = 0
needs_reboot = False
for process in psutil.process_iter():
if process.cmdline() == ['python2.7',
'/usr/local/bin/mycroft-speech-client']:
count_instances += 1
if (count_instances > 1):
LOG.info("Duplicate mycroft-speech-client found")
needs_reboot = True
count_instances = 0
for process in psutil.process_iter():
if process.cmdline() == ['python2.7',
'/usr/local/bin/mycroft-skills']:
count_instances += 1
if (count_instances > 1):
LOG.info("Duplicate mycroft-skills found")
needs_reboot = True
if needs_reboot:
LOG.info("Hack reboot...")
self.reader.process("unit.reboot")
self.ws.emit(Message("enclosure.eyes.spin"))
self.ws.emit(Message("enclosure.mouth.reset"))