diff --git a/mycroft/__init__.py b/mycroft/__init__.py index acba657fada8..779c86fc517d 100644 --- a/mycroft/__init__.py +++ b/mycroft/__init__.py @@ -14,8 +14,7 @@ # 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 @@ -23,11 +22,10 @@ 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") diff --git a/mycroft/audio/audioservice.py b/mycroft/audio/audioservice.py index b9c6c1395f5c..14019b4a4d2a 100644 --- a/mycroft/audio/audioservice.py +++ b/mycroft/audio/audioservice.py @@ -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 diff --git a/mycroft/audio/interface.py b/mycroft/audio/interface.py index b12525b42ccf..afd2d1a1a06b 100644 --- a/mycroft/audio/interface.py +++ b/mycroft/audio/interface.py @@ -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): diff --git a/mycroft/audio/service.py b/mycroft/audio/service.py index dc769bfba004..a9c43c574cd0 100644 --- a/mycroft/audio/service.py +++ b/mycroft/audio/service.py @@ -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 diff --git a/mycroft/audio/utils.py b/mycroft/audio/utils.py index 7f8840e07acf..f37203c2842b 100644 --- a/mycroft/audio/utils.py +++ b/mycroft/audio/utils.py @@ -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 diff --git a/mycroft/deprecated/audio/services/simple/__init__.py b/mycroft/deprecated/audio/services/simple/__init__.py index 0b73f5ac0990..d3d7f0126728 100644 --- a/mycroft/deprecated/audio/services/simple/__init__.py +++ b/mycroft/deprecated/audio/services/simple/__init__.py @@ -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 diff --git a/mycroft/deprecated/audio/speech.py b/mycroft/deprecated/audio/speech.py index d5808281c532..68a5ef2ef02f 100644 --- a/mycroft/deprecated/audio/speech.py +++ b/mycroft/deprecated/audio/speech.py @@ -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 diff --git a/mycroft/deprecated/enclosure/base.py b/mycroft/deprecated/enclosure/base.py index 5dd9721792f3..40ab28ab923d 100644 --- a/mycroft/deprecated/enclosure/base.py +++ b/mycroft/deprecated/enclosure/base.py @@ -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 diff --git a/mycroft/deprecated/enclosure/mark1/__init__.py b/mycroft/deprecated/enclosure/mark1/__init__.py index 37282b885661..5dde6cdaf96d 100644 --- a/mycroft/deprecated/enclosure/mark1/__init__.py +++ b/mycroft/deprecated/enclosure/mark1/__init__.py @@ -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 diff --git a/mycroft/deprecated/skills/settings.py b/mycroft/deprecated/skills/settings.py index 418cf7a3adb0..2e402ab07f4b 100644 --- a/mycroft/deprecated/skills/settings.py +++ b/mycroft/deprecated/skills/settings.py @@ -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 diff --git a/mycroft/enclosure/display_manager.py b/mycroft/enclosure/display_manager.py index 1bd424e47b57..2bf44d6165de 100644 --- a/mycroft/enclosure/display_manager.py +++ b/mycroft/enclosure/display_manager.py @@ -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 diff --git a/mycroft/gui/bus.py b/mycroft/gui/bus.py index 89c38cd9ef6b..9c4bca0d9df5 100644 --- a/mycroft/gui/bus.py +++ b/mycroft/gui/bus.py @@ -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 diff --git a/mycroft/gui/extensions.py b/mycroft/gui/extensions.py index fe6f0262bf47..93248501036c 100644 --- a/mycroft/gui/extensions.py +++ b/mycroft/gui/extensions.py @@ -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 diff --git a/mycroft/gui/homescreen.py b/mycroft/gui/homescreen.py index 72ffa7d4acd0..3970b4c7e454 100644 --- a/mycroft/gui/homescreen.py +++ b/mycroft/gui/homescreen.py @@ -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 diff --git a/mycroft/gui/interfaces/smartspeaker.py b/mycroft/gui/interfaces/smartspeaker.py index 0cb83c162074..7c84dee08814 100644 --- a/mycroft/gui/interfaces/smartspeaker.py +++ b/mycroft/gui/interfaces/smartspeaker.py @@ -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 diff --git a/mycroft/gui/namespace.py b/mycroft/gui/namespace.py index 96d47f635237..8a1e9e2a4e7c 100644 --- a/mycroft/gui/namespace.py +++ b/mycroft/gui/namespace.py @@ -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, diff --git a/mycroft/gui/service.py b/mycroft/gui/service.py index 491521384027..1d65c094c707 100644 --- a/mycroft/gui/service.py +++ b/mycroft/gui/service.py @@ -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 diff --git a/mycroft/listener/service.py b/mycroft/listener/service.py index 94f55cbd352c..6ac7dad7c2fa 100644 --- a/mycroft/listener/service.py +++ b/mycroft/listener/service.py @@ -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 ) diff --git a/mycroft/messagebus/__init__.py b/mycroft/messagebus/__init__.py index 5f5ba83b4ea5..03284a4e4dc0 100644 --- a/mycroft/messagebus/__init__.py +++ b/mycroft/messagebus/__init__.py @@ -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 diff --git a/mycroft/messagebus/client/__init__.py b/mycroft/messagebus/client/__init__.py index 0262da399b56..5dbc1c6b59a6 100644 --- a/mycroft/messagebus/client/__init__.py +++ b/mycroft/messagebus/client/__init__.py @@ -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 diff --git a/mycroft/messagebus/client/client.py b/mycroft/messagebus/client/client.py index bda99f2743cf..1655765b3681 100644 --- a/mycroft/messagebus/client/client.py +++ b/mycroft/messagebus/client/client.py @@ -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() diff --git a/mycroft/messagebus/load_config.py b/mycroft/messagebus/load_config.py index eb6e5baf05c0..ad64a419631d 100644 --- a/mycroft/messagebus/load_config.py +++ b/mycroft/messagebus/load_config.py @@ -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 diff --git a/mycroft/messagebus/message.py b/mycroft/messagebus/message.py index f023f8a983e2..e44fa61b3873 100644 --- a/mycroft/messagebus/message.py +++ b/mycroft/messagebus/message.py @@ -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 diff --git a/mycroft/messagebus/send.py b/mycroft/messagebus/send.py index 1a250e3cfa28..4ee0cda70b6f 100644 --- a/mycroft/messagebus/send.py +++ b/mycroft/messagebus/send.py @@ -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(): diff --git a/mycroft/messagebus/send_func.py b/mycroft/messagebus/send_func.py index abc263138078..a89c69de4766 100644 --- a/mycroft/messagebus/send_func.py +++ b/mycroft/messagebus/send_func.py @@ -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() diff --git a/mycroft/messagebus/service/__main__.py b/mycroft/messagebus/service/__main__.py index dacae90eb88b..622e142eb686 100644 --- a/mycroft/messagebus/service/__main__.py +++ b/mycroft/messagebus/service/__main__.py @@ -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 diff --git a/mycroft/messagebus/service/event_handler.py b/mycroft/messagebus/service/event_handler.py index 02d297340af9..2287e334776a 100644 --- a/mycroft/messagebus/service/event_handler.py +++ b/mycroft/messagebus/service/event_handler.py @@ -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 = [] diff --git a/mycroft/skills/__main__.py b/mycroft/skills/__main__.py index 4d379d86944f..0e50398d6b71 100644 --- a/mycroft/skills/__main__.py +++ b/mycroft/skills/__main__.py @@ -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 diff --git a/mycroft/skills/api.py b/mycroft/skills/api.py index 3546ee6944e4..a0d1ed7a44eb 100644 --- a/mycroft/skills/api.py +++ b/mycroft/skills/api.py @@ -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(): diff --git a/mycroft/skills/common_iot_skill.py b/mycroft/skills/common_iot_skill.py index 8b4625afbb19..54769fc0e76d 100644 --- a/mycroft/skills/common_iot_skill.py +++ b/mycroft/skills/common_iot_skill.py @@ -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" diff --git a/mycroft/skills/common_play_skill.py b/mycroft/skills/common_play_skill.py index f75e2ca7b678..eecc5c66404e 100644 --- a/mycroft/skills/common_play_skill.py +++ b/mycroft/skills/common_play_skill.py @@ -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 diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py index 8c6c3e2018d3..3acf993246f1 100644 --- a/mycroft/skills/event_scheduler.py +++ b/mycroft/skills/event_scheduler.py @@ -15,258 +15,7 @@ """Event scheduler system for calling skill (and other) methods at a specific times. """ -import json -import shutil -import time -from datetime import datetime, timedelta -from threading import Thread, Lock -from os.path import isfile, join, expanduser - -from ovos_config.config import Configuration -from ovos_config.locations import get_xdg_data_save_path, get_xdg_config_save_path -from mycroft.messagebus.message import Message -from ovos_utils.log import LOG -from ovos_utils.events import create_basic_wrapper, EventContainer, EventSchedulerInterface - - -def repeat_time(sched_time, repeat): - """Next scheduled time for repeating event. Guarantees that the - time is not in the past (but could skip interim events) - - Args: - sched_time (float): Scheduled unix time for the event - repeat (float): Repeat period in seconds - - Returns: (float) time for next event - """ - next_time = sched_time + repeat - while next_time < time.time(): - # Schedule at an offset to assure no doubles - next_time = time.time() + abs(repeat) - return next_time - - -class EventScheduler(Thread): - """Create an event scheduler thread. Will send messages at a - predetermined time to the registered targets. - - Args: - bus: Mycroft messagebus (mycroft.messagebus) - schedule_file: File to store pending events to on shutdown - """ - - def __init__(self, bus, schedule_file='schedule.json', autostart=True): - super().__init__() - - self.events = {} - self.event_lock = Lock() - - self.bus = bus - self.is_running = True - - core_conf = Configuration() - data_dir = core_conf.get('data_dir') or get_xdg_data_save_path() - old_schedule_path = join(expanduser(data_dir), schedule_file) - - self.schedule_file = join(get_xdg_config_save_path(), schedule_file) - if isfile(old_schedule_path): - shutil.move(old_schedule_path, self.schedule_file) - - if self.schedule_file: - self.load() - - self.bus.on('mycroft.scheduler.schedule_event', - self.schedule_event_handler) - self.bus.on('mycroft.scheduler.remove_event', - self.remove_event_handler) - self.bus.on('mycroft.scheduler.update_event', - self.update_event_handler) - self.bus.on('mycroft.scheduler.get_event', - self.get_event_handler) - if autostart: - self.start() - - def load(self): - """Load json data with active events from json file.""" - if isfile(self.schedule_file): - json_data = {} - with open(self.schedule_file) as f: - try: - json_data = json.load(f) - except Exception as e: - LOG.error(e) - current_time = time.time() - with self.event_lock: - for key in json_data: - event_list = json_data[key] - # discard non repeating events that has already happened - self.events[key] = [tuple(e) for e in event_list - if e[0] > current_time or e[1]] - - def run(self): - while self.is_running: - self.check_state() - time.sleep(0.5) - - def check_state(self): - """Check if an event should be triggered.""" - with self.event_lock: - # Check all events - pending_messages = [] - for event in self.events: - current_time = time.time() - e = self.events[event] - # Get scheduled times that has passed - passed = [(t, r, d, c) for - (t, r, d, c) in e if t <= current_time] - # and remaining times that we're still waiting for - remaining = [(t, r, d, c) for - t, r, d, c in e if t > current_time] - # Trigger registered methods - for sched_time, repeat, data, context in passed: - pending_messages.append(Message(event, data, context)) - # if this is a repeated event add a new trigger time - if repeat: - next_time = repeat_time(sched_time, repeat) - remaining.append((next_time, repeat, data, context)) - # update list of events - self.events[event] = remaining - - # Remove events have are now completed - self.clear_empty() - - # Finally, emit the queued up events that triggered - for msg in pending_messages: - self.bus.emit(msg) - - def schedule_event(self, event, sched_time, repeat=None, - data=None, context=None): - """Add event to pending event schedule. - - Args: - event (str): Handler for the event - sched_time ([type]): [description] - repeat ([type], optional): Defaults to None. [description] - data ([type], optional): Defaults to None. [description] - context (dict, optional): context (dict, optional): message - context to send when the - handler is called - """ - data = data or {} - with self.event_lock: - # get current list of scheduled times for event, [] if missing - event_list = self.events.get(event, []) - - # Don't schedule if the event is repeating and already scheduled - if repeat and event in self.events: - LOG.debug(f'Repeating event {event} is already scheduled, discarding') - else: - # add received event and time - event_list.append((sched_time, repeat, data, context)) - self.events[event] = event_list - - def schedule_event_handler(self, message): - """Messagebus interface to the schedule_event method. - Required data in the message envelope is - event: event to emit - time: time to emit the event - - Optional data is - repeat: repeat interval - data: data to send along with the event - """ - event = message.data.get('event') - sched_time = message.data.get('time') - repeat = message.data.get('repeat') - data = message.data.get('data') - context = message.context - if event and sched_time: - self.schedule_event(event, sched_time, repeat, data, context) - elif not event: - LOG.error('Scheduled event name not provided') - else: - LOG.error('Scheduled event time not provided') - - def remove_event(self, event): - """Remove an event from the list of scheduled events. - - Args: - event (str): event identifier - """ - with self.event_lock: - if event in self.events: - self.events.pop(event) - - def remove_event_handler(self, message): - """Messagebus interface to the remove_event method.""" - event = message.data.get('event') - self.remove_event(event) - - def update_event(self, event, data): - """Change an existing events data. - - This will only update the first call if multiple calls are registered - to the same event identifier. - - Args: - event (str): event identifier - data (dict): new data - """ - with self.event_lock: - # if there is an active event with this name - if len(self.events.get(event, [])) > 0: - time, repeat, _, context = self.events[event][0] - self.events[event][0] = (time, repeat, data, context) - - def update_event_handler(self, message): - """Messagebus interface to the update_event method.""" - event = message.data.get('event') - data = message.data.get('data') - self.update_event(event, data) - - def get_event_handler(self, message): - """Messagebus interface to get_event. - - Emits another event sending event status. - """ - event_name = message.data.get("name") - event = None - with self.event_lock: - if event_name in self.events: - event = self.events[event_name] - emitter_name = f'mycroft.event_status.callback.{event_name}' - self.bus.emit(message.reply(emitter_name, data=event)) - - def store(self): - """Write current schedule to disk.""" - with self.event_lock: - with open(self.schedule_file, 'w') as f: - json.dump(self.events, f) - - def clear_repeating(self): - """Remove repeating events from events dict.""" - with self.event_lock: - for e in self.events: - self.events[e] = [i for i in self.events[e] if i[1] is None] - - def clear_empty(self): - """Remove empty event entries from events dict.""" - with self.event_lock: - self.events = {k: self.events[k] for k in self.events - if self.events[k] != []} - - def shutdown(self): - """Stop the running thread.""" - self.is_running = False - # Remove listeners - self.bus.remove_all_listeners('mycroft.scheduler.schedule_event') - self.bus.remove_all_listeners('mycroft.scheduler.remove_event') - self.bus.remove_all_listeners('mycroft.scheduler.update_event') - # Wait for thread to finish - self.join() - # Prune event list in preparation for saving - self.clear_repeating() - self.clear_empty() - # Store all pending scheduled events - self.store() +# backwards compat - do not delete until 0.2.0 +from ovos_bus_client.util.scheduler import repeat_time, EventScheduler, create_basic_wrapper, \ + EventContainer, EventSchedulerInterface diff --git a/mycroft/skills/intent_service.py b/mycroft/skills/intent_service.py index 81998887643b..7ebbe2c1ee32 100644 --- a/mycroft/skills/intent_service.py +++ b/mycroft/skills/intent_service.py @@ -15,7 +15,7 @@ """Mycroft's intent service, providing intent parsing since forever!""" from ovos_config.config import Configuration from ovos_config.locale import setup_locale -from mycroft.messagebus.message import Message, dig_for_message +from ovos_bus_client.message import Message, dig_for_message from mycroft.metrics import report_timing, Stopwatch from mycroft.skills.intent_service_interface import open_intent_envelope from mycroft.skills.intent_services import ( diff --git a/mycroft/skills/intent_services/commonqa_service.py b/mycroft/skills/intent_services/commonqa_service.py index 3b0dd13d7362..7bd87d788eb7 100644 --- a/mycroft/skills/intent_services/commonqa_service.py +++ b/mycroft/skills/intent_services/commonqa_service.py @@ -3,7 +3,7 @@ from itertools import chain from threading import Lock, Event -from mycroft_bus_client.message import Message, dig_for_message +from ovos_bus_client.message import Message, dig_for_message from mycroft.skills.intent_services.base import IntentMatch from mycroft.skills.skill_data import CoreResources diff --git a/mycroft/skills/intent_services/converse_service.py b/mycroft/skills/intent_services/converse_service.py index 4643ab8ffa6d..133738ccca95 100644 --- a/mycroft/skills/intent_services/converse_service.py +++ b/mycroft/skills/intent_services/converse_service.py @@ -1,7 +1,7 @@ import time from ovos_config.config import Configuration -from mycroft.messagebus.message import Message +from ovos_bus_client.message import Message from mycroft.skills.intent_services import ( IntentMatch ) diff --git a/mycroft/skills/intent_services/padatious_service.py b/mycroft/skills/intent_services/padatious_service.py index d6f7edaa7590..05b247de573f 100644 --- a/mycroft/skills/intent_services/padatious_service.py +++ b/mycroft/skills/intent_services/padatious_service.py @@ -21,7 +21,7 @@ from os.path import expanduser, isfile 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 mycroft.skills.intent_services.base import IntentMatch diff --git a/mycroft/skills/mycroft_skill/mycroft_skill.py b/mycroft/skills/mycroft_skill/mycroft_skill.py index 02ec92a5e690..67b711914420 100644 --- a/mycroft/skills/mycroft_skill/mycroft_skill.py +++ b/mycroft/skills/mycroft_skill/mycroft_skill.py @@ -18,9 +18,9 @@ from ovos_utils.intents import Intent, IntentBuilder from ovos_utils.skills import get_non_properties from mycroft.gui import SkillGUI -from mycroft.messagebus.message import Message, dig_for_message +from ovos_bus_client.message import Message, dig_for_message from mycroft.metrics import report_metric -from mycroft.skills.event_scheduler import EventSchedulerInterface +from ovos_bus_client.util.scheduler import EventScheduler, EventSchedulerInterface from mycroft.skills.intent_service_interface import IntentServiceInterface from ovos_utils.messagebus import get_handler_name, create_wrapper, EventContainer from ovos_utils.enclosure.api import EnclosureAPI diff --git a/mycroft/skills/settings.py b/mycroft/skills/settings.py index 95b860a3ef82..f695d2cdbfc0 100644 --- a/mycroft/skills/settings.py +++ b/mycroft/skills/settings.py @@ -64,7 +64,7 @@ from ovos_backend_client.pairing import is_paired, requires_backend from ovos_utils.log import LOG from ovos_backend_client.settings import RemoteSkillSettings, get_display_name -from mycroft_bus_client.message import Message, dig_for_message +from ovos_bus_client.message import Message, dig_for_message # backwards compat imports from mycroft.deprecated.skills.settings import SkillSettingsDownloader, SettingsMetaUploader, load_remote_settings_cache, \ diff --git a/mycroft/skills/skill_loader.py b/mycroft/skills/skill_loader.py index f37544fb283b..8e82fce4e38d 100644 --- a/mycroft/skills/skill_loader.py +++ b/mycroft/skills/skill_loader.py @@ -26,7 +26,7 @@ from ovos_workshop.skills.base import BaseSkill from ovos_utils.process_utils import RuntimeRequirements from ovos_config.config import Configuration -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills.mycroft_skill.mycroft_skill import MycroftSkill from mycroft.skills.settings import SettingsMetaUploader from ovos_utils.log import LOG diff --git a/mycroft/skills/skill_manager.py b/mycroft/skills/skill_manager.py index c2a209f9cb15..e22e68e83a0b 100644 --- a/mycroft/skills/skill_manager.py +++ b/mycroft/skills/skill_manager.py @@ -23,14 +23,14 @@ from ovos_backend_client.pairing import is_paired from mycroft.enclosure.api import EnclosureAPI 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 mycroft.util import connected from ovos_utils.network_utils import is_connected from ovos_utils.gui import is_gui_connected from mycroft.skills.skill_loader import get_skill_directories, SkillLoader, PluginSkillLoader, find_skill_plugins from mycroft.skills.skill_updater import SeleneSkillManifestUploader -from mycroft.messagebus import MessageBusClient +from ovos_bus_client.client import MessageBusClient # do not delete - bacwards compat imports from mycroft.deprecated.skills.settings import UploadQueue, SkillSettingsDownloader diff --git a/mycroft/util/process_utils.py b/mycroft/util/process_utils.py index e9e06445ead6..e9bd58c6ade9 100644 --- a/mycroft/util/process_utils.py +++ b/mycroft/util/process_utils.py @@ -5,7 +5,7 @@ from ovos_utils.log import LOG from ovos_config.config import Configuration from ovos_utils import create_daemon, wait_for_exit_signal -import mycroft.messagebus.client +from ovos_bus_client import MessageBusClient from ovos_utils.process_utils import ProcessState, ProcessStatus, StatusCallbackMap @@ -121,7 +121,7 @@ def start_message_bus_client(service, bus=None, whitelist=None): """ # Create a client if one was not provided if bus is None: - bus = mycroft.messagebus.client.MessageBusClient() + bus = MessageBusClient() Configuration.set_config_update_handlers(bus) bus_connected = Event() bus.on('message', create_echo_function(service, whitelist)) diff --git a/requirements/extra-audiobackend.txt b/requirements/extra-audiobackend.txt index 108d285a368c..2720f879933b 100644 --- a/requirements/extra-audiobackend.txt +++ b/requirements/extra-audiobackend.txt @@ -1,6 +1,6 @@ -ovos_plugin_common_play~=0.0.3 -ovos-ocp-youtube-plugin~=0.0.1 -ovos-ocp-m3u-plugin~=0.0.1 -ovos-ocp-rss-plugin~=0.0.2 +ovos_plugin_common_play~=0.0, >=0.0.5a5 +ovos-ocp-youtube-plugin~=0.0, >=0.0.1 +ovos-ocp-m3u-plugin~=0.0, >=0.0.1 +ovos-ocp-rss-plugin~=0.0, >=0.0.2 ovos-ocp-files-plugin~=0.13 -ovos-ocp-news-plugin~=0.0.3 +ovos-ocp-news-plugin~=0.0, >=0.0.3 diff --git a/requirements/minimal.txt b/requirements/minimal.txt index 35ad6e3fd0f7..af766a362101 100644 --- a/requirements/minimal.txt +++ b/requirements/minimal.txt @@ -2,13 +2,13 @@ requests~=2.26 python-dateutil~=2.6 watchdog~=2.1 -mycroft-messagebus-client~=0.9,!=0.9.2,!=0.9.3 combo-lock~=0.2 padacioso~=0.1.2 -ovos-utils~=0.0, >=0.0.31a1 -ovos-plugin-manager~=0.0, >=0.0.22 -ovos-config~=0.0,>=0.0.5 +ovos_bus_client~=0.0, >=0.0.3a17 +ovos-utils~=0.0, >=0.0.31a6 +ovos-plugin-manager~=0.0, >=0.0.23a6 +ovos-config~=0.0,>=0.0.8a3 ovos-lingua-franca~=0.4, >=0.4.6 ovos_backend_client~=0.0, >=0.0.5 -ovos_workshop~=0.0, >=0.0.11 \ No newline at end of file +ovos_workshop~=0.0, >=0.0.12a3 \ No newline at end of file diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 6eac654d2b92..532c24148cde 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -8,18 +8,18 @@ combo-lock~=0.2 PyYAML~=5.4 watchdog~=2.1 -mycroft-messagebus-client~=0.9,!=0.9.2,!=0.9.3 adapt-parser~=0.5 padatious~=0.4.8 padacioso~=0.1.2 fann2==1.0.7 padaos~=0.1 +ovos_bus_client~=0.0, >=0.0.3a17 ovos_backend_client~=0.0, >=0.0.5 -ovos-config~=0.0,>=0.0.5 -ovos-utils~=0.0, >=0.0.31a1 -ovos-plugin-manager~=0.0, >=0.0.22 -ovos_workshop~=0.0, >=0.0.11 +ovos-config~=0.0,>=0.0.8a3 +ovos-utils~=0.0, >=0.0.31a6 +ovos-plugin-manager~=0.0, >=0.0.23a6 +ovos_workshop~=0.0, >=0.0.12a3 ovos_PHAL~=0.0, >=0.0.2 ovos-lingua-franca>=0.4.6 @@ -31,12 +31,13 @@ ovos-ww-plugin-pocketsphinx~=0.1 ovos-ww-plugin-precise~=0.1 ovos-vad-plugin-webrtcvad~=0.0.1 -ovos_plugin_common_play~=0.0.3 -# ovos-ocp-youtube-plugin -ovos-ocp-m3u-plugin~=0.0.1 -ovos-ocp-rss-plugin~=0.0.2 +ovos_plugin_common_play~=0.0, >=0.0.5a5 +# ovos-ocp-youtube-plugin~=0.0, >=0.0.1 +ovos-ocp-m3u-plugin~=0.0, >=0.0.1 +ovos-ocp-rss-plugin~=0.0, >=0.0.2 ovos-ocp-files-plugin~=0.13 -ovos-ocp-news-plugin~=0.0.3 +ovos-ocp-news-plugin~=0.0, >=0.0.3 + ovos-skill-volume~=0.0.1 ovos-skill-fallback-unknown~=0.0.2 diff --git a/requirements/tests.txt b/requirements/tests.txt index d6052a46b0b1..baa0d49b3afc 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -7,6 +7,7 @@ sphinx==2.2.1 sphinx-rtd-theme==0.4.3 mock_msm~=0.9.2 +mycroft-messagebus-client ovos-stt-plugin-selene>=0.0.3a3 ovos-stt-plugin-vosk>=0.1.3 python-vlc==1.1.2 diff --git a/test/unittests/audio/test_service.py b/test/unittests/audio/test_service.py index e9eceb80466c..f6428e5141b0 100644 --- a/test/unittests/audio/test_service.py +++ b/test/unittests/audio/test_service.py @@ -17,7 +17,7 @@ import unittest.mock as mock import mycroft.audio.audioservice as audio_service -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from .services.working import WorkingBackend """Tests for Audioservice class""" diff --git a/test/unittests/audio/test_utils.py b/test/unittests/audio/test_utils.py index 04e838f24cec..ee9bc59b2778 100644 --- a/test/unittests/audio/test_utils.py +++ b/test/unittests/audio/test_utils.py @@ -60,7 +60,7 @@ def test_wait_while_speaking(self): self.assertTrue(done_waiting) @mock.patch('mycroft.audio.utils.is_speaking') - @mock.patch('mycroft.messagebus.send_func.send') + @mock.patch('ovos_bus_client.send_func.send') def test_stop_speaking(self, mock_send, mock_is_speaking): """Test that stop speak message is sent.""" mock_is_speaking.return_value = True @@ -68,7 +68,7 @@ def test_stop_speaking(self, mock_send, mock_is_speaking): mock_send.assert_called_with('mycroft.audio.speech.stop') @mock.patch('mycroft.audio.utils.is_speaking') - @mock.patch('mycroft.messagebus.send_func.send') + @mock.patch('ovos_bus_client.send_func.send') def test_stop_speaking_when_not(self, mock_send, mock_is_speaking): """Check that the stop speaking msg isn't sent when not speaking.""" mock_is_speaking.return_value = False diff --git a/test/unittests/compat/test_simple_audio_backend.py b/test/unittests/compat/test_simple_audio_backend.py index 532a046cf71a..c249bf6e1645 100644 --- a/test/unittests/compat/test_simple_audio_backend.py +++ b/test/unittests/compat/test_simple_audio_backend.py @@ -5,7 +5,7 @@ import unittest.mock as mock import mycroft.deprecated.audio.services.simple as simple -from mycroft.messagebus import Message +from ovos_bus_client.message import Message """Tests for the simple audio service backend.""" diff --git a/test/unittests/enclosure/test_gui.py b/test/unittests/enclosure/test_gui.py index 8a21dabbb565..7c416d2b3b11 100644 --- a/test/unittests/enclosure/test_gui.py +++ b/test/unittests/enclosure/test_gui.py @@ -17,7 +17,7 @@ from unittest import TestCase, mock from mycroft.gui import SkillGUI -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.util.file_utils import resolve_resource_file diff --git a/test/unittests/gui/test_bigscreen_extension.py b/test/unittests/gui/test_bigscreen_extension.py index a3875bf620e7..0fcfa0decf47 100644 --- a/test/unittests/gui/test_bigscreen_extension.py +++ b/test/unittests/gui/test_bigscreen_extension.py @@ -4,7 +4,7 @@ from ..mocks import MessageBusMock from mycroft.configuration import Configuration from test.util import base_config -from mycroft.messagebus import Message +from ovos_bus_client.message import Message PATCH_MODULE = "mycroft.gui.extensions" diff --git a/test/unittests/gui/test_namespace_manager.py b/test/unittests/gui/test_namespace_manager.py index 4a4945a11036..954df60aa46f 100644 --- a/test/unittests/gui/test_namespace_manager.py +++ b/test/unittests/gui/test_namespace_manager.py @@ -18,7 +18,7 @@ from mycroft.gui.namespace import Namespace, NamespaceManager from mycroft.gui.page import GuiPage -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from ..mocks import MessageBusMock PATCH_MODULE = "mycroft.gui.namespace" diff --git a/test/unittests/gui/test_smartspeaker_extension.py b/test/unittests/gui/test_smartspeaker_extension.py index 00551ca6c396..f0ddbf2975f0 100644 --- a/test/unittests/gui/test_smartspeaker_extension.py +++ b/test/unittests/gui/test_smartspeaker_extension.py @@ -4,7 +4,7 @@ from ..mocks import MessageBusMock from mycroft.configuration import Configuration from test.util import base_config -from mycroft.messagebus import Message +from ovos_bus_client.message import Message PATCH_MODULE = "mycroft.gui.extensions" diff --git a/test/unittests/messagebus/client/test_client.py b/test/unittests/messagebus/client/test_client.py index 7cd823531d8b..dad1256820f1 100644 --- a/test/unittests/messagebus/client/test_client.py +++ b/test/unittests/messagebus/client/test_client.py @@ -14,8 +14,8 @@ # from unittest import TestCase from unittest.mock import patch, Mock -from mycroft.configuration import Configuration -from mycroft.messagebus.client import MessageBusClient, MessageWaiter +from ovos_config import Configuration +from ovos_bus_client.client import MessageBusClient, MessageWaiter WS_CONF = { 'websocket': { diff --git a/test/unittests/skills/test_audioservice.py b/test/unittests/skills/test_audioservice.py index 75635374f735..0230036c1a43 100644 --- a/test/unittests/skills/test_audioservice.py +++ b/test/unittests/skills/test_audioservice.py @@ -1,6 +1,6 @@ from unittest import TestCase, mock -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills.audioservice import AudioService diff --git a/test/unittests/skills/test_common_play_skill.py b/test/unittests/skills/test_common_play_skill.py index 352f0e1bb54f..cef63748daf9 100644 --- a/test/unittests/skills/test_common_play_skill.py +++ b/test/unittests/skills/test_common_play_skill.py @@ -1,6 +1,6 @@ from unittest import TestCase, mock -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills.common_play_skill import CommonPlaySkill, CPSMatchLevel from mycroft.skills.audioservice import AudioService from test.unittests.mocks import AnyCallable diff --git a/test/unittests/skills/test_common_query_skill.py b/test/unittests/skills/test_common_query_skill.py index 7b31dcea4042..a27053d9f231 100644 --- a/test/unittests/skills/test_common_query_skill.py +++ b/test/unittests/skills/test_common_query_skill.py @@ -1,6 +1,6 @@ from unittest import TestCase, mock -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills.common_query_skill import (CommonQuerySkill, CQSMatchLevel, CQSVisualMatchLevel, handles_visuals) diff --git a/test/unittests/skills/test_event_scheduler.py b/test/unittests/skills/test_event_scheduler.py index 5e624d10213b..49b11d775ff9 100644 --- a/test/unittests/skills/test_event_scheduler.py +++ b/test/unittests/skills/test_event_scheduler.py @@ -7,8 +7,8 @@ from pyee import ExecutorEventEmitter from unittest.mock import MagicMock, patch -from mycroft.skills.event_scheduler import (EventScheduler, - EventSchedulerInterface) +from ovos_utils.messagebus import FakeBus +from ovos_bus_client.util.scheduler import EventScheduler, EventSchedulerInterface class TestEventScheduler(unittest.TestCase): @@ -110,12 +110,12 @@ def f(message): bus = ExecutorEventEmitter() es = EventSchedulerInterface('tester') - es.set_bus(bus) + es.set_bus(FakeBus()) es.set_id('id') # Schedule a repeating event es.schedule_repeating_event(f, None, 10, name='f') - self.assertTrue(len(bus._events['id:f']) == 1) + self.assertTrue(len(es.bus.ee._events['id:f']) == 1) es.shutdown() # Check that the reference to the function has been removed from the diff --git a/test/unittests/skills/test_intent_service.py b/test/unittests/skills/test_intent_service.py index 95bfad4ce0d9..e6dab4460026 100644 --- a/test/unittests/skills/test_intent_service.py +++ b/test/unittests/skills/test_intent_service.py @@ -17,7 +17,7 @@ from adapt.intent import IntentBuilder from mycroft.configuration.locale import setup_locale from mycroft.configuration import Configuration -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills.intent_service import IntentService from ovos_utils.messagebus import get_message_lang from mycroft.skills.intent_services.adapt_service import (ContextManager, diff --git a/test/unittests/skills/test_mycroft_skill.py b/test/unittests/skills/test_mycroft_skill.py index 15a11daf2f87..f6359f1be452 100644 --- a/test/unittests/skills/test_mycroft_skill.py +++ b/test/unittests/skills/test_mycroft_skill.py @@ -25,7 +25,7 @@ from adapt.intent import IntentBuilder from copy import deepcopy from mycroft.configuration import Configuration -from mycroft.messagebus.message import Message +from ovos_bus_client.message import Message from mycroft.skills.core import MycroftSkill, resting_screen_handler, intent_handler from mycroft.skills.intent_service import open_intent_envelope from mycroft.skills.skill_data import (load_regex_from_file, load_regex, diff --git a/test/unittests/skills/test_mycroft_skill_get_response.py b/test/unittests/skills/test_mycroft_skill_get_response.py index c8d603eb62d8..5cbea497d292 100644 --- a/test/unittests/skills/test_mycroft_skill_get_response.py +++ b/test/unittests/skills/test_mycroft_skill_get_response.py @@ -8,7 +8,7 @@ from lingua_franca import load_language from mycroft.skills import MycroftSkill -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from test.unittests.mocks import base_config, AnyCallable diff --git a/test/unittests/skills/test_skill_api.py b/test/unittests/skills/test_skill_api.py index 776842cf0360..035a5010b57d 100644 --- a/test/unittests/skills/test_skill_api.py +++ b/test/unittests/skills/test_skill_api.py @@ -1,7 +1,7 @@ from unittest import TestCase, mock from mycroft import MycroftSkill -from mycroft.messagebus import Message +from ovos_bus_client.message import Message from mycroft.skills import skill_api_method from mycroft.skills.api import SkillApi diff --git a/test/unittests/skills/test_utterance_intents.py b/test/unittests/skills/test_utterance_intents.py index a1de18e6c070..fdbbecb4a18d 100644 --- a/test/unittests/skills/test_utterance_intents.py +++ b/test/unittests/skills/test_utterance_intents.py @@ -1,6 +1,6 @@ import unittest from mycroft.skills.intent_services.padatious_service import PadatiousService, FallbackIntentContainer -from mycroft_bus_client.message import Message +from ovos_bus_client.message import Message from ovos_utils.messagebus import FakeBus diff --git a/test/unittests/util/test_audio_utils.py b/test/unittests/util/test_audio_utils.py index a58614b1ad17..b8fa544a8426 100644 --- a/test/unittests/util/test_audio_utils.py +++ b/test/unittests/util/test_audio_utils.py @@ -13,7 +13,7 @@ } -@mock.patch('ovos_utils.sound.Configuration') +@mock.patch('ovos_utils.sound.read_mycroft_config') @mock.patch('ovos_utils.sound.subprocess') class TestPlaySounds(TestCase): def test_play_ogg(self, mock_subprocess, mock_conf):