Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ https://github.com/user-attachments/assets/aab8d8e8-248f-46a1-919c-9b0601236ac1
- **[GlazeWM Binding Mode](https://github.com/amnweb/yasb/wiki/(Widget)-GlazeWM-Binding-Mode)**: GlazeWM binding mode widget.
- **[GlazeWM Tiling Direction](https://github.com/amnweb/yasb/wiki/(Widget)-GlazeWM-Tiling-Direction)**: GlazeWM tiling direction widget.
- **[GlazeWM Workspaces](https://github.com/amnweb/yasb/wiki/(Widget)-GlazeWM-Workspaces)**: GlazeWM workspaces widget.
- **[Glucose Monitor](https://github.com/amnweb/yasb/wiki/(Widget)-Glucose-Monitor)**: Nightscout CGM Widget.
- **[Grouper](https://github.com/amnweb/yasb/wiki/(Widget)-Grouper)**: Groups multiple widgets together in a container.
- **[GPU](https://github.com/amnweb/yasb/wiki/(Widget)-GPU)**: Displays GPU utilization, temperature, and memory usage.
- **[Home](https://github.com/amnweb/yasb/wiki/(Widget)-Home)**: A customizable home widget menu.
Expand Down
Binary file added docs/assets/glucose_monitor_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 94 additions & 0 deletions docs/widgets/(Widget)-Glucose-Monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Glucose Monitor Widget

Nightscout (also known as CGM in the Cloud) is an open-source cloud application used by people with diabetes and parents
of kids with diabetes to visualize, store and share the data from their Continuous Glucose Monitoring sensors in
real-time. Once setup, Nightscout acts as a central repository of blood glucose and insulin dosing/treatment data for a
single person, allowing you to view the CGM graph and treatment data anywhere using just a web browser connected to the
internet.

There are several parts to this system. You need somewhere online to store, process and visualize this data (a
Nightscout Site), something to upload CGM data to your Nightscout (an Uploader), and then optionally you can use other
devices to access or view this data (one - or more - Follower).

Go to [Nightscout documentation](https://nightscout.github.io/nightscout/new_user/) for the details.

This widget allows you to monitor someone's blood sugar level
through [Nightscout CGM remote monitor](https://github.com/nightscout/cgm-remote-monitor) API.

| Option | Type | Default | Description |
|-------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `label` | string | `<span>\ud83e\ude78</span><span class='sgv'>{sgv}</span><span>{direction}</span>` | The format string for the widget. |
| `error_label` | string | `<span>\ud83e\ude78</span>{error_message}` | The format string for the error widget. |
| `tooltip` | string | `({sgv_delta}) {delta_time_in_minutes} min` | The format string for the tooltip. |
| `host` | string | `...` | The URL for your [Nightscout CGM remote monitor](https://github.com/nightscout/cgm-remote-monitor). |
| `secret` | string | `...` | The secret key for the CGM API. |
| `secret_env_name` | string | `...` | If the secret variable is equals to `env` then widget will try to get secret from the environment variable with a name of the `secret_env_name` value. |
| `direction_icons` | dict | `{"double_up": "\u2b06\ufe0f\u2b06\ufe0f", "single_up": "\u2b06\ufe0f", "forty_five_up": "\u2197\ufe0f", "flat": "\u27a1\ufe0f", "forty_five_down": "\u2198\ufe0f", "single_down": "\u2b07\ufe0f", "double_down": "\u2b07\ufe0f\u2b07\ufe0f"}` | Direction icon settings. |
| `sgv_measurement_units` | string | `mmol/l` | SGV measurement units can be `mg/dl` or `mmol/l`. |
| `callbacks` | dict | `{"on_left": "open_cgm", "on_middle": "do_nothing", "on_right": "do_nothing"}` | Callbacks for mouse events on the glucose monitor widget. |
| `notify_on_error` | boolean | `True` | Send a notification on error. |
| `label_shadow` | dict | `None` | Label shadow options. |
| `container_shadow` | dict | `None` | Container shadow options. |
| `sgv_range` | dict | `{"min": 4, "max": 9}` | Normal SGV range to append `in-range` or `out-range` CSS class for span with `.sgv` CSS class. |

## Example Configuration

```yaml
glucose_monitor:
type: "yasb.glucose_monitor.GlucoseMonitor"
options:
label: "<span>\ud83e\ude78</span><span class='sgv'>{sgv}</span><span>{direction}</span>"
error_label: "<span>\ud83e\ude78</span>{error_message}"
tooltip: "({sgv_delta}) {delta_time_in_minutes} min"
host: "https://your-domain.com"
secret: "env"
secret_env_name: "YASB_CGM_YOUR_SECRET_ENV_NAME"
sgv_measurement_units: "mmol/l"
sgv_range:
min: 4
max: 9
```

## Description of Options

- **label:** The format string for the widget.
- **error_label:** The format string for the error widget.
- **tooltip:** The format string for the tooltip.
- **host:** The URL for your [Nightscout CGM remote monitor](https://github.com/nightscout/cgm-remote-monitor).
- **secret:** The secret key for the CGM API.
- **secret_env_name:** If the secret variable is equals to `env` then widget will try to get secret from the environment variable with a name of the `secret_env_name` value.
- **direction_icons:** Direction icon settings.
- **sgv_measurement_units:** SGV measurement units can be `mg/dl` or `mmol/l`.
- **callbacks:** Callbacks for mouse events on the glucose monitor widget.
- **notify_on_error:** Send a notification on error.
- **label_shadow:** Label shadow options.
- **container_shadow:** Container shadow options.
- **sgv_range:** Normal SGV range to append `in-range` or `out-range` CSS class for span with `.sgv` CSS class.

## Example Style

```css
.cgm-widget {
padding: 0 4px 0 4px;
}

.cgm-widget .widget-container {
}
.cgm-widget .label {
}

.cgm-widget .sgv.in-range {
color: green;
}

.cgm-widget .sgv.out-range {
color: red;
}

.cgm-widget .icon {
}
```

## Preview of the Widget

![Glucose Monitor YASB Widget](assets/glucose_monitor_01.png)
152 changes: 152 additions & 0 deletions src/core/validation/widgets/yasb/glucose_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
DEFAULTS = {
"label": "<span>\ud83e\ude78<span><span class='sgv'>{sgv}</span><span>{direction}</span>",
"error_label": "<span>\ud83e\ude78</span>{error_message}",
"tooltip": "({sgv_delta}) {delta_time_in_minutes} min",
"host": "",
"secret": "",
"secret_env_name": "",
"direction_icons": {
"double_up": "\u2b06\ufe0f\u2b06\ufe0f",
"single_up": "\u2b06\ufe0f",
"forty_five_up": "\u2197\ufe0f",
"flat": "\u27a1\ufe0f",
"forty_five_down": "\u2198\ufe0f",
"single_down": "\u2b07\ufe0f",
"double_down": "\u2b07\ufe0f\u2b07\ufe0f",
},
"sgv_measurement_units": "mmol/l", # "mg/dl" or "mmol/l"
"callbacks": {"on_left": "open_cgm", "on_middle": "do_nothing", "on_right": "do_nothing"},
"notify_on_error": True,
"sgv_range": {
"min": 4,
"max": 9,
},
}

VALIDATION_SCHEMA = {
"label": {
"type": "string",
"required": False,
"default": DEFAULTS["label"],
},
"error_label": {
"type": "string",
"required": False,
"default": DEFAULTS["error_label"],
},
"tooltip": {
"type": "string",
"required": False,
"default": DEFAULTS["tooltip"],
},
"host": {
"type": "string",
"default": DEFAULTS["host"],
},
"secret": {
"type": "string",
"default": DEFAULTS["secret"],
},
"secret_env_name": {
"type": "string",
"required": False,
"default": DEFAULTS["secret_env_name"],
},
"direction_icons": {
"type": "dict",
"required": False,
"schema": {
"double_up": {
"type": "string",
"default": DEFAULTS["direction_icons"]["double_up"],
},
"single_up": {
"type": "string",
"default": DEFAULTS["direction_icons"]["single_up"],
},
"forty_five_up": {
"type": "string",
"default": DEFAULTS["direction_icons"]["forty_five_up"],
},
"flat": {
"type": "string",
"default": DEFAULTS["direction_icons"]["flat"],
},
"forty_five_down": {
"type": "string",
"default": DEFAULTS["direction_icons"]["forty_five_down"],
},
"single_down": {
"type": "string",
"default": DEFAULTS["direction_icons"]["single_down"],
},
"double_down": {
"type": "string",
"default": DEFAULTS["direction_icons"]["double_down"],
},
},
"default": DEFAULTS["direction_icons"],
},
"sgv_measurement_units": {
"type": "string",
"required": False,
"default": DEFAULTS["sgv_measurement_units"],
},
"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"],
},
"notify_on_error": {
"type": "boolean",
"required": False,
"default": DEFAULTS["notify_on_error"],
},
"label_shadow": {
"type": "dict",
"required": False,
"schema": {
"enabled": {"type": "boolean", "default": False},
"color": {"type": "string", "default": "black"},
"offset": {"type": "list", "default": [1, 1]},
"radius": {"type": "integer", "default": 3},
},
"default": {"enabled": False, "color": "black", "offset": [1, 1], "radius": 3},
},
"container_shadow": {
"type": "dict",
"required": False,
"schema": {
"enabled": {"type": "boolean", "default": False},
"color": {"type": "string", "default": "black"},
"offset": {"type": "list", "default": [1, 1]},
"radius": {"type": "integer", "default": 3},
},
"default": {"enabled": False, "color": "black", "offset": [1, 1], "radius": 3},
},
"sgv_range": {
"type": "dict",
"required": False,
"schema": {
"min": {"type": "float", "default": DEFAULTS["sgv_range"]["min"]},
"max": {"type": "float", "default": DEFAULTS["sgv_range"]["max"]},
},
"default": {
"min": DEFAULTS["sgv_range"]["min"],
"max": DEFAULTS["sgv_range"]["max"],
},
},
}
Loading