diff --git a/homeassistant/components/powerwall/sensor.py b/homeassistant/components/powerwall/sensor.py index c5a580d648dd..b7ad9aad86bb 100644 --- a/homeassistant/components/powerwall/sensor.py +++ b/homeassistant/components/powerwall/sensor.py @@ -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): diff --git a/tests/components/powerwall/test_sensor.py b/tests/components/powerwall/test_sensor.py index 9e040e6615f9..855720e60a21 100644 --- a/tests/components/powerwall/test_sensor.py +++ b/tests/components/powerwall/test_sensor.py @@ -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",