-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add Glucose Monitor Widget #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Glucose Monitor Widget #503
Conversation
|
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 - |
3cc48d5 to
70ddba4
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
07b4cdb to
ad6feb5
Compare
|
Now it supports environment variables and uses I added |
|
YASB can read environment variables directly, like |
ad6feb5 to
16eab0c
Compare
|
Added a description for the widget in the wiki with the links for the Nightscout official documentation. |
16eab0c to
41a94c1
Compare
|
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. |
OK, now it’s easier for me to understand what this widget is actually for. Thanks for the info! You should remove the 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. And lastly, it’s better to keep icons as Unicode UTF-16 characters rather than as image icons. |
3d6928f to
6fcb3a4
Compare
There was a problem hiding this 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:
yasb/src/core/widgets/yasb/custom.py
Lines 137 to 168 in 0919bbb
| 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.
908aa69 to
4219182
Compare
|
|
Is everything OK? |
4219182 to
0090ac9
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly
0090ac9 to
5adda3d
Compare
|
5adda3d to
fe5b6ad
Compare
fe5b6ad to
7d86902
Compare
|
@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 |
There was a problem hiding this 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 👍
|
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. |
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