diff --git a/homeassistant/components/wallbox/__init__.py b/homeassistant/components/wallbox/__init__.py index d927e7282ed..9a133b1794a 100644 --- a/homeassistant/components/wallbox/__init__.py +++ b/homeassistant/components/wallbox/__init__.py @@ -21,8 +21,10 @@ from homeassistant.helpers.update_coordinator import ( ) from .const import ( + CHARGER_CURRENCY_KEY, CHARGER_CURRENT_VERSION_KEY, CHARGER_DATA_KEY, + CHARGER_ENERGY_PRICE_KEY, CHARGER_LOCKED_UNLOCKED_KEY, CHARGER_MAX_CHARGING_CURRENT_KEY, CHARGER_NAME_KEY, @@ -124,6 +126,12 @@ class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]): data[CHARGER_LOCKED_UNLOCKED_KEY] = data[CHARGER_DATA_KEY][ CHARGER_LOCKED_UNLOCKED_KEY ] + 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_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 9d1db637879..d7ee2dbb388 100644 --- a/homeassistant/components/wallbox/const.py +++ b/homeassistant/components/wallbox/const.py @@ -15,8 +15,10 @@ CHARGER_CHARGING_TIME_KEY = "charging_time" CHARGER_COST_KEY = "cost" CHARGER_CURRENT_MODE_KEY = "current_mode" CHARGER_CURRENT_VERSION_KEY = "currentVersion" +CHARGER_CURRENCY_KEY = "currency" CHARGER_DATA_KEY = "config_data" CHARGER_DEPOT_PRICE_KEY = "depot_price" +CHARGER_ENERGY_PRICE_KEY = "energy_price" CHARGER_SERIAL_NUMBER_KEY = "serial_number" CHARGER_PART_NUMBER_KEY = "part_number" CHARGER_SOFTWARE_KEY = "software" diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index 1fae68da2e4..f44f5ea6aaa 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -31,9 +31,11 @@ from .const import ( CHARGER_CHARGING_POWER_KEY, CHARGER_CHARGING_SPEED_KEY, CHARGER_COST_KEY, + CHARGER_CURRENCY_KEY, CHARGER_CURRENT_MODE_KEY, CHARGER_DATA_KEY, CHARGER_DEPOT_PRICE_KEY, + CHARGER_ENERGY_PRICE_KEY, CHARGER_MAX_AVAILABLE_POWER_KEY, CHARGER_MAX_CHARGING_CURRENT_KEY, CHARGER_SERIAL_NUMBER_KEY, @@ -127,6 +129,16 @@ 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( + key=CHARGER_ENERGY_PRICE_KEY, + icon="mdi:ev-station", + name="Energy Price", + precision=2, + device_class=SensorDeviceClass.MONETARY, + state_class=SensorStateClass.MEASUREMENT, ), CHARGER_STATUS_DESCRIPTION_KEY: WallboxSensorEntityDescription( key=CHARGER_STATUS_DESCRIPTION_KEY, @@ -188,3 +200,10 @@ class WallboxSensor(WallboxEntity, SensorEntity): round(self.coordinator.data[self.entity_description.key], sensor_round), ) return cast(StateType, self.coordinator.data[self.entity_description.key]) + + @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: + 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 53af3b6383d..ef72f556a8c 100644 --- a/tests/components/wallbox/__init__.py +++ b/tests/components/wallbox/__init__.py @@ -10,8 +10,10 @@ from homeassistant.components.wallbox.const import ( CHARGER_ADDED_RANGE_KEY, CHARGER_CHARGING_POWER_KEY, CHARGER_CHARGING_SPEED_KEY, + CHARGER_CURRENCY_KEY, CHARGER_CURRENT_VERSION_KEY, CHARGER_DATA_KEY, + CHARGER_ENERGY_PRICE_KEY, CHARGER_LOCKED_UNLOCKED_KEY, CHARGER_MAX_AVAILABLE_POWER_KEY, CHARGER_MAX_CHARGING_CURRENT_KEY, @@ -42,10 +44,12 @@ test_response = json.loads( CHARGER_NAME_KEY: "WallboxName", CHARGER_DATA_KEY: { CHARGER_MAX_CHARGING_CURRENT_KEY: 24, + CHARGER_ENERGY_PRICE_KEY: 0.4, CHARGER_LOCKED_UNLOCKED_KEY: False, 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": "€"}, }, } )