From c68149c75bceb5cc75c60416fda6a424463133e4 Mon Sep 17 00:00:00 2001 From: Hessel Date: Wed, 23 Nov 2022 11:25:21 +0100 Subject: [PATCH] Fix Wallbox price unit (#82420) * Change Symbol to Currency code in test * change unit to currency/kWh * f string --- homeassistant/components/wallbox/__init__.py | 8 +++++--- homeassistant/components/wallbox/const.py | 1 + homeassistant/components/wallbox/sensor.py | 7 ++++--- tests/components/wallbox/__init__.py | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/wallbox/__init__.py b/homeassistant/components/wallbox/__init__.py index 9a133b1794a..b5e935c27f1 100644 --- a/homeassistant/components/wallbox/__init__.py +++ b/homeassistant/components/wallbox/__init__.py @@ -33,6 +33,7 @@ from .const import ( CHARGER_SOFTWARE_KEY, CHARGER_STATUS_DESCRIPTION_KEY, CHARGER_STATUS_ID_KEY, + CODE_KEY, CONF_STATION, DOMAIN, ChargerStatus, @@ -129,9 +130,10 @@ class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]): data[CHARGER_ENERGY_PRICE_KEY] = data[CHARGER_DATA_KEY][ CHARGER_ENERGY_PRICE_KEY ] - data[CHARGER_CURRENCY_KEY] = data[CHARGER_DATA_KEY][CHARGER_CURRENCY_KEY][ - "code" - ] + data[ + CHARGER_CURRENCY_KEY + ] = f"{data[CHARGER_DATA_KEY][CHARGER_CURRENCY_KEY][CODE_KEY]}/kWh" + data[CHARGER_STATUS_DESCRIPTION_KEY] = CHARGER_STATUS.get( data[CHARGER_STATUS_ID_KEY], ChargerStatus.UNKNOWN ) diff --git a/homeassistant/components/wallbox/const.py b/homeassistant/components/wallbox/const.py index d7ee2dbb388..a6f92541a10 100644 --- a/homeassistant/components/wallbox/const.py +++ b/homeassistant/components/wallbox/const.py @@ -5,6 +5,7 @@ DOMAIN = "wallbox" BIDIRECTIONAL_MODEL_PREFIXES = ["QSX"] +CODE_KEY = "code" CONF_STATION = "station" CHARGER_ADDED_DISCHARGED_ENERGY_KEY = "added_discharged_energy" CHARGER_ADDED_ENERGY_KEY = "added_energy" diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index f44f5ea6aaa..9ce76d59608 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -129,7 +129,6 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { icon="mdi:ev-station", name="Depot Price", precision=2, - device_class=SensorDeviceClass.MONETARY, state_class=SensorStateClass.MEASUREMENT, ), CHARGER_ENERGY_PRICE_KEY: WallboxSensorEntityDescription( @@ -137,7 +136,6 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { icon="mdi:ev-station", name="Energy Price", precision=2, - device_class=SensorDeviceClass.MONETARY, state_class=SensorStateClass.MEASUREMENT, ), CHARGER_STATUS_DESCRIPTION_KEY: WallboxSensorEntityDescription( @@ -204,6 +202,9 @@ class WallboxSensor(WallboxEntity, SensorEntity): @property def native_unit_of_measurement(self) -> str | None: """Return the unit of measurement of the sensor. When monetary, get the value from the api.""" - if self.entity_description.device_class == SensorDeviceClass.MONETARY: + if self.entity_description.key in ( + CHARGER_ENERGY_PRICE_KEY, + CHARGER_DEPOT_PRICE_KEY, + ): return cast(str, self.coordinator.data[CHARGER_CURRENCY_KEY]) return cast(str, self.entity_description.native_unit_of_measurement) diff --git a/tests/components/wallbox/__init__.py b/tests/components/wallbox/__init__.py index ef72f556a8c..ed20e01cb2c 100644 --- a/tests/components/wallbox/__init__.py +++ b/tests/components/wallbox/__init__.py @@ -49,7 +49,7 @@ test_response = json.loads( CHARGER_SERIAL_NUMBER_KEY: "20000", CHARGER_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E", CHARGER_SOFTWARE_KEY: {CHARGER_CURRENT_VERSION_KEY: "5.5.10"}, - CHARGER_CURRENCY_KEY: {"code": "€"}, + CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"}, }, } )