Skip to content

Commit

Permalink
bug/fix everything around brightness/nightmode... (#31)
Browse files Browse the repository at this point in the history
* bug/get_rid_of_duplicate_configs

closes #26

* clean up some more, did this thing ever work right?

* reformat some more

* Update ovos_gui_plugin_shell_companion/__init__.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* drop hardcoded sleeps, use events, standardize brightness handlers names to follow conventions

* further simplify dimming logic

* night mode tweaks

* refactor periodic nightmode check, schedule events directly for sunset/sunrise times

* typo

* readme

* safety checks around brightness manager, default_brightness setting, change brightness during nightmode

* safety checks and error logs

* low_brightness and auto_dim_seconds from config

* autodim during night mode

* fix value range

* ensure ints not floats

* remove redundant checks

* simplify further

* fix sunrise/sunset calculation

* fix sunrise/sunset typo

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update README.md

* improve responsiveness

* streamline sunset calculations, no need for a 12h timer...

* avoid multiple events firing

* simplify suntimes calc

* DRY

* less log spam

* syntax error

* Update README.md

* configurable sunset/sunrise times

* refactor/split discover into helper methods

* check if modes are enabled on launch, not only on GUI settings change

use the ovos-shell native brightness control

WHY did this code even exist

* option to make default

* better nightmode autodim

* better nightmode autodim

* more logs

* error handling

* fix night time check

* minimize writes

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
JarbasAl and coderabbitai[bot] authored Sep 18, 2024
1 parent 2c19374 commit 18dcb8d
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 440 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/unit_tests.yml

This file was deleted.

56 changes: 49 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
# OVOS Shell companion

provides various bus APIs that integrate with ovos-shell
provides various bus APIs that integrate with [ovos-shell](https://github.com/OpenVoiceOS/ovos-shell)

- color scheme manager
- notifications widgets
- configuration provider (settings UI)
- brightness control (night mode etc)


these used to be several individual plugins but they all are ovos-shell specific integrations and ovos-shell requires all of them, so they have been unified
## Features

```json
{
"gui": {
"ovos-gui-plugin-shell-companion": {
"sunrise_time": "auto",
"sunset_time": "auto",
"default_brightness": 100,
"night_default_brightness": 70,
"low_brightness": 20,
"auto_dim_seconds": 60,
"auto_dim": false,
"auto_nightmode": false
}
}
}
```


### Night mode

night mode will perform actions based on sunset/sunrise times

- the homescreen changes to a simple clock with white text on a black background.
- default brightness is reduced.
- auto-dim is enabled

`sunrise_time` and `sunset_time` will be automatically calculated based on location if set to `"auto"`, specific times can be explicitly set with the format `"HH:MM"`, eg. if you are an early riser you may want `"sunrise_time": "05:30"`

brightness level during nighttime can be set via `"night_default_brightness"`

### Auto Dim

auto-dim will lower the screen brightness after 60 seconds of inactivity, until the user interacts with the GUI or talks to the OVOS device

brightness level when idle can be set via `"low_brightness"`

auto-dim can be enabled at all times by setting `"auto_dim": true` in your config


## DEPRECATION WARNING

> in **ovos-core version 0.0.7** the bus apis provided by this repo used to be several individual PHAL plugins
the following packages have been deprecated in favor of this repo:
- https://github.com/OpenVoiceOS/ovos-PHAL-plugin-dashboard <- DEPRECATED, community maintained, no official replacement, [removed from ovos-shell](https://github.com/OpenVoiceOS/ovos-gui/pull/10)
- https://github.com/OpenVoiceOS/ovos-PHAL-plugin-configuration-provider
- https://github.com/OpenVoiceOS/ovos-PHAL-plugin-notification-widgets
- https://github.com/OpenVoiceOS/ovos-PHAL-plugin-brightness-control-rpi
- https://github.com/OpenVoiceOS/ovos-PHAL-plugin-color-scheme-manager
- [ovos-PHAL-plugin-dashboard](https://github.com/OpenVoiceOS/ovos-PHAL-plugin-dashboard) <- DEPRECATED, community maintained, no official replacement, [removed from ovos-shell](https://github.com/OpenVoiceOS/ovos-gui/pull/10)
- [ovos-PHAL-plugin-configuration-provider](https://github.com/OpenVoiceOS/ovos-PHAL-plugin-configuration-provider) <- now part of this repo
- [ovos-PHAL-plugin-notification-widgets](https://github.com/OpenVoiceOS/ovos-PHAL-plugin-notification-widgets) <- now part of this repo
- [ovos-PHAL-plugin-brightness-control-rpi](https://github.com/OpenVoiceOS/ovos-PHAL-plugin-brightness-control-rpi) <- now part of this repo
- [ovos-PHAL-plugin-color-scheme-manager](https://github.com/OpenVoiceOS/ovos-PHAL-plugin-color-scheme-manager) <- now part of this repo
38 changes: 19 additions & 19 deletions ovos_gui_plugin_shell_companion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import platform

from os.path import join, dirname
from ovos_bus_client.client import MessageBusClient

from ovos_bus_client import Message
from ovos_utils import network_utils
from ovos_bus_client.apis.gui import GUIInterface
from ovos_utils.log import LOG
from ovos_bus_client.client import MessageBusClient
from ovos_config.config import Configuration
from ovos_plugin_manager.templates.gui import GUIExtension
from ovos_utils import network_utils
from ovos_utils.log import LOG

from ovos_gui_plugin_shell_companion.brightness import BrightnessManager
from ovos_gui_plugin_shell_companion.color_manager import ColorManager
from ovos_gui_plugin_shell_companion.config import get_ovos_shell_config
from ovos_gui_plugin_shell_companion.cui import ConfigUIManager
from ovos_gui_plugin_shell_companion.helpers import ConfigUIManager
from ovos_gui_plugin_shell_companion.wigets import WidgetManager
from ovos_plugin_manager.templates.gui import GUIExtension


class OVOSShellCompanionExtension(GUIExtension):
Expand Down Expand Up @@ -44,13 +43,12 @@ def __init__(self, config: dict, bus: MessageBusClient = None,
LOG.info("OVOS Shell: Initializing")
super().__init__(config=config, bus=bus, gui=gui,
preload_gui=preload_gui, permanent=permanent)
self.local_display_config = get_ovos_shell_config()
self.about_page_data = []
self.build_initial_about_page_data()

self.color_manager = ColorManager(self.bus)
self.widgets = WidgetManager(self.bus)
self.bright = BrightnessManager(self.bus)
self.bright = BrightnessManager(self.bus, self.config)
self.cui = ConfigUIManager(self.bus)

def register_bus_events(self):
Expand Down Expand Up @@ -81,7 +79,7 @@ def register_bus_events(self):
self.handle_display_auto_nightmode_config_set)

def handle_remove_namespace(self, message):
LOG.info("Got Clear Namespace Event In Skill")
LOG.debug("Clearing namespace (mycroft.gui.screen.close)")
get_skill_namespace = message.data.get("skill_id", "")
if get_skill_namespace:
self.bus.emit(Message("gui.clear.namespace",
Expand Down Expand Up @@ -139,11 +137,11 @@ def handle_device_display_factory(self, message):
self.gui.show_page("SYSTEM_AdditionalSettings.qml", override_idle=True)

def handle_device_display_settings(self, message):
LOG.debug(f"Display settings: {self.local_display_config}")
LOG.debug(f"Display settings: {self.config}")
self.gui['state'] = 'settings/display_settings'
# wallpaper_rotation data is determined via Messagebus in Qt directly
self.gui['display_auto_dim'] = self.local_display_config.get("auto_dim", False)
self.gui['display_auto_nightmode'] = self.local_display_config.get("auto_nightmode", False)
self.gui['display_auto_dim'] = self.config.get("auto_dim", False)
self.gui['display_auto_nightmode'] = self.config.get("auto_nightmode", False)
self.gui.show_page("SYSTEM_AdditionalSettings.qml", override_idle=True)

def handle_device_about_page(self, message):
Expand All @@ -156,15 +154,17 @@ def handle_device_about_page(self, message):

def handle_display_auto_dim_config_set(self, message):
auto_dim = message.data.get("auto_dim", False)
self.local_display_config["auto_dim"] = auto_dim
self.local_display_config.store()
self.bus.emit(Message("speaker.extension.display.auto.dim.changed"))
if auto_dim:
self.bright.start_auto_dim()
else:
self.bright.stop_auto_dim()

def handle_display_auto_nightmode_config_set(self, message):
auto_nightmode = message.data.get("auto_nightmode", False)
self.local_display_config["auto_nightmode"] = auto_nightmode
self.local_display_config.store()
self.bus.emit(Message("speaker.extension.display.auto.nightmode.changed"))
if auto_nightmode:
self.bright.start_auto_night_mode()
else:
self.bright.stop_auto_night_mode()

def display_advanced_config_for_group(self, message=None):
group_meta = message.data.get("settingsMetaData")
Expand Down
Loading

0 comments on commit 18dcb8d

Please sign in to comment.