Skip to content

Conversation

@metamorph-dev
Copy link

This change will add a Glucose Monitor Widget which you can connect to the Nightscout CGM remote monitor

This widget allows you to see your or your nearest and dearest blood sugar level in real time

@Video-Nomad
Copy link
Contributor

Thanks for the pull request! Really cool widget idea. I don't think we can test it though, so I guess we will have to trust you that it works 😅

However, there's one slight problem - requests library. We explicitly removed it from YASB because it affected the startup time too much. It's a huge library to include just to get a request going. Please consider rewriting that part to urllib if possible.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from 3cc48d5 to 70ddba4 Compare October 16, 2025 12:51
Copy link
Contributor

@Video-Nomad Video-Nomad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments.

label: "🩸$sgv$direction"
tooltip: "($sgv_delta) $delta_time_in_minutes min"
host: "https://your-domain.com"
secret: "your-secret"
Copy link
Contributor

@Video-Nomad Video-Nomad Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting secret in the config is not a great idea. Using env var should be an option, similar to how weather widget or github widget handles these.

super().__init__(timer_interval=self.update_interval_in_milliseconds, class_name="cgm-widget")

self._label_content = label
self._label_template = Template(label)
Copy link
Contributor

@Video-Nomad Video-Nomad Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although using templates is definitely a valid approach, we are currently switching to format and format_map instead. So, the placeholders should be in the format {sgv} {direction} etc.

Check the #498 for similar approach. I don't know if that PR will be merged or not, but we are using curly braces in all the widget so this should be consistent.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch 2 times, most recently from 07b4cdb to ad6feb5 Compare October 16, 2025 14:44
@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 16, 2025

Now it supports environment variables and uses format_map.

I added secret_env_name in the configuration, 'cause it might not be a single widget of this type.

@amnweb
Copy link
Owner

amnweb commented Oct 16, 2025

YASB can read environment variables directly, like secret_env_name: "$env:SECRET", or from the .env file, so that’s no problem at all.
But I don’t understand this widget host: "https://your-domain.com". What exactly is host? I mean, it’s not clearly documented how to use this widget.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from ad6feb5 to 16eab0c Compare October 16, 2025 15:30
@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 16, 2025

Added a description for the widget in the wiki with the links for the Nightscout official documentation.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from 16eab0c to 41a94c1 Compare October 16, 2025 15:37
@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 16, 2025

I can give you my config for this widget with all the credentials so you can see how it looks.

After that of course I'll revoke my API keys.

@amnweb
Copy link
Owner

amnweb commented Oct 16, 2025

Added a description for the widget in the wiki with the links for the Nightscout official documentation.

OK, now it’s easier for me to understand what this widget is actually for. Thanks for the info!
I have a few more suggestions to keep the codebase clean: the data label/placeholder should be label: {sgv}{direction} instead of $sgv$direction.

You should remove the container_padding.

        self._widget_container_layout.setContentsMargins(
            self._padding["left"],
            self._padding["top"],
            self._padding["right"],
            self._padding["bottom"],
        )

It’s deprecated, and we’ll remove it from all widgets in the future, so there’s no need to create new widgets with this option, the style is available via CSS.
Also all widgets support shadow so you can add it using add_shadow.

And lastly, it’s better to keep icons as Unicode UTF-16 characters rather than as image icons.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch 5 times, most recently from 3d6928f to 6fcb3a4 Compare October 16, 2025 16:19
Copy link
Contributor

@Video-Nomad Video-Nomad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. There's no explicit icon/label separation as we have on other text-based widgets, but I don't know how important it is for this widget. This part as an example:

def _create_dynamically_label(self, content: str, content_alt: str):
def process_content(content, is_alt=False):
label_parts = re.split("(<span.*?>.*?</span>)", content)
widgets = []
for part in label_parts:
part = part.strip()
if not part:
continue
if "<span" in part and "</span>" in part:
class_name = re.search(r'class=(["\'])([^"\']+?)\1', part)
class_result = class_name.group(2) if class_name else "icon"
icon = re.sub(r"<span.*?>|</span>", "", part).strip()
label = QLabel(icon)
label.setProperty("class", class_result)
else:
label = QLabel(part)
label.setProperty("class", "label alt" if is_alt else "label")
label.setText(self._label_placeholder)
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self._set_cursor(label)
add_shadow(label, self._label_shadow)
self._widget_container_layout.addWidget(label)
widgets.append(label)
if is_alt:
label.hide()
else:
label.show()
return widgets
self._widgets = process_content(content)
self._widgets_alt = process_content(content_alt, is_alt=True)

Other than that, I see no issues at least on the surface.

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch 2 times, most recently from 908aa69 to 4219182 Compare October 17, 2025 09:41
@metamorph-dev
Copy link
Author

  • Rebased on the main branch
  • Added explicit icon/label separation
  • Added notification on error

@metamorph-dev
Copy link
Author

Is everything OK?
Do I need to add something more?

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from 4219182 to 0090ac9 Compare October 28, 2025 06:13
Copy link
Contributor

@Video-Nomad Video-Nomad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments

tooltip: "({sgv_delta}) {delta_time_in_minutes} min"
host: "https://your-domain.com"
secret: "env"
secret_env_name: "YASB_CGM_YOUR_SECRET_ENV_NAME"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

Copy link
Contributor

@Video-Nomad Video-Nomad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing add_shadow configuration

tooltip: "({sgv_delta}) {delta_time_in_minutes} min"
host: "https://your-domain.com"
secret: "env"
secret_env_name: "YASB_CGM_YOUR_SECRET_ENV_NAME"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from 0090ac9 to 5adda3d Compare October 28, 2025 09:45
@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 28, 2025

  • Added special setting notify_on_error to make notifications optional
  • Added explicit zeroed contents margin
  • Added .cgm-widget .icon style in CSS example documentation
  • Added <span> for icons in all places
  • Added label_shadow and container_shadow configuration
  • Added error label

@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from 5adda3d to fe5b6ad Compare October 28, 2025 10:24
@metamorph-dev metamorph-dev force-pushed the feat/glucose-monitor-widget branch from fe5b6ad to 7d86902 Compare October 28, 2025 12:31
@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 28, 2025

Added blood sugar level (sgv) css styling support for the label.

Now using <span class="sgv">{sgv}</span> in the label, in-range/out-range CSS styles, and sgv_range configuration, it is available to set preferred CSS styles based on whether the blood sugar level is in range or not.

For example: display a good blood sugar level with green color or with red color if it is bad.

image

@Video-Nomad
Copy link
Contributor

@metamorph-dev Can you attach a dummy response example? Just json. Remove all the personal or sensitive data, of course. Just to test how this widget would look like when the server is working as expected.

@metamorph-dev
Copy link
Author

metamorph-dev commented Oct 28, 2025

@metamorph-dev Can you attach a dummy response example? Just json. Remove all the personal or sensitive data, of course. Just to test how this widget would look like when the server is working as expected.

[
  {
    "_id": "6900db08b2b258d49270ca37",
    "device": "xDrip-LibreReceiver",
    "date": 1761663707057,
    "dateString": "2025-10-28T15:01:47.057Z",
    "sgv": 147,
    "delta": -2.997,
    "direction": "Flat",
    "type": "sgv",
    "filtered": 142000,
    "unfiltered": 142000,
    "rssi": 100,
    "noise": 1,
    "sysTime": "2025-10-28T15:01:47.057Z",
    "utcOffset": 60,
    "mills": 1761663707057
  }
]

The API stores sgv in mg/dl

Copy link
Contributor

@Video-Nomad Video-Nomad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Up to @amnweb to merge this of course. Thanks for the tweaks @metamorph-dev 👍

@amnweb
Copy link
Owner

amnweb commented Oct 29, 2025

Looks good to me as well, but since this PR will directly change the README, I won’t merge it until we’re ready to build the stable release. @metamorph-dev if you still need to change something, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants