Preserve float precision in Powerwall charge sensor (#181991)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
crt
2026-09-12 23:41:23 +02:00
committed by GitHub
co-authored by Copilot Autofix powered by AI
parent 180837806b
commit c14167f3a4
2 changed files with 12 additions and 4 deletions
+3 -2
View File
@@ -286,6 +286,7 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = PERCENTAGE
_attr_device_class = SensorDeviceClass.BATTERY
_attr_suggested_display_precision = 0
@property
@override
@@ -295,9 +296,9 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
@property
@override
def native_value(self) -> int:
def native_value(self) -> float:
"""Get the current value in percentage."""
return round(self.data.charge)
return self.data.charge
class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
+9 -2
View File
@@ -32,7 +32,11 @@ from tests.common import MockConfigEntry, async_fire_time_changed
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors(hass: HomeAssistant, device_registry: dr.DeviceRegistry) -> None:
async def test_sensors(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test creation of the sensors."""
mock_powerwall = await _mock_powerwall_with_fixtures(hass)
@@ -113,7 +117,10 @@ async def test_sensors(hass: HomeAssistant, device_registry: dr.DeviceRegistry)
assert float(hass.states.get("sensor.mysite_solar_import").state) == 28.2
state = hass.states.get("sensor.mysite_charge")
assert state.state == "47"
assert state.state == "47.34587394586"
entity_entry = entity_registry.async_get("sensor.mysite_charge")
assert entity_entry is not None
assert entity_entry.options["sensor"]["suggested_display_precision"] == 0
expected_attributes = {
"unit_of_measurement": PERCENTAGE,
"friendly_name": "MySite Charge",