Skip to content

Commit

Permalink
Merge pull request #59 from Video-Nomad/feat/libre-hardware-monitor-w…
Browse files Browse the repository at this point in the history
…idget

feat(widget): Libre Hardware Monitor Widget
  • Loading branch information
amnweb authored Oct 22, 2024
2 parents d7d5a7a + b71b92f commit f63022b
Show file tree
Hide file tree
Showing 8 changed files with 516 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ for more themes visit [yasb-themes](https://github.com/amnweb/yasb-themes)
- **[Github](https://github.com/amnweb/yasb/wiki/(Widget)-Github)**: Shows notifications from GitHub.
- **[Disk](https://github.com/amnweb/yasb/wiki/(Widget)-Disk)**: Displays disk usage information.
- **[Language](https://github.com/amnweb/yasb/wiki/(Widget)-Language)**: Shows the current input language.
- **[Libre Hardware Monitor](https://github.com/amnweb/yasb/wiki/(Widget)-Libre-HW-Monitor)**: Connects to Libre Hardware Monitor to get sensor data.
- **[Media](https://github.com/amnweb/yasb/wiki/(Widget)-Media)**: Displays media controls and information.
- **[Memory](https://github.com/amnweb/yasb/wiki/(Widget)-Memory)**: Shows current memory usage.
- **[OBS](https://github.com/amnweb/yasb/wiki/(Widget)-Obs)**: Integrates with OBS Studio to show recording status.
Expand Down
1 change: 1 addition & 0 deletions docs/_Sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Github](./(Widget)-Github)
- [Disk](./(Widget)-Disk)
- [Language](./(Widget)-Language)
- [Libre Hardware Monitor](./(Widget)-Libre-HW-Monitor)
- [Media](./(Widget)-Media)
- [Memory](./(Widget)-Memory)
- [OBS](./(Widget)-Obs)
Expand Down
96 changes: 96 additions & 0 deletions docs/widgets/(Widget)-Libre-HW-Monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Libre Hardware Monitor Widget Configuration

| Option | Type | Default | Description |
|-------------------------|---------|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| `label` | string | `"<span>\udb82\udcae </span> {info[value]}{info[unit]}"` | The primary label format. |
| `label_alt` | string | `"<span>\uf4bc </span>{info[histogram]} {info[value]} ({info[min]}/{info[max]}) {info[unit]}"` | Histograms. The alternative label format. |
| `sensor_id` | string | `"/amdcpu/0/load/0"` | Libre Hardware Monitor SensorId from http://localhost:8085/data.json |
| `class_name` | string | `"libre-monitor-widget"` | CSS class name for styling of different widget instances. |
| `update_interval` | integer | `1000` | The interval in milliseconds to update the widget. |
| `precision` | integer | `1` | Floating point precision of the info[value]. |
| `history_size` | integer | `60` | The size of the min/max history. |
| `histogram_num_columns` | integer | `10` | The number of columns in the histogram. |
| `histogram_fixed_min` | integer | `None` | Histogram minimum value. If None - set as history minimum value. |
| `histogram_fixed_max` | integer | `None` | Histogram maximum value. If None - set as history maximum value. |
| `server_host` | string | `"localhost"` | Libre Hardware Monitor server host. |
| `server_port` | integer | `8085` | Libre Hardware Monitor server port. |
| `server_username` | string | `""` | Libre Hardware Monitor username. Only needed if auth is enabled. |
| `server_password` | string | `""` | Libre Hardware Monitor password. Only needed if auth is enabled. |
| `histogram_icons` | list | `['\u2581', '\u2581', '\u2582', '\u2583', '\u2584', '\u2585', '\u2586', '\u2587', '\u2588']` | Icons representing CPU usage histograms. |
| `callbacks` | dict | `{'on_left': 'toggle_label', 'on_middle': 'do_nothing', 'on_right': 'do_nothing'}` | Callback functions for different mouse button actions. |

## Example Configuration (GPU Temperature)

```yaml
libre_gpu:
type: "yasb.libre_monitor.LibreHardwareMonitorWidget"
options:
label: "<span>\udb82\udcae </span> {info[value]}{info[unit]}"
label_alt: "<span>\uf437 </span>{info[histogram]} {info[value]} ({info[min]}/{info[max]}) {info[unit]}"
sensor_id: "/gpu-nvidia/0/temperature/0"
update_interval: 1000
precision: 1
histogram_num_columns: 10
class_name: "libre-monitor-widget"

history_size: 60
histogram_icons:
- '\u2581' # 0%
- '\u2581' # 10%
- '\u2582' # 20%
- '\u2583' # 30%
- '\u2584' # 40%
- '\u2585' # 50%
- '\u2586' # 60%
- '\u2587' # 70%
- '\u2588' # 80%+

# histogram_fixed_min: 0.0
# histogram_fixed_max: 100.0

# server_host: "localhost"
# server_port: 8085
# server_username: "admin"
# server_password: "password"

callbacks:
on_left: "toggle_label"
on_middle: "do_nothing"
on_right: "do_nothing"
```
## Set up instructions
1. Install Libre Hardware Monitor https://github.com/LibreHardwareMonitor/LibreHardwareMonitor
2. Run Libre Hardware Monitor.
3. Start the Remote Web Server (Options -> Remote Web Server -> Run).
4. Find the required SensorId in the http://localhost:8085/data.json.
5. Update the widget configuration with the required SensorId.
**Note**: Libre Hardware Monitor and its web server must be running in the background for the widget to work. Autostart is recommended.
## Description of Options
- **label**: The format string for the Libre Monitor label. You can use placeholders like `{info[value]} {info[unit]}` to dynamically insert required information.
- **label_alt**: The alternative format string for the Libre Monitor label. Useful for displaying additional details like histogram `{info[histogram]}` or min/max values `{info[min]} {info[max]}`.
- **class_name**: Custom CSS class name for the widget instance. Useful when having multiple widgets with different styling.
- **sensor_id**: The sensor ID of the Libre Hardware Monitor server. All the SensorIds can be found in the http://localhost:8085/data.json when the server is running (Options->Remote Web Server->Run).
- **update_interval**: The interval in milliseconds at which the widget updates its information. Limited by the Libre Hardware Monitor update interval.
- **precision**: Floating point precision of the `{info[value]}`.
- **history_size**: The size of the min/max history. The history is reset when the widget/yasb is reloaded.
- **histogram_fixed_min**: Set the fixed minimum value of the histogram. Actual sensor min value from the history is not changed. If not set manually it will be set as history minimum value.
- **histogram_fixed_max**: Set the fixed maximum value of the histogram. Actual sensor max value from the history is not changed. If not set manually it will be set as history maximum value.
- **histogram_icons**: A list of icons representing different values of the histogram.
- **histogram_num_columns**: The number of columns to display in the histogram.
- **server_host**: The host of the Libre Hardware Monitor server.
- **server_port**: The port of the Libre Hardware Monitor server.
- **server_username**: The username of the Libre Hardware Monitor server. Required if auth is enabled.
- **server_password**: The password of the Libre Hardware Monitor server. Required if auth is enabled.
- **callbacks**: A dictionary specifying the callbacks for mouse events. The keys are `on_left`, `on_middle`, and `on_right`, and the values are the names of the callback functions.

## Example Style
```css
.libre-monitor-widget {}
.libre-monitor-widget .widget-container {}
.libre-monitor-widget .widget-container .label {}
.libre-monitor-widget .widget-container .label.alt {}
.libre-monitor-widget .widget-container .icon {}
```
3 changes: 2 additions & 1 deletion src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'core.widgets.yasb.weather',
'core.widgets.yasb.memory',
'core.widgets.yasb.cpu',
'core.widgets.yasb.libre_monitor',
'core.widgets.yasb.active_window',
'core.widgets.yasb.applications',
'core.widgets.yasb.battery',
Expand Down Expand Up @@ -100,4 +101,4 @@
"build_exe": build_options,
"bdist_msi": bdist_msi_options,
},
)
)
48 changes: 47 additions & 1 deletion src/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,50 @@ widgets:
label_alt: "\ue62a"
class_name: "system-widget"
callbacks:
on_left: "exec start_menu"
on_left: "exec start_menu"

libre_monitor_widget:
type: "yasb.libre_monitor.LibreHardwareMonitorWidget"
options:
# Available "info" keys: value, unit, min, max, histogram
label: "<span>\udb82\udcae </span> {info[value]}{info[unit]}"
label_alt: "<span>\uf437 </span>{info[histogram]} {info[value]} ({info[min]}/{info[max]}) {info[unit]}"
sensor_id: "/gpu-nvidia/0/temperature/0" # "SensorId" from http://localhost:8085/data.json when the Libre HWM server is running.
update_interval: 1000 # Update interval in milliseconds. Limited by the Libre HWM update interval.
precision: 0
histogram_num_columns: 10

# Optional. Custom widget class name to customize multiple widgets. Default is libre-monitor-widget.
class_name: "libre-monitor-widget"

# Optional. A history of min and max values.
# history_size: 50

# Optional. Custom histogram icons. Must have exactly 9 icons.
# histogram_icons:
# - '\u2581'
# - '\u2581'
# - '\u2582'
# - '\u2583'
# - '\u2584'
# - '\u2585'
# - '\u2586'
# - '\u2587'
# - '\u2588'

# Optional. Fixed min/max value range for the histogram. Actual {info[min]} and {info[max]} values are untouched.
# histogram_fixed_min: 0.0
# histogram_fixed_max: 100.0

# Optional. Custom Libre HWM server host and port.
# server_host: "localhost"
# server_port: 8085

# Optional. If you enable auth in Libre HWM, set username and password and restart the server.
# server_username: "admin"
# server_password: "password"

callbacks:
on_left: "toggle_label"
on_middle: "do_nothing"
on_right: "do_nothing"
143 changes: 143 additions & 0 deletions src/core/validation/widgets/yasb/libre_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
DEFAULTS = {
'class_name': 'libre-monitor-widget',
'label': '<span>\udb82\udcae </span> {info[value]}{info[unit]}',
'label_alt': '<span>\uf437 </span>{info[histogram]} {info[value]} ({info[min]}/{info[max]}) {info[unit]}',
'update_interval': 1000,
'sensor_id': '/amdcpu/0/load/0',
'histogram_icons': [
r'\u2581',
r'\u2581',
r'\u2582',
r'\u2583',
r'\u2584',
r'\u2585',
r'\u2586',
r'\u2587',
r'\u2588'
],
'histogram_num_columns': 10,
'precision': 2,
'history_size': 60,
'histogram_fixed_min': None,
'histogram_fixed_max': None,
'server_host': 'localhost',
'server_port': 8085,
'server_username': '',
'server_password': '',
'callbacks': {
'on_left': 'toggle_label',
'on_middle': 'do_nothing',
'on_right': 'do_nothing'
},
}

VALIDATION_SCHEMA = {
'class_name': {
'type': 'string',
'default': DEFAULTS['class_name'],
'required': False,
},
'label': {
'type': 'string',
'default': DEFAULTS['label']
},
'label_alt': {
'type': 'string',
'default': DEFAULTS['label_alt']
},
'update_interval': {
'type': 'integer',
'default': DEFAULTS['update_interval'],
'min': 0,
'max': 60000
},
'sensor_id': {
'type': 'string',
'default': DEFAULTS['sensor_id'],
},
'histogram_icons': {
'type': 'list',
'default': DEFAULTS['histogram_icons'],
'minlength': 9,
'maxlength': 9,
"schema": {
'type': 'string'
}
},
'histogram_num_columns': {
'type': 'integer',
'default': DEFAULTS['histogram_num_columns'],
'min': 0,
'max': 128
},
'precision': {
'type': 'integer',
'default': DEFAULTS['precision'],
'min': 0,
'max': 30,
'required': False,
},
'history_size': {
'type': 'integer',
'default': DEFAULTS['history_size'],
'min': DEFAULTS["histogram_num_columns"],
'max': 50000,
'required': False,
},
'histogram_fixed_min': {
'type': 'float',
'default': DEFAULTS['histogram_fixed_min'],
'min': -10000.0,
'max': 10000.0,
'required': False,
'nullable': True
},
'histogram_fixed_max': {
'type': 'float',
'default': DEFAULTS['histogram_fixed_max'],
'min': -10000.0,
'max': 10000.0,
'required': False,
'nullable': True
},
'server_host': {
'type': 'string',
'default': DEFAULTS['server_host'],
'required': False,
},
'server_port': {
'type': 'integer',
'default': DEFAULTS['server_port'],
'min': 0,
'max': 65535,
'required': False,
},
'server_username': {
'type': 'string',
'default': DEFAULTS['server_username'],
'required': False,
},
'server_password': {
'type': 'string',
'default': DEFAULTS['server_password'],
'required': False,
},
'callbacks': {
'type': 'dict',
'schema': {
'on_left': {
'type': 'string',
'default': DEFAULTS['callbacks']['on_left'],
},
'on_middle': {
'type': 'string',
'default': DEFAULTS['callbacks']['on_middle'],
},
'on_right': {
'type': 'string',
'default': DEFAULTS['callbacks']['on_right'],
}
},
'default': DEFAULTS['callbacks']
}
}
Loading

0 comments on commit f63022b

Please sign in to comment.