Skip to content

Commit ada12d4

Browse files
authored
Merge pull request #573 from swingerman/swingerman/issue567
fix: Handle decimal values < 1.0 in full_value attribute (fixes #567)
2 parents c6becf7 + af81c1c commit ada12d4

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

.github/copilot-instructions.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ interface Severity {
109109

110110
### Local Testing Environment
111111

112-
- Home Assistant runs in dev container on port 9123
112+
- Home Assistant runs in dev container on port 8123
113113
- Card served from Rollup dev server on port 5000
114114
- Test entities defined in `config/configuration.yaml` (input_number, input_boolean)
115+
- start home assistant:
116+
117+
```bash
118+
./scripts/develop
119+
```
115120

116121
### Common Issues
117122

config/configuration.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ input_number:
1313
max: 100
1414
step: .5
1515
icon: hass:battery
16+
17+
energy_consumption:
18+
name: Today's Energy Consumption
19+
initial: 0.95
20+
min: 0
21+
max: 2.0
22+
step: 0.01
23+
unit_of_measurement: "kWh"
24+
icon: mdi:lightning-bolt
1625

1726
input_boolean:
1827
battery_charging:

config/ui-lovelace.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@ views:
22
- cards:
33
- type: custom:fluid-level-background-card
44
name: Fluid Level Background Card
5-
entity: input_number.battery_evel
5+
entity: input_number.battery_level
66
test_gui: true
7+
8+
# Test case for issue #567 - decimal values less than 1.0
9+
- type: custom:fluid-level-background-card
10+
card:
11+
type: tile
12+
entity: input_number.energy_consumption
13+
features_position: bottom
14+
vertical: true
15+
hide_state: false
16+
show_entity_picture: false
17+
icon: mdi:lightning-bolt
18+
name: Today's Energy Consumption
19+
full_value: 1.8
20+
entity: input_number.energy_consumption
21+
722
- type: entities
823
entities:
924
- input_number.battery_level
10-
- input_number.battery_charging
25+
- input_boolean.battery_charging
26+
- input_number.energy_consumption

src/fluid-level-background-card.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ export class FluidLevelBackgroundCard extends LitElement {
417417
safeEntityValue = entityValue;
418418
}
419419
if (typeof entityValue === 'string') {
420-
safeEntityValue = isNaN(parseInt(entityValue, 10)) ? 0 : parseInt(entityValue, 10);
420+
safeEntityValue = isNaN(parseFloat(entityValue)) ? 0 : parseFloat(entityValue);
421421
}
422422

423-
if (safeEntityValue > 0) {
424-
// calcualte the percentage bsed on the full value
423+
if (safeEntityValue >= 0) {
424+
// calculate the percentage based on the full value
425425
return (safeEntityValue / this._full_value) * 100;
426426
}
427427
return 0;

0 commit comments

Comments
 (0)