Skip to content

Commit 052d9c3

Browse files
Developer089claude
andcommitted
Show battery voltage to 2 decimal places
Add optional 'precision' register field -> suggested_display_precision, and set battery voltage (0.01 V resolution) to 2 decimals. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent af23b45 commit 052d9c3

4 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎custom_components/deye_modbus/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_REGISTER_FIELDS = {
2929
"name", "unique_id", "register_type", "address", "count", "scale", "offset",
3030
"unit_of_measurement", "device_class", "state_class", "signed", "word_order",
31-
"options", "mask", "icon", "enabled_default",
31+
"options", "mask", "icon", "enabled_default", "precision",
3232
}
3333

3434

‎custom_components/deye_modbus/coordinator.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class RegisterDef:
4545
mask: int | None = None # bitmask applied to raw before sign/scale
4646
icon: str | None = None
4747
enabled_default: bool = True # entity_registry_enabled_default
48+
precision: int | None = None # suggested_display_precision (decimals)
4849

4950

5051
class DeyeModbusCoordinator(DataUpdateCoordinator[dict[str, Any]]):

‎custom_components/deye_modbus/maps/sun_3ph_hybrid.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ sensors:
175175
address: 587
176176
count: 1
177177
scale: 0.01
178+
precision: 2
178179
unit_of_measurement: V
179180
device_class: voltage
180181
state_class: measurement

‎custom_components/deye_modbus/sensor.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(self, coordinator: DeyeModbusCoordinator, entry: ConfigEntry, reg:
4040
self._attr_device_info = build_device_info(entry)
4141
self._attr_native_unit_of_measurement = reg.unit_of_measurement
4242
self._attr_entity_registry_enabled_default = bool(reg.enabled_default)
43+
if reg.precision is not None:
44+
self._attr_suggested_display_precision = int(reg.precision)
4345
if reg.icon:
4446
self._attr_icon = reg.icon
4547
if reg.device_class:

0 commit comments

Comments
 (0)