Skip to content

Commit

Permalink
refactor/ovos-bus-client (#110)
Browse files Browse the repository at this point in the history
* refactor/ovos-bus-client

* circular import

* scripts module

(cherry picked from commit 34f269f)
  • Loading branch information
JarbasAl authored and NeonDaniel committed Apr 18, 2023
1 parent b2b2040 commit 2b28786
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 62 deletions.
4 changes: 2 additions & 2 deletions ovos_utils/intents/intent_service_interface.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from os.path import exists, isfile


from mycroft_bus_client import MessageBusClient
from mycroft_bus_client.message import Message, dig_for_message
from ovos_bus_client import MessageBusClient
from ovos_bus_client.message import Message, dig_for_message
from ovos_utils import create_daemon
from ovos_utils.log import LOG

Expand Down
11 changes: 7 additions & 4 deletions ovos_utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from logging.handlers import RotatingFileHandler
from os.path import join

from mycroft_bus_client.message import dig_for_message


class LOG:
Expand Down Expand Up @@ -115,9 +114,13 @@ def _get_real_logger(cls):

logger = cls.create_logger(name, tostdout=True)
if cls.diagnostic_mode:
msg = dig_for_message()
if msg:
logger.debug(f"DIAGNOSTIC - source bus message {msg.serialize()}")
try:
from ovos_bus_client.message import dig_for_message
msg = dig_for_message()
if msg:
logger.debug(f"DIAGNOSTIC - source bus message {msg.serialize()}")
except ImportError:
pass
return logger

@classmethod
Expand Down
16 changes: 14 additions & 2 deletions ovos_utils/messagebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from inspect import signature
from threading import Event

from mycroft_bus_client import MessageBusClient
from mycroft_bus_client.message import dig_for_message, Message

from ovos_config.config import Configuration
from ovos_config.locale import get_default_lang
from pyee import BaseEventEmitter
Expand Down Expand Up @@ -127,6 +126,8 @@ def get_message_lang(message=None):
Returns:
The language code from the message or the default language.
"""
from ovos_bus_client.message import dig_for_message

message = message or dig_for_message()
default_lang = get_default_lang()
if not message:
Expand All @@ -139,6 +140,8 @@ def get_websocket(host, port, route='/', ssl=False, threaded=True):
"""
Returns a connection to a websocket
"""
from ovos_bus_client import MessageBusClient

client = MessageBusClient(host, port, route, ssl)
if threaded:
client.run_in_thread()
Expand Down Expand Up @@ -198,6 +201,8 @@ def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None):
Returns:
The received message or None if the response timed out
"""
from ovos_bus_client.message import Message

auto_close = bus is None
bus = bus or get_mycroft_bus()
if isinstance(message, str):
Expand All @@ -220,6 +225,8 @@ def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None):


def send_message(message, data=None, context=None, bus=None):
from ovos_bus_client.message import Message

auto_close = bus is None
bus = bus or get_mycroft_bus()
if isinstance(message, str):
Expand Down Expand Up @@ -572,6 +579,8 @@ def set_data_gatherer(self, callback, default_data=None, daemonic=False, interva
"""
prepare responder for sending, register answers
"""
from ovos_bus_client.message import Message

self.bus.remove_all_listeners(self.trigger_message)
if ".request" in self.trigger_message:
response_type = self.trigger_message.replace(".request", ".reply")
Expand Down Expand Up @@ -623,6 +632,7 @@ class BusQuery:
"""

def __init__(self, message, bus=None):
from ovos_bus_client.message import Message
self.bus = bus or get_mycroft_bus()
self._waiting = False
self.response = Message(None, None, None)
Expand All @@ -649,6 +659,8 @@ def _wait_response(self, timeout):
self._waiting = False

def send(self, response_type=None, timeout=10):
from ovos_bus_client.message import Message

self.response = Message(None, None, None)
if response_type is None:
response_type = self.query.type + ".reply"
Expand Down
45 changes: 0 additions & 45 deletions ovos_utils/scripts.py

This file was deleted.

2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mycroft-messagebus-client~=0.9,!=0.9.2,!=0.9.3
ovos-bus-client~=0.0, >=0.0.3a4
pexpect~=4.8
requests~=2.26
json_database~=0.7
Expand Down
9 changes: 1 addition & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,5 @@ def required(requirements_file):
license='Apache',
author='jarbasAI',
author_email='jarbasai@mailfence.com',
description='collection of simple utilities for use across the mycroft ecosystem',
entry_points={
'console_scripts': [
'ovos-listen=ovos_utils.scripts:ovos_listen',
'ovos-speak=ovos_utils.scripts:ovos_speak',
'ovos-say-to=ovos_utils.scripts:ovos_say_to',
]
}
description='collection of simple utilities for use across the mycroft ecosystem'
)

0 comments on commit 2b28786

Please sign in to comment.