Skip to content

Commit 5521b94

Browse files
authored
#6: Update icon border progress to 1.6.0 - invert progress support (#8)
1 parent 54062b0 commit 5521b94

File tree

8 files changed

+319
-242
lines changed

8 files changed

+319
-242
lines changed

modules/icon_border_progress/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
### v1.6.0
4+
5+
<details><summary>See Changes</summary>
6+
7+
- Added ability to invert progress using `invert: true`.
8+
9+
</details>
10+
311
### v1.5.0
412

513
<details><summary>See Changes</summary>

modules/icon_border_progress/CONFIG_OPTIONS.md

Lines changed: 266 additions & 237 deletions
Large diffs are not rendered by default.

modules/icon_border_progress/__tests__/code.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,24 @@ describe("icon_border_progress", () => {
279279
);
280280
});
281281

282+
it("should invert progress percentage correctly", () => {
283+
// setup
284+
mockHass.states["sensor.progress"].state = "75";
285+
mockThis.config.icon_border_progress[0].invert = true;
286+
287+
// exercise
288+
icon_border_progress.call(mockThis, mockCard, mockHass);
289+
290+
// Verify SVG helper was called with correct progress value (75%)
291+
expect(strokeDashProgress.createProgressBorder).toHaveBeenCalledWith(
292+
mockElement,
293+
25, // 25% progress
294+
"rgb(255, 255, 0)",
295+
"white",
296+
{ animationDuration: 800, borderRadiusOverride: undefined, offsetPercent: 0, strokeWidth: 3 },
297+
);
298+
});
299+
282300
// https://github.com/Clooos/Bubble-Card/discussions/1525#discussioncomment-13732526
283301
// Ensure inputs accept floats
284302
it("should calculate progress percentage correctly for floats", () => {

modules/icon_border_progress/__tests__/integration.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ describe("icon_border_progress - Integration Tests", () => {
437437
{
438438
button: "sub-button-1",
439439
source: "sensor.saros_10_battery",
440+
invert: true,
440441
start: "sensor.start_value",
441442
end: "sensor.end_value",
442443
color_stops: [
@@ -448,7 +449,7 @@ describe("icon_border_progress - Integration Tests", () => {
448449
},
449450
];
450451

451-
// Battery is at 75, with start=0 and end=200, progress should be 37.5%
452+
// Battery is at 75, with start=0 and end=200, and invert=true, progress should be 62.5%
452453
mockHass.states["sensor.saros_10_battery"].state = "75";
453454
mockHass.states["sensor.start_value"] = { state: "0" };
454455
mockHass.states["sensor.end_value"] = { state: "200" };
@@ -467,7 +468,7 @@ describe("icon_border_progress - Integration Tests", () => {
467468
const progressPath = svg.querySelector(".progress-path");
468469
expect(progressPath).toBeTruthy();
469470
expect(progressPath.getAttribute("stroke")).not.toBe("transparent");
470-
verifyStrokeDashArray(progressPath, 0, 0, 112.5, 187.5);
471+
verifyStrokeDashArray(progressPath, 0, 0, 187.5, 112.5);
471472
expect(subButton1.style.background).toBe("rgb(10, 10, 10)"); // JSDOM converts #0a0a0a to rgb
472473
});
473474

modules/icon_border_progress/code.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ export function icon_border_progress(card, hass) {
7676

7777
function updateProgressDisplay(progressSource, buttonConfig, buttonElement) {
7878
const progressValue = calculateProgressValue(progressSource, buttonConfig);
79+
const inverted = buttonConfig?.invert || false;
80+
const adjustedProgress = inverted ? 100 - progressValue : progressValue;
7981
const colorStops = buttonConfig.color_stops || [];
80-
const progressColor = resolveColorFromStops(progressValue, colorStops, buttonConfig.interpolate_colors);
82+
const progressColor = resolveColorFromStops(adjustedProgress, colorStops, buttonConfig.interpolate_colors);
8183
const colors = resolveColorConfigs(buttonConfig);
8284

83-
applyProgressStyling(buttonElement, progressValue, progressColor, colors, buttonConfig);
85+
applyProgressStyling(buttonElement, adjustedProgress, progressColor, colors, buttonConfig);
8486
}
8587

8688
// Main processing loop

modules/icon_border_progress/editor.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ editor:
2020
label: "✨Source entity"
2121
selector:
2222
entity: {}
23+
- name: invert
24+
label: "Invert the progress direction"
25+
selector:
26+
boolean:
27+
default: false
2328
- name: condition
2429
label: "Condition to show progress (see docs for additional condition configuration)"
2530
selector:
@@ -106,6 +111,11 @@ editor:
106111
label: "✨Source entity"
107112
selector:
108113
entity: {}
114+
- name: invert
115+
label: "Invert the progress direction"
116+
selector:
117+
boolean:
118+
default: false
109119
- name: condition
110120
label: "Condition to show progress (see docs for additional condition configuration)"
111121
selector:

modules/icon_border_progress/module.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module_info:
22
id: icon_border_progress
33
name: Icon Border Progress
4-
version: 1.5.0
4+
version: 1.6.0
55
creator: lsmarsden
66
link: >-
77
https://github.com/lsmarsden/bubble-card-modules/tree/main/icon_border_progress

modules/icon_border_progress/schema.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ items:
88

99
definitions:
1010
icon_progress_config:
11+
type: array
12+
items:
13+
$ref: "#/definitions/button_config"
14+
15+
button_config:
1116
type: object
1217
properties:
1318
button:
@@ -21,6 +26,10 @@ definitions:
2126
type: string
2227
description: "[DEPRECATED] Use 'source' instead. Source entity for progress value"
2328
format: "entity[attribute]"
29+
invert:
30+
type: boolean
31+
description: "Invert the progress direction (default: false)"
32+
default: false
2433
start:
2534
oneOf:
2635
- type: number

0 commit comments

Comments
 (0)