Skip to content

Commit 4c46b5b

Browse files
committed
Fix default and 0 precision values
1 parent be28235 commit 4c46b5b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Version: 1.0.6 20241222 - Added 14 day change and 1 year change
2626
Version: 1.0.7 20241227 - Added ath_price, ath_date and ath_change
2727
Version: 1.0.8 20260317 - Updated code to support future Home Assistant versions
2828
Version: 1.0.9 20260322 - Optional CoinGecko API price precision (config + /coins/markets)
29+
Version: 1.0.10 20260323 - Fix default and 0 precision values

custom_components/cryptoinfo/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "cryptoinfo",
33
"name": "Cryptoinfo",
4-
"version": "1.0.9",
4+
"version": "1.0.10",
55
"config_flow": true,
66
"iot_class": "cloud_polling",
77
"documentation": "https://github.com/heyajohnny/cryptoinfo",

custom_components/cryptoinfo/sensor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,15 @@ def __init__(
306306
def native_value(self):
307307
"""Return the native value of the sensor."""
308308
if self.coordinator.data and self.cryptocurrency_id in self.coordinator.data:
309-
return float(
309+
value = float(
310310
self.coordinator.data[self.cryptocurrency_id]["current_price"]
311311
) * float(self.multiplier)
312+
# Keep integer display when there are no decimals (or precision=0).
313+
if self._api_precision == "0":
314+
return int(round(value))
315+
if self._api_precision == "" and value.is_integer():
316+
return int(value)
317+
return value
312318
return None
313319

314320
@property

0 commit comments

Comments
 (0)