Merge pull request #748 from amcgee7/amcgee7_docs
This add comments to document the message classpull/724/head^2
commit
a426b48783
|
@ -16,6 +16,7 @@ install:
|
|||
# command to run tests
|
||||
script:
|
||||
- pep8 mycroft test
|
||||
- ./start.sh unittest --fail-on-error
|
||||
- nose2 test --with-coverage --config=test/unittest.cfg
|
||||
env:
|
||||
- IS_TRAVIS=true
|
||||
|
|
1
msm/msm
1
msm/msm
|
@ -91,6 +91,7 @@ function install() {
|
|||
}
|
||||
|
||||
function update() {
|
||||
cd $mycroft_skill_folder
|
||||
goto_skills_dir
|
||||
for d in $(ls -d */); do
|
||||
if git -C "$d" rev-parse --git-dir > /dev/null 2>&1; then
|
||||
|
|
|
@ -148,6 +148,7 @@ class EnclosureReader(Thread):
|
|||
self.ws.emit(Message("mycroft.disable.ssh"))
|
||||
self.ws.emit(Message("speak", {
|
||||
'utterance': mycroft.dialog.get("reset to factory defaults")}))
|
||||
time.sleep(5)
|
||||
wait_while_speaking()
|
||||
self.ws.emit(Message("enclosure.mouth.reset"))
|
||||
self.ws.emit(Message("enclosure.eyes.spin"))
|
||||
|
|
|
@ -149,6 +149,8 @@ class AudioConsumer(Thread):
|
|||
LOG.error("Could not request Speech Recognition {0}".format(e))
|
||||
except ConnectionError as e:
|
||||
LOG.error("Connection Error: {0}".format(e))
|
||||
self.__speak(mycroft.dialog.get("not connected to the internet",
|
||||
self.stt.lang))
|
||||
self.emitter.emit("recognizer_loop:no_internet")
|
||||
except HTTPError as e:
|
||||
if e.response.status_code == 401:
|
||||
|
|
|
@ -157,6 +157,8 @@ def handle_mic_unmute(event):
|
|||
def handle_stop(event):
|
||||
global _last_stop_signal
|
||||
_last_stop_signal = time.time()
|
||||
kill([config.get('tts').get('module')])
|
||||
kill(["aplay"])
|
||||
stop_speaking()
|
||||
|
||||
|
||||
|
|
|
@ -274,10 +274,9 @@ class WiFi:
|
|||
# item being selected.
|
||||
self.ws.on('mycroft.wifi.start', self.start)
|
||||
|
||||
# Similar to the above. Resets to factory defaults
|
||||
# This event is similar to the above, but resets the wifi
|
||||
self.ws.on('mycroft.wifi.reset', self.reset)
|
||||
|
||||
# Similar to the above. Enable/disable SSH
|
||||
# an event to enable SSH
|
||||
self.ws.on('mycroft.enable.ssh', self.ssh_enable)
|
||||
self.ws.on('mycroft.disable.ssh', self.ssh_disable)
|
||||
|
||||
|
@ -553,7 +552,7 @@ class WiFi:
|
|||
self.stop()
|
||||
|
||||
def reset(self, event=None):
|
||||
"""Reset the unit to the factory defaults """
|
||||
"""Resets the wifi to the default """
|
||||
LOG.info("Resetting the WPA_SUPPLICANT File")
|
||||
try:
|
||||
call(
|
||||
|
|
|
@ -22,12 +22,31 @@ __author__ = 'seanfitz'
|
|||
|
||||
|
||||
class Message(object):
|
||||
"""This class is used to minipulate data to be sent over the websocket
|
||||
|
||||
Message objects will be used to send information back and fourth
|
||||
between processes of mycroft service, voice, skill and cli
|
||||
|
||||
Attributes:
|
||||
type: type of data sent within the message.
|
||||
data: data sent within the message
|
||||
context: info about the message not part of data such as source,
|
||||
destination or domain.
|
||||
"""
|
||||
def __init__(self, type, data={}, context=None):
|
||||
self.type = type
|
||||
self.data = data
|
||||
self.context = context
|
||||
|
||||
def serialize(self):
|
||||
"""This returns a string of the message info.
|
||||
|
||||
This makes it easy to send over a websocket. This uses
|
||||
json dumps to generate the string with type, data and context
|
||||
|
||||
Returns:
|
||||
str: a json string representation of the message.
|
||||
"""
|
||||
return json.dumps({
|
||||
'type': self.type,
|
||||
'data': self.data,
|
||||
|
@ -36,10 +55,42 @@ class Message(object):
|
|||
|
||||
@staticmethod
|
||||
def deserialize(value):
|
||||
"""This takes a string and constructs a message object.
|
||||
|
||||
This makes it easy to take strings from the websocket and create
|
||||
a message object. This uses json loads to get the info and generate
|
||||
the message object.
|
||||
|
||||
Args:
|
||||
value(str): This is the json string received from the websocket
|
||||
|
||||
Returns:
|
||||
Message: message object constructed from the json string passed
|
||||
int the function.
|
||||
"""
|
||||
obj = json.loads(value)
|
||||
return Message(obj.get('type'), obj.get('data'), obj.get('context'))
|
||||
|
||||
def reply(self, type, data, context={}):
|
||||
"""This is used to construct a reply message for a give message
|
||||
|
||||
This will take the same parameters as a message object but use
|
||||
the current message object as a refrence. It will copy the context
|
||||
form the existing message object and add any context passed in to
|
||||
the function. Check for a target passed in to the function from
|
||||
the data object and add that to the context as a target. If the
|
||||
context has a client name then that will become the target in the
|
||||
context. The new message will then have data passed in plus the
|
||||
new context generated.
|
||||
|
||||
Args:
|
||||
type: type of message
|
||||
data: data for message
|
||||
context: intented context for new message
|
||||
|
||||
Returns:
|
||||
Message: Message object to be used on the reply to the message
|
||||
"""
|
||||
new_context = self.context if self.context else {}
|
||||
for key in context:
|
||||
new_context[key] = context[key]
|
||||
|
@ -50,6 +101,20 @@ class Message(object):
|
|||
return Message(type, data, context=new_context)
|
||||
|
||||
def publish(self, type, data, context={}):
|
||||
"""
|
||||
|
||||
Copy the original context and add passed in context. Delete
|
||||
any target in the new context. Return a new message object with
|
||||
passed in data and new context. Type remains unchanged.
|
||||
|
||||
Args:
|
||||
type: type of message
|
||||
data: date to send with message
|
||||
context: context added to existing context
|
||||
|
||||
Returns:
|
||||
Message: Message object to publish
|
||||
"""
|
||||
new_context = self.context.copy() if self.context else {}
|
||||
for key in context:
|
||||
new_context[key] = context[key]
|
||||
|
|
|
@ -25,6 +25,10 @@ from mycroft.messagebus.client.ws import WebsocketClient
|
|||
from mycroft.skills.core import create_skill_descriptor, load_skill
|
||||
from mycroft.skills.intent_service import IntentService
|
||||
from mycroft.util.log import getLogger
|
||||
import signal
|
||||
|
||||
# ignore DIGCHLD to terminate subprocesses correctly
|
||||
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
||||
|
||||
__author__ = 'seanfitz'
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
@ -37,6 +38,9 @@ from mycroft.util.log import getLogger
|
|||
from mycroft.api import is_paired
|
||||
import mycroft.dialog
|
||||
|
||||
# ignore DIGCHLD to terminate subprocesses correctly
|
||||
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
||||
|
||||
logger = getLogger("Skills")
|
||||
|
||||
__author__ = 'seanfitz'
|
||||
|
|
Loading…
Reference in New Issue