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

Commit

Permalink
Check if GUI is connected rather than maintain list of platforms (#3025)
Browse files Browse the repository at this point in the history
* Check if GUI is connected rather than maintain list of platforms

There are already many Mycroft platforms that have GUIs
and this will only grow. We want to know if the device
has a GUI connected rather than if it is in a pre-defined
list of platforms.

* Create a mock GUI with a settable connected attribute
  • Loading branch information
krisgesling authored Nov 24, 2021
1 parent 77549d0 commit 89cfad7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 1 addition & 8 deletions mycroft/skills/common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def is_CQSVisualMatchLevel(match_level):
return isinstance(match_level, type(CQSVisualMatchLevel.EXACT))


VISUAL_DEVICES = ['mycroft_mark_2']

"""these are for the confidence calculation"""
# how much each topic word is worth
# when found in the answer
Expand All @@ -53,10 +51,6 @@ def is_CQSVisualMatchLevel(match_level):
WORD_COUNT_DIVISOR = 100


def handles_visuals(platform):
return platform in VISUAL_DEVICES


class CommonQuerySkill(MycroftSkill, ABC):
"""Question answering skills should be based on this class.
Expand Down Expand Up @@ -149,9 +143,8 @@ def __calc_confidence(self, match, phrase, level, answer):
num_sentences = float(float(len(answer.split("."))) / float(10))

# Add bonus if match has visuals and the device supports them.
platform = self.config_core.get("enclosure", {}).get("platform")
bonus = 0.0
if is_CQSVisualMatchLevel(level) and handles_visuals(platform):
if is_CQSVisualMatchLevel(level) and self.gui.connected:
bonus = 0.1

# extract topic
Expand Down
20 changes: 11 additions & 9 deletions test/unittests/skills/test_common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from mycroft.messagebus import Message
from mycroft.skills.common_query_skill import (CommonQuerySkill, CQSMatchLevel,
CQSVisualMatchLevel,
handles_visuals)
CQSVisualMatchLevel)
from test.unittests.mocks import AnyCallable


Expand All @@ -23,11 +22,6 @@ def test_lifecycle(self):
bus.on.assert_any_call('question:action', AnyCallable())
skill.shutdown()

def test_handles_visuals(self):
"""Test the helper method to determine if the skill handles visuals."""
self.assertTrue(handles_visuals('mycroft_mark_2'))
self.assertFalse(handles_visuals('mycroft_mark_1'))

def test_common_test_skill_action(self):
"""Test that the optional action is triggered."""
query_action = self.bus.on.call_args_list[-1][0][1]
Expand All @@ -44,6 +38,7 @@ def test_common_test_skill_action(self):

class TestCommonQueryMatching(TestCase):
"""Tests for CQS_match_query_phrase."""

def setUp(self):
self.skill = CQSTest()
self.bus = mock.Mock(name='bus')
Expand Down Expand Up @@ -99,11 +94,10 @@ def test_successful_match_query_phrase(self):
self.assertEqual(response.data['conf'], 1.12)

def test_successful_visual_match_query_phrase(self):
self.skill.config_core['enclosure']['platform'] = 'mycroft_mark_2'
self.skill.gui.connected = True
query_phrase = self.bus.on.call_args_list[-2][0][1]
self.skill.CQS_match_query_phrase.return_value = (
'What\'s the meaning of life', CQSVisualMatchLevel.EXACT, '42')

query_phrase(Message('question:query',
data={'phrase': 'What\'s the meaning of life'}))

Expand All @@ -125,14 +119,22 @@ def test_successful_visual_match_query_phrase(self):

class CQSTest(CommonQuerySkill):
"""Simple skill for testing the CommonQuerySkill"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.CQS_match_query_phrase = mock.Mock(name='match_phrase')
self.CQS_action = mock.Mock(name='selected_action')
self.skill_id = 'CQSTest'
self.gui = MockGUI()

def CQS_match_query_phrase(self, phrase):
pass

def CQS_action(self, phrase, data):
pass


class MockGUI():
def __init__(self):
self.connected = False
self.setup_default_handlers = AnyCallable

0 comments on commit 89cfad7

Please sign in to comment.