diff --git a/homeassistant/components/wallbox/__init__.py b/homeassistant/components/wallbox/__init__.py index e5c8b7719a3a5ef0e48e5db9c902708741d0e5be..410a3115f9fe9fb3208ebdfcd6fae0a21f8f85e5 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 4a403d0afc8390650f4802052cfbed1924854229..f8031bd86a4991648d6fc672acf5e5ac1a08a7ca 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 3aa2dde38f022c89fee89389741a1519848e11fa..9777602f6c9083245986307947e84b752cabb4b7 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 41dcd0e6ee00894f156407627b8fe1ec23e2b15b..2551eed6a2efe4a7ee2b259c9343345dcc220f80 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)