diff --git a/homeassistant/components/wallbox/__init__.py b/homeassistant/components/wallbox/__init__.py index e5c8b7719a3..410a3115f9f 100644 --- a/homeassistant/components/wallbox/__init__.py +++ b/homeassistant/components/wallbox/__init__.py @@ -75,7 +75,7 @@ class WallboxCoordinator(DataUpdateCoordinator): filtered_data = {k: data[k] for k in CONF_SENSOR_TYPES if k in data} for key, value in filtered_data.items(): - if sensor_round := CONF_SENSOR_TYPES[key][CONF_ROUND]: + if (sensor_round := CONF_SENSOR_TYPES[key][CONF_ROUND]) is not None: try: filtered_data[key] = round(value, sensor_round) except TypeError: diff --git a/tests/components/wallbox/__init__.py b/tests/components/wallbox/__init__.py index 4a403d0afc8..f8031bd86a4 100644 --- a/tests/components/wallbox/__init__.py +++ b/tests/components/wallbox/__init__.py @@ -31,7 +31,7 @@ test_response = json.loads( json.dumps( { CONF_CHARGING_POWER_KEY: 0, - CONF_MAX_AVAILABLE_POWER_KEY: 25, + CONF_MAX_AVAILABLE_POWER_KEY: 25.2, CONF_CHARGING_SPEED_KEY: 0, CONF_ADDED_RANGE_KEY: "xx", CONF_ADDED_ENERGY_KEY: "44.697", diff --git a/tests/components/wallbox/const.py b/tests/components/wallbox/const.py index 3aa2dde38f0..9777602f6c9 100644 --- a/tests/components/wallbox/const.py +++ b/tests/components/wallbox/const.py @@ -8,3 +8,4 @@ CONF_STATUS = "status" CONF_MOCK_NUMBER_ENTITY_ID = "number.mock_title_max_charging_current" CONF_MOCK_SENSOR_CHARGING_SPEED_ID = "sensor.mock_title_charging_speed" CONF_MOCK_SENSOR_CHARGING_POWER_ID = "sensor.mock_title_charging_power" +CONF_MOCK_SENSOR_MAX_AVAILABLE_POWER = "sensor.mock_title_max_available_power" diff --git a/tests/components/wallbox/test_sensor.py b/tests/components/wallbox/test_sensor.py index 41dcd0e6ee0..2551eed6a2e 100644 --- a/tests/components/wallbox/test_sensor.py +++ b/tests/components/wallbox/test_sensor.py @@ -5,6 +5,7 @@ from tests.components.wallbox import entry, setup_integration from tests.components.wallbox.const import ( CONF_MOCK_SENSOR_CHARGING_POWER_ID, CONF_MOCK_SENSOR_CHARGING_SPEED_ID, + CONF_MOCK_SENSOR_MAX_AVAILABLE_POWER, ) @@ -21,4 +22,8 @@ async def test_wallbox_sensor_class(hass): assert state.attributes[CONF_ICON] == "mdi:speedometer" assert state.name == "Mock Title Charging Speed" + # Test round with precision '0' works + state = hass.states.get(CONF_MOCK_SENSOR_MAX_AVAILABLE_POWER) + assert state.state == "25.0" + await hass.config_entries.async_unload(entry.entry_id)