Skip to content

Commit

Permalink
Merge branch 'master' into pythonw
Browse files Browse the repository at this point in the history
  • Loading branch information
timmo001 committed Jun 8, 2022
2 parents b0b874b + 867e702 commit 2dddc0e
Show file tree
Hide file tree
Showing 47 changed files with 1,054 additions and 582 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ The GUI for the application. This shows a system tray icon and allows you to int

Shared package required by the `systembridgebackend`, `systembridgecli` and `systembridgegui` packages.

### `systembridgewindowssensors`

Specifically for windows, adds sensors to get windows system information.

### Developing

You can install each python module using pip:
Expand Down
3 changes: 0 additions & 3 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ good-names = [
# locally-disabled - it spams too much
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
# abstract-class-little-used - prevents from setting right foundation
# unused-argument - generic callbacks and setup methods create a lot of warnings
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
Expand All @@ -67,13 +66,11 @@ good-names = [
# wrong-import-order - isort guards this
disable = [
"format",
"abstract-class-little-used",
"abstract-method",
"cyclic-import",
"duplicate-code",
"inconsistent-return-statements",
"locally-disabled",
"no-self-use",
"not-context-manager",
"too-few-public-methods",
"too-many-ancestors",
Expand Down
2 changes: 1 addition & 1 deletion backend/systembridgebackend/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

from incremental import Version

__version__ = Version("systembridgebackend", 3, 1, 0, dev=9)
__version__ = Version("systembridgebackend", 3, 1, 5, dev=0)
__all__ = ["__version__"]
1 change: 1 addition & 0 deletions backend/systembridgebackend/modules/display/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_displays(
if (
item[COLUMN_HARDWARE_TYPE] is not None
and "display" in item[COLUMN_HARDWARE_TYPE].lower()
and item[COLUMN_HARDWARE_NAME] is not None
and item[COLUMN_HARDWARE_NAME] not in displays
):
displays.append(item[COLUMN_HARDWARE_NAME])
Expand Down
4 changes: 4 additions & 0 deletions backend/systembridgebackend/modules/display/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ async def update_resolution_vertical(

async def update_all_data(self) -> None:
"""Update data"""

# Clear table in case of hardware changes since last run
self._database.clear_table("display")

display_list = []
for display_name in self._display.get_displays(self._database):
display_key = make_key(display_name)
Expand Down
4 changes: 4 additions & 0 deletions backend/systembridgebackend/modules/gpu/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ async def update_temperature(

async def update_all_data(self) -> None:
"""Update data"""

# Clear table in case of hardware changes since last run
self._database.clear_table("gpu")

gpu_list = []
for gpu_name in self._gpu.get_gpus(self._database):
gpu_key = make_key(gpu_name)
Expand Down
16 changes: 11 additions & 5 deletions backend/systembridgebackend/modules/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections.abc import Callable

from systembridgeshared.base import Base
from systembridgeshared.const import MODEL_MAP
from systembridgeshared.database import Database


Expand Down Expand Up @@ -88,10 +89,18 @@ async def refresh_data_by_module(
self._logger.warning("Module to refresh not implemented: %s", module)
return

if (model := MODEL_MAP.get(module)) is None:
self._logger.warning("Unknown model: %s", module)
return

new_data = self._database.table_data_to_ordered_dict(module)
if new_data and new_data != self._data[module]:
if new_data is None:
self._logger.warning("No data found for module: %s", module)
return

if new_data != self._data[module]:
self._logger.info("Data changed for module: %s", module)
self._data[module] = new_data
self._data[module] = model(**new_data).dict()
for listener in self._registered_listeners:
self._logger.info("Listener: %s - %s", listener.id, listener.modules)
if module in listener.modules:
Expand All @@ -113,9 +122,6 @@ def remove_listener(
if listener.id == listener_id:
self._registered_listeners.remove(listener)
self._logger.info("Removed listener: %s", listener_id)
self._logger.info(
"Registered listeners: %s", self._registered_listeners
)
return True

self._logger.info("Listener not found: %s", listener_id)
Expand Down
4 changes: 4 additions & 0 deletions backend/systembridgebackend/modules/sensors/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ async def update_windows_sensors(self) -> None:

async def update_all_data(self) -> None:
"""Update data"""

# Clear table in case of hardware changes since last run
self._database.clear_table("sensors")

await asyncio.gather(
*[
self.update_fans(),
Expand Down
2 changes: 1 addition & 1 deletion backend/systembridgebackend/modules/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def version_latest(self) -> GitHubReleaseModel | None:
)
return None

def version_newer_avaliable(
def version_newer_available(
self,
database: Database,
) -> bool | None:
Expand Down
8 changes: 4 additions & 4 deletions backend/systembridgebackend/modules/system/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ async def update_version_latest(self) -> None:
release.tag_name.replace("v", "") if release is not None else None,
)

async def update_version_newer_avaliable(self) -> None:
async def update_version_newer_available(self) -> None:
"""Update newer version available"""
self._database.write(
"system",
"version_newer_avaliable",
self._system.version_newer_avaliable(self._database),
"version_newer_available",
self._system.version_newer_available(self._database),
)

async def update_all_data(self) -> None:
Expand All @@ -105,4 +105,4 @@ async def update_all_data(self) -> None:
]
)
# Run after other version updates
await self.update_version_newer_avaliable()
await self.update_version_newer_available()
7 changes: 5 additions & 2 deletions backend/systembridgebackend/modules/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def __init__(
self._classes = [
{"name": "battery", "cls": BatteryUpdate(self._database)},
{"name": "disk", "cls": DiskUpdate(self._database)},
{"name": "display", "cls": DisplayUpdate(self._database)},
{"name": "system", "cls": SystemUpdate(self._database)},
]
self._classes_frequent = [
{"name": "sensors", "cls": SensorsUpdate(self._database)},
{"name": "cpu", "cls": CPUUpdate(self._database)},
{"name": "display", "cls": DisplayUpdate(self._database)},
{"name": "gpu", "cls": GPUUpdate(self._database)},
{"name": "memory", "cls": MemoryUpdate(self._database)},
{"name": "network", "cls": NetworkUpdate(self._database)},
Expand Down Expand Up @@ -75,6 +74,10 @@ async def update_frequent_data(
if not self._database.connected:
self._database.connect()

sensors_update = SensorsUpdate(self._database)
await sensors_update.update_all_data()
await updated_callback("sensors")

tasks = [self._update(cls, updated_callback) for cls in self._classes_frequent]
await asyncio.gather(*tasks)

Expand Down
6 changes: 6 additions & 0 deletions backend/systembridgebackend/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
handler_shutdown,
handler_sleep,
)
from systembridgebackend.server.update import handler_update
from systembridgebackend.server.websocket import WebSocketHandler


Expand Down Expand Up @@ -237,6 +238,11 @@ async def _handler_websocket(
"/api/power/logout",
methods=["POST"],
)
self._server.add_route(
lambda r: _handler_generic(r, handler_update),
"/api/update",
methods=["POST"],
)

if "--no-frontend" not in sys.argv:
try:
Expand Down
20 changes: 20 additions & 0 deletions backend/systembridgebackend/server/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""System Bridge: Server Handler - Update"""
from sanic.request import Request
from sanic.response import HTTPResponse, json
from systembridgeshared.update import Update


async def handler_update(
request: Request,
) -> HTTPResponse:
"""Handle the update request."""
versions = Update().update(
request.args.get("version"),
wait=False,
)
return json(
{
"message": "Updating the application",
"versions": versions,
}
)

0 comments on commit 2dddc0e

Please sign in to comment.