From 8efb9dad7e749ca93a5f8a2bee18117f656a904d Mon Sep 17 00:00:00 2001 From: Emma Vanbrabant Date: Wed, 16 Aug 2023 08:42:38 +0100 Subject: [PATCH] Add device_class to Renault charging remaining time (#98393) * Add device_class on charging remaining time Set `device_class to `duration` on the `charging_remaining_time` entity in the Renault integration. I had some issues showing this property on my dashboard, and setting this fixed it. The recommendation to open an issue against the original integration in these kinds of cases came from [here](https://community.home-assistant.io/t/how-to-format-a-card-to-show-hours-instead-of-seconds/425473/7). * Update test const to add duration * fix other cars * Update test_sensor.ambr * add duration in ambr --- homeassistant/components/renault/sensor.py | 1 + tests/components/renault/const.py | 3 +++ .../renault/snapshots/test_sensor.ambr | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 050c5a930f6..92deb3438de 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -190,6 +190,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( key="charging_remaining_time", coordinator="battery", data_key="chargingRemainingTime", + device_class=SensorDeviceClass.DURATION, entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], icon="mdi:timer", native_unit_of_measurement=UnitOfTime.MINUTES, diff --git a/tests/components/renault/const.py b/tests/components/renault/const.py index 4b2a7dfc72b..342ab803f33 100644 --- a/tests/components/renault/const.py +++ b/tests/components/renault/const.py @@ -198,6 +198,7 @@ MOCK_VEHICLES = { ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.KILO_WATT, }, { + ATTR_DEVICE_CLASS: SensorDeviceClass.DURATION, ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", ATTR_STATE: "145", @@ -433,6 +434,7 @@ MOCK_VEHICLES = { ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.KILO_WATT, }, { + ATTR_DEVICE_CLASS: SensorDeviceClass.DURATION, ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", ATTR_STATE: STATE_UNKNOWN, @@ -668,6 +670,7 @@ MOCK_VEHICLES = { ATTR_UNIT_OF_MEASUREMENT: UnitOfPower.KILO_WATT, }, { + ATTR_DEVICE_CLASS: SensorDeviceClass.DURATION, ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time", ATTR_ICON: "mdi:timer", ATTR_STATE: "145", diff --git a/tests/components/renault/snapshots/test_sensor.ambr b/tests/components/renault/snapshots/test_sensor.ambr index b4e2f105b3b..46b231ac7ef 100644 --- a/tests/components/renault/snapshots/test_sensor.ambr +++ b/tests/components/renault/snapshots/test_sensor.ambr @@ -404,7 +404,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -811,6 +811,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': , @@ -1100,7 +1101,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -1505,6 +1506,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': , @@ -1790,7 +1792,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -2223,6 +2225,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': , @@ -2803,7 +2806,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -3210,6 +3213,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': , @@ -3499,7 +3503,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -3904,6 +3908,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': , @@ -4189,7 +4194,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': 'mdi:timer', 'original_name': 'Charging remaining time', 'platform': 'renault', @@ -4622,6 +4627,7 @@ }), StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'REG-NUMBER Charging remaining time', 'icon': 'mdi:timer', 'state_class': ,