Skip to content

Commit

Permalink
reduce bus/log spam (#37)
Browse files Browse the repository at this point in the history
* modernize

- rename methods for consistency (show/display/update_gui ... what a mess)

- make the scheduled event update only mk1 faceplate, no need to spam the GUI bus every 10 seconds (this isnt the homescreen clock)

- remove references to deprecated self.enclosure.display_manager

- add settings changed callback, only send the repeating events if the setting is enabled, no need to spam debug logs otherwise!

- rm create_skill deprecated function

* damn tests

* ui -> qt5

rm dead files and bad automations

* typo
  • Loading branch information
JarbasAl authored Apr 14, 2024
1 parent 1f14dd3 commit 5cd270a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 314 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/publish_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ jobs:
run: |
VER=$(python setup.py --version)
python scripts/remove_alpha.py
- name: Prepare Skillstore metadata
run: |
python scripts/prepare_skillstore.py
python scripts/release_skillstore.py
- name: "Generate release changelog"
uses: heinrichreimer/[email protected]
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/publish_major.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ jobs:
run: |
VER=$(python setup.py --version)
python scripts/remove_alpha.py
- name: Prepare Skillstore metadata
run: |
python scripts/prepare_skillstore.py
python scripts/release_skillstore.py
- name: "Generate release changelog"
uses: heinrichreimer/[email protected]
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/publish_minor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ jobs:
run: |
VER=$(python setup.py --version)
python scripts/remove_alpha.py
- name: Prepare Skillstore metadata
run: |
python scripts/prepare_skillstore.py
python scripts/release_skillstore.py
- name: "Generate release changelog"
uses: heinrichreimer/[email protected]
with:
Expand Down
74 changes: 41 additions & 33 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,27 @@ def initialize(self):
self.default_timezone = None
date_time_format.cache(self.lang)

self.settings_change_callback = self.on_settings_changed
if self.settings.get("show_time"):
self.schedule_clock_rendering()

def schedule_clock_rendering(self):
self.cancel_scheduled_event("clock")
# Start a callback that repeats every 10 seconds
# TODO: Add mechanism to only start timer when UI setting
# is checked, but this requires a notifier for settings
# updates from the web.
now = datetime.datetime.now()
callback_time = (datetime.datetime(now.year, now.month, now.day,
now.hour, now.minute) +
datetime.timedelta(seconds=60))
self.schedule_repeating_event(self.update_display, callback_time, 10)
self.schedule_repeating_event(self.update_mk1_faceplate,
when=callback_time,
frequency=10,
name="clock")

def on_settings_changed(self):
if self.settings.get("show_time"):
self.schedule_clock_rendering()
else:
self.cancel_scheduled_event("clock")

@property
def use_24hour(self):
Expand Down Expand Up @@ -234,12 +246,16 @@ def get_spoken_current_time(self, location=None,

return s

def display(self, display_time):
if display_time:
self.display_gui(display_time)
self.display_mark1(display_time)
def show_time(self, display_time=None):
display_time = display_time or self.get_display_current_time()
self.show_time_gui(display_time)
self.show_time_mark1(display_time)

def show_time_mark1(self, display_time=None):
display_time = display_time or self.get_display_current_time()
# TODO - move to mark 1 plugin/gui extension,
# implement "homescreen" for mark1

def display_mark1(self, display_time):
# Map characters to the display encoding for a Mark 1
# (4x8 except colon, which is 2x8)
code_dict = {
Expand Down Expand Up @@ -295,40 +311,37 @@ def _is_alarm_set(self):
msg = self.bus.wait_for_response(query)
return msg and msg.data.get("active_alarms", 0) > 0

def display_gui(self, display_time):
def show_time_gui(self, display_time=None):
display_time = display_time or self.get_display_current_time()
""" Display time on the Mycroft GUI. """
self.gui.clear()
self.gui['time_string'] = display_time
self.gui['ampm_string'] = ''
self.gui['date_string'] = self.get_display_date()
self.gui.show_page('time.qml')
self.gui.show_page('time')

def _is_display_idle(self):
# check if the display is being used by another skill right now
# or _get_active() == "TimeSkill"
return self.enclosure.display_manager.get_active() == ''

def update_display(self, force=False):
def update_mk1_faceplate(self, force=False):
# TODO - move to mark 1 plugin/gui extension,
# implement "homescreen" for mark1

# Don't show idle time when answering a query to prevent
# overwriting the displayed value.
if self.answering_query:
return

self.gui['time_string'] = self.get_display_current_time()
self.gui['date_string'] = self.get_display_date()
self.gui['ampm_string'] = '' # TODO
self.gui['weekday_string'] = self.get_weekday()
self.gui['month_string'] = self.get_month_date()

if self.settings.get("show_time", False):
# user requested display of time while idle
if (force is True) or self._is_display_idle():
# (Mark1 faceplate)
if force or self._is_display_idle():
current_time = self.get_display_current_time()
if self.displayed_time != current_time:
self.displayed_time = current_time
self.display(current_time)
# return mouth to 'idle'
self.enclosure.display_manager.remove_active()
self.show_time_mark1(current_time)
else:
self.displayed_time = None # another skill is using display
else:
Expand All @@ -337,8 +350,6 @@ def update_display(self, force=False):
if self._is_display_idle():
# erase the existing displayed time
self.enclosure.mouth_reset()
# return mouth to 'idle'
self.enclosure.display_manager.remove_active()
self.displayed_time = None

def _extract_location(self, utt):
Expand Down Expand Up @@ -377,7 +388,7 @@ def handle_query_time(self, message):
# and briefly show the time
self.answering_query = True
self.enclosure.deactivate_mouth_events()
self.display(self.get_display_current_time(location))
self.show_time(self.get_display_current_time(location))
time.sleep(5)
self.enclosure.mouth_reset()
self.enclosure.activate_mouth_events()
Expand Down Expand Up @@ -410,7 +421,7 @@ def handle_query_future_time(self, message):
# and briefly show the time
self.answering_query = True
self.enclosure.deactivate_mouth_events()
self.display(self.get_display_current_time(location, dt))
self.show_time(self.get_display_current_time(location, dt))
time.sleep(5)
self.enclosure.mouth_reset()
self.enclosure.activate_mouth_events()
Expand Down Expand Up @@ -438,9 +449,10 @@ def handle_show_time(self, message):
else:
self.display_tz = None

# show time immediately
# enable setting
self.settings["show_time"] = True
self.update_display(True)
# show time immediately
self.show_time()

######################################################################
# Date queries
Expand Down Expand Up @@ -628,8 +640,4 @@ def show_date_gui(self, location, day):
self.gui['day_string'] = month_string[0]
self.gui['month_string'] = month_string[1]
self.gui['year_string'] = self.get_year(day, location)
self.gui.show_page('date.qml')


def create_skill():
return TimeSkill()
self.gui.show_page('date')
File renamed without changes.
File renamed without changes.
113 changes: 0 additions & 113 deletions res/desktop/skill.json

This file was deleted.

76 changes: 0 additions & 76 deletions scripts/prepare_skillstore.py

This file was deleted.

Loading

0 comments on commit 5cd270a

Please sign in to comment.