Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

fix/ensure_valid_urls #15

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ovos_backend_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def backend_type(self):

@property
def backend_url(self):
if not self.backend.url.startswith("http"):
self.backend.url = f"http://{self.backend.url}"
return self.backend.url

@property
Expand Down
10 changes: 10 additions & 0 deletions ovos_backend_client/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, url, version="v1", identity_file=None, backend_type=BackendTy
self.backend_type = backend_type
self._identity_file = identity_file
self.backend_version = version
if not url.startswith("http"):
url = f"http://{url}"
self.url = url
self.credentials = credentials or {}

Expand Down Expand Up @@ -59,6 +61,8 @@ def refresh_token(self):

def get(self, url=None, *args, **kwargs):
url = url or self.url
if not url.startswith("http"):
url = f"http://{url}"
headers = self.headers
if "headers" in kwargs:
headers.update(kwargs.pop("headers"))
Expand All @@ -67,6 +71,8 @@ def get(self, url=None, *args, **kwargs):

def post(self, url=None, *args, **kwargs):
url = url or self.url
if not url.startswith("http"):
url = f"http://{url}"
headers = self.headers
if "headers" in kwargs:
headers.update(kwargs.pop("headers"))
Expand All @@ -75,6 +81,8 @@ def post(self, url=None, *args, **kwargs):

def put(self, url=None, *args, **kwargs):
url = url or self.url
if not url.startswith("http"):
url = f"http://{url}"
headers = self.headers
if "headers" in kwargs:
headers.update(kwargs.pop("headers"))
Expand All @@ -83,6 +91,8 @@ def put(self, url=None, *args, **kwargs):

def patch(self, url=None, *args, **kwargs):
url = url or self.url
if not url.startswith("http"):
url = f"http://{url}"
headers = self.headers
if "headers" in kwargs:
headers.update(kwargs.pop("headers"))
Expand Down
24 changes: 17 additions & 7 deletions ovos_backend_client/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from ovos_utils.messagebus import Message, FakeBus
from ovos_utils.network_utils import is_connected

from ovos_backend_client.api import DeviceApi
from ovos_backend_client.api import DeviceApi, BackendType
from ovos_backend_client.exceptions import BackendDown, InternetDown, HTTPError
from ovos_backend_client.identity import IdentityManager
from ovos_backend_client.backends.selene import SELENE_API_URL


def is_backend_disabled():
Expand Down Expand Up @@ -107,7 +108,10 @@ def __init__(self, bus=None, enclosure=None,
restart_callback=None,
end_callback=None,
pairing_url="home.mycroft.ai",
api_url="api.mycroft.ai"):
api_url=SELENE_API_URL,
version="v1",
identity_file=None,
backend_type=None):
self.pairing_url = pairing_url
self.api_url = api_url
self.restart_callback = restart_callback
Expand All @@ -118,8 +122,9 @@ def __init__(self, bus=None, enclosure=None,
self.end_callback = end_callback

self.bus = bus or FakeBus()
self.enclosure = enclosure or EnclosureAPI(self.bus, "skill-ovos-setup.openvoiceos")
self.api = DeviceApi(url=api_url)
self.enclosure = enclosure or EnclosureAPI(self.bus, "ovos-backend-client.openvoiceos")
self.api = DeviceApi(url=api_url, version=version,
identity_file=identity_file, backend_type=backend_type)
self.data = None
self.time_code_expires = None
self.uuid = str(uuid4())
Expand All @@ -130,9 +135,13 @@ def __init__(self, bus=None, enclosure=None,
self.count = -1 # for repeating pairing code. -1 = not running
self.num_failed_codes = 0

def set_api_url(self, url):
def set_api_url(self, url, version="v1", identity_file=None, backend_type=BackendType.SELENE):
if not url.startswith("http"):
url = f"http://{url}"
self.api_url = url
self.api = DeviceApi(url)
self.api = DeviceApi(url, version=version,
identity_file=identity_file,
backend_type=backend_type)

def shutdown(self):
with self.activator_lock:
Expand Down Expand Up @@ -218,6 +227,7 @@ def check_for_activate(self):
# Something must be seriously wrong
LOG.debug("Second save attempt failed: " + repr(e2))
self.abort_and_restart()
return

# Assume speaking is the pairing code. Stop TTS of that.
self.bus.emit(Message("mycroft.audio.speech.stop"))
Expand Down Expand Up @@ -294,7 +304,7 @@ def __create_activator(self):
self.activator.start()

def handle_pairing_code(self):
"""Speak pairing code."""
"""Log pairing code."""
code = self.data.get("code")
LOG.info("Pairing code: " + code)
if self.enclosure:
Expand Down