Skip to content

Commit

Permalink
mycroft-bus-client -> ovos-bus-client (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Apr 11, 2023
1 parent 9a0242d commit b1a9d39
Show file tree
Hide file tree
Showing 63 changed files with 100 additions and 449 deletions.
8 changes: 3 additions & 5 deletions mycroft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
#
from os.path import abspath, dirname, join
from ovos_config.config import Configuration
from mycroft.api import Api # TODO - why is this here? nothing should be using it, can it be removed safely?
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message

from ovos_utils.intents import AdaptIntent, IntentBuilder, Intent
from mycroft.skills.context import adds_context, removes_context
from mycroft.skills import (MycroftSkill, FallbackSkill,
intent_handler, intent_file_handler)
from ovos_utils.log import LOG


MYCROFT_ROOT_PATH = abspath(join(dirname(__file__), '..'))

__all__ = ['MYCROFT_ROOT_PATH',
'Api',
'Message']
__all__ = ['MYCROFT_ROOT_PATH']

_cfg = Configuration()
_log_level = _cfg.get("log_level", "INFO")
Expand Down
2 changes: 1 addition & 1 deletion mycroft/audio/audioservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from mycroft.audio.services import RemoteAudioBackend
from ovos_config.config import Configuration
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from ovos_utils.process_utils import MonotonicEvent
from mycroft.util.plugins import find_plugins
Expand Down
2 changes: 1 addition & 1 deletion mycroft/audio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from os.path import abspath
from datetime import timedelta

from mycroft.messagebus.message import Message, dig_for_message
from ovos_bus_client.message import Message, dig_for_message


def ensure_uri(s):
Expand Down
2 changes: 1 addition & 1 deletion mycroft/audio/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from threading import Thread, Lock
from os.path import exists, expanduser
from mycroft_bus_client import Message
from ovos_bus_client import Message

from mycroft.audio.tts import TTSFactory, TTS
from ovos_config.config import Configuration
Expand Down
2 changes: 1 addition & 1 deletion mycroft/audio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def stop_speaking():
TODO: Skills should only be able to stop speech they've initiated
"""
if is_speaking():
from mycroft.messagebus.send import send
from ovos_bus_client.send_func import send
send('mycroft.audio.speech.stop')

# Block until stopped
Expand Down
2 changes: 1 addition & 1 deletion mycroft/deprecated/audio/services/simple/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from time import sleep

from mycroft.audio.services import AudioBackend
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from mycroft.util import play_mp3, play_ogg, play_wav
import mimetypes
Expand Down
2 changes: 1 addition & 1 deletion mycroft/deprecated/audio/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

from threading import Lock
from mycroft_bus_client import MessageBusClient, Message
from ovos_bus_client import MessageBusClient, Message
from ovos_utils.log import LOG

bus: MessageBusClient = None
Expand Down
2 changes: 1 addition & 1 deletion mycroft/deprecated/enclosure/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

from ovos_config.config import Configuration
from mycroft.messagebus.client import MessageBusClient
from ovos_bus_client.client import MessageBusClient
from mycroft.util import start_message_bus_client


Expand Down
2 changes: 1 addition & 1 deletion mycroft/deprecated/enclosure/mark1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from mycroft.deprecated.enclosure.mark1.mouth import EnclosureMouth
from ovos_config.config import LocalConf
from ovos_config.locations import USER_CONFIG
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from mycroft.util import play_wav, connected
from ovos_utils.signal import check_for_signal, create_signal
from mycroft.util.audio_test import record
Expand Down
2 changes: 1 addition & 1 deletion mycroft/deprecated/skills/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from ovos_backend_client.pairing import is_paired
from ovos_backend_client.api import DeviceApi
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from mycroft.util.file_utils import ensure_directory_exists
from ovos_utils.log import LOG
from ovos_config.config import Configuration
Expand Down
2 changes: 1 addition & 1 deletion mycroft/enclosure/display_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

import os

from mycroft.messagebus.client import MessageBusClient
from ovos_bus_client.client import MessageBusClient
from ovos_utils import get_ipc_directory
from ovos_utils.log import LOG

Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from tornado.websocket import WebSocketHandler

from ovos_config.config import Configuration
from mycroft.messagebus import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from ovos_utils import create_daemon

Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mycroft.gui.homescreen import HomescreenManager
from mycroft.gui.interfaces.mobile import MobileExtensionGuiInterface
from mycroft.gui.interfaces.smartspeaker import SmartSpeakerExtensionGuiInterface
from mycroft.messagebus import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from ovos_backend_client.pairing import is_paired

Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/homescreen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mycroft.messagebus import Message
from ovos_bus_client.message import Message
from ovos_config.config import Configuration, LocalConf
from ovos_config.locations import USER_CONFIG
from ovos_utils.log import LOG
Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/interfaces/smartspeaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os.path import exists, join

from json_database import JsonStorage
from mycroft.messagebus import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG
from mycroft.version import OVOS_VERSION_STR
from ovos_utils import network_utils
Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from typing import List, Union

from ovos_config.config import Configuration
from mycroft.messagebus import Message, MessageBusClient
from ovos_bus_client import Message, MessageBusClient
from ovos_utils.log import LOG
from mycroft.gui.bus import (
create_gui_service,
Expand Down
2 changes: 1 addition & 1 deletion mycroft/gui/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mycroft.messagebus.client import MessageBusClient
from ovos_bus_client.client import MessageBusClient
from mycroft.util import start_message_bus_client
from ovos_utils.log import LOG
from mycroft.gui.namespace import NamespaceManager
Expand Down
2 changes: 1 addition & 1 deletion mycroft/listener/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ovos_config.config import Configuration
from mycroft.enclosure.api import EnclosureAPI
from ovos_backend_client.identity import IdentityManager
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from mycroft.util import (
start_message_bus_client
)
Expand Down
6 changes: 3 additions & 3 deletions mycroft/messagebus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mycroft.messagebus.client.client import MessageBusClient
from mycroft.messagebus.message import Message
from mycroft.messagebus.send_func import send
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_bus_client.send_func import send

try:
from mycroft.messagebus.service.event_handler import MessageBusEventHandler
Expand Down
4 changes: 2 additions & 2 deletions mycroft/messagebus/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""TODO: 21.08 simplify structure (move client.py up one level)."""
from mycroft.messagebus.client.client import MessageBusClient
from mycroft_bus_client.client import MessageWaiter
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.client import MessageWaiter
21 changes: 3 additions & 18 deletions mycroft/messagebus/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,13 @@
# limitations under the License.
#

from mycroft_bus_client import MessageBusClient as _MessageBusClient
from mycroft_bus_client.client import MessageWaiter
from ovos_bus_client import MessageBusClient
from ovos_bus_client.client import MessageWaiter

from mycroft.messagebus.load_config import load_message_bus_config
from ovos_bus_client.conf import load_message_bus_config
import mycroft.util.process_utils


class MessageBusClient(_MessageBusClient):
# minimize reading of the .conf
_config_cache = None

def __init__(self, host=None, port=None, route=None, ssl=None, cache=False):
config_overrides = dict(host=host, port=port, route=route, ssl=ssl)
if cache and self._config_cache:
config = self._config_cache
else:
config = load_message_bus_config(**config_overrides)
if cache:
MessageBusClient._config_cache = config
super().__init__(config.host, config.port, config.route, config.ssl)


def echo():
message_bus_client = MessageBusClient()

Expand Down
35 changes: 1 addition & 34 deletions mycroft/messagebus/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,4 @@
The message bus event handler and client use basically the same configuration.
This code is re-used in both to load config values.
"""
from collections import namedtuple

from ovos_config.config import Configuration
from ovos_utils.log import LOG

MessageBusConfig = namedtuple(
'MessageBusConfig',
['host', 'port', 'route', 'ssl']
)


def load_message_bus_config(**overrides):
"""Load the bits of device configuration needed to run the message bus."""
LOG.info('Loading message bus configs')
config = Configuration()

try:
websocket_configs = config['websocket']
except KeyError as ke:
LOG.error('No websocket configs found ({})'.format(repr(ke)))
raise
else:
mb_config = MessageBusConfig(
host=overrides.get('host') or websocket_configs.get('host'),
port=overrides.get('port') or websocket_configs.get('port'),
route=overrides.get('route') or websocket_configs.get('route'),
ssl=overrides.get('ssl') or config.get('ssl')
)
if not all([mb_config.host, mb_config.port, mb_config.route]):
error_msg = 'Missing one or more websocket configs'
LOG.error(error_msg)
raise ValueError(error_msg)

return mb_config
from ovos_bus_client.conf import MessageBusConfig, load_message_bus_config
28 changes: 1 addition & 27 deletions mycroft/messagebus/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import re

from mycroft.util.parse import normalize
from mycroft_bus_client.message import dig_for_message
import mycroft_bus_client


class Message(mycroft_bus_client.Message):
"""Mycroft specific Message class."""

def utterance_remainder(self):
"""
For intents get the portion not consumed by Adapt.
For example: if they say 'Turn on the family room light' and there are
entity matches for "turn on" and "light", then it will leave behind
" the family room " which is then normalized to "family room".
Returns:
str: Leftover words or None if not an utterance.
"""
utt = normalize(self.data.get("utterance", ""))
if utt and "__tags__" in self.data:
for token in self.data["__tags__"]:
# Substitute only whole words matching the token
utt = re.sub(r'\b' + token.get("key", "") + r"\b", "", utt)
return normalize(utt)
from ovos_bus_client.message import dig_for_message, Message
2 changes: 1 addition & 1 deletion mycroft/messagebus/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import sys
import json

from mycroft.messagebus.send_func import send
from ovos_bus_client.send_func import send


def main():
Expand Down
30 changes: 3 additions & 27 deletions mycroft/messagebus/send_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,8 @@
from websocket import create_connection

from ovos_config.config import Configuration
from mycroft.messagebus.client import MessageBusClient
from mycroft.messagebus.message import Message
from ovos_bus_client.client import MessageBusClient
from ovos_bus_client.message import Message
from ovos_bus_client.send_func import send


def send(message_to_send, data_to_send=None):
"""Send a single message over the websocket.
Args:
message_to_send (str): Message to send
data_to_send (dict): data structure to go along with the
message, defaults to empty dict.
"""
data_to_send = data_to_send or {}

# Calculate the standard Mycroft messagebus websocket address
config = Configuration()
config = config.get("websocket")
url = MessageBusClient.build_url(
config.get("host"),
config.get("port"),
config.get("route"),
config.get("ssl")
)

# Send the provided message/data
ws = create_connection(url)
packet = Message(message_to_send, data_to_send).serialize()
ws.send(packet)
ws.close()
2 changes: 1 addition & 1 deletion mycroft/messagebus/service/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
processes. It implements a websocket server so can also be used by external
systems to integrate with the Mycroft system.
"""
from mycroft.messagebus.load_config import load_message_bus_config
from ovos_bus_client.conf import load_message_bus_config
from mycroft.messagebus.service.event_handler import MessageBusEventHandler

from ovos_utils.process_utils import reset_sigint_handler
Expand Down
2 changes: 1 addition & 1 deletion mycroft/messagebus/service/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from tornado.websocket import WebSocketHandler
from pyee import EventEmitter

from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from ovos_utils.log import LOG

client_connections = []
Expand Down
2 changes: 1 addition & 1 deletion mycroft/skills/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ovos_config.locale import setup_locale
from mycroft.skills.api import SkillApi
from mycroft.skills.core import FallbackSkill
from mycroft.skills.event_scheduler import EventScheduler
from ovos_bus_client.util.scheduler import EventScheduler
from mycroft.skills.intent_service import IntentService
from mycroft.skills.skill_manager import SkillManager, on_error, on_stopping, on_ready, on_alive, on_started
from mycroft.util import start_message_bus_client
Expand Down
2 changes: 1 addition & 1 deletion mycroft/skills/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
The skill api allows skills interact with eachother over the message bus
just like interacting with any other object.
"""
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message


class SkillApi():
Expand Down
2 changes: 1 addition & 1 deletion mycroft/skills/common_iot_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from itertools import count

from mycroft.skills.mycroft_skill import MycroftSkill
from mycroft.messagebus.message import Message, dig_for_message
from ovos_bus_client.message import Message, dig_for_message

ENTITY = "ENTITY"
SCENE = "SCENE"
Expand Down
2 changes: 1 addition & 1 deletion mycroft/skills/common_play_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import re
from enum import Enum, IntEnum
from abc import ABC, abstractmethod
from mycroft.messagebus.message import Message
from ovos_bus_client.message import Message
from mycroft.skills.mycroft_skill import MycroftSkill
from mycroft.skills.audioservice import AudioService

Expand Down
Loading

0 comments on commit b1a9d39

Please sign in to comment.