From b04a65f4d1d66f8f170c6085d9748cf45b086b40 Mon Sep 17 00:00:00 2001 From: Richard Kroegel <42204099+rikroe@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:25:45 +0200 Subject: [PATCH] Change BMW select and sensor enums to lowercase (#118751) Co-authored-by: Richard --- .../components/bmw_connected_drive/select.py | 4 +-- .../components/bmw_connected_drive/sensor.py | 4 --- .../bmw_connected_drive/strings.json | 22 ++++++++++++-- .../snapshots/test_select.ambr | 30 +++++++++---------- .../snapshots/test_sensor.ambr | 6 ++-- .../bmw_connected_drive/test_select.py | 10 +++---- 6 files changed, 45 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/bmw_connected_drive/select.py b/homeassistant/components/bmw_connected_drive/select.py index 409002b48e9..db54627b5b6 100644 --- a/homeassistant/components/bmw_connected_drive/select.py +++ b/homeassistant/components/bmw_connected_drive/select.py @@ -52,8 +52,8 @@ SELECT_TYPES: dict[str, BMWSelectEntityDescription] = { key="charging_mode", translation_key="charging_mode", is_available=lambda v: v.is_charging_plan_supported, - options=[c.value for c in ChargingMode if c != ChargingMode.UNKNOWN], - current_option=lambda v: str(v.charging_profile.charging_mode.value), # type: ignore[union-attr] + options=[c.value.lower() for c in ChargingMode if c != ChargingMode.UNKNOWN], + current_option=lambda v: str(v.charging_profile.charging_mode.value).lower(), # type: ignore[union-attr] remote_service=lambda v, o: v.remote_services.trigger_charging_profile_update( charging_mode=ChargingMode(o) ), diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index e7f56075e63..34169817f47 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -221,9 +221,5 @@ class BMWSensor(BMWBaseEntity, SensorEntity): if state == STATE_UNKNOWN: state = None - # special handling for charging_status to avoid a breaking change - if self.entity_description.key == "charging_status" and state: - state = state.upper() - self._attr_native_value = state super()._handle_coordinator_update() diff --git a/homeassistant/components/bmw_connected_drive/strings.json b/homeassistant/components/bmw_connected_drive/strings.json index 539c281a1a5..587b13f084d 100644 --- a/homeassistant/components/bmw_connected_drive/strings.json +++ b/homeassistant/components/bmw_connected_drive/strings.json @@ -83,7 +83,11 @@ "name": "AC Charging Limit" }, "charging_mode": { - "name": "Charging Mode" + "name": "Charging Mode", + "state": { + "immediate_charging": "Immediate charging", + "delayed_charging": "Delayed charging" + } } }, "sensor": { @@ -97,7 +101,21 @@ "name": "Charging end time" }, "charging_status": { - "name": "Charging status" + "name": "Charging status", + "state": { + "default": "Default", + "charging": "Charging", + "error": "Error", + "complete": "Complete", + "fully_charged": "Fully charged", + "finished_fully_charged": "Finished, fully charged", + "finished_not_full": "Finished, not full", + "invalid": "Invalid", + "not_charging": "Not charging", + "plugged_in": "Plugged in", + "waiting_for_charging": "Waiting for charging", + "target_reached": "Target reached" + } }, "charging_target": { "name": "Charging target" diff --git a/tests/components/bmw_connected_drive/snapshots/test_select.ambr b/tests/components/bmw_connected_drive/snapshots/test_select.ambr index 94155598ef7..34a8817c8db 100644 --- a/tests/components/bmw_connected_drive/snapshots/test_select.ambr +++ b/tests/components/bmw_connected_drive/snapshots/test_select.ambr @@ -6,8 +6,8 @@ 'area_id': None, 'capabilities': dict({ 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'config_entry_id': , @@ -43,8 +43,8 @@ 'attribution': 'Data provided by MyBMW', 'friendly_name': 'i3 (+ REX) Charging Mode', 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'context': , @@ -52,7 +52,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'DELAYED_CHARGING', + 'state': 'delayed_charging', }) # --- # name: test_entity_state_attrs[select.i4_edrive40_ac_charging_limit-entry] @@ -141,8 +141,8 @@ 'area_id': None, 'capabilities': dict({ 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'config_entry_id': , @@ -178,8 +178,8 @@ 'attribution': 'Data provided by MyBMW', 'friendly_name': 'i4 eDrive40 Charging Mode', 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'context': , @@ -187,7 +187,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'IMMEDIATE_CHARGING', + 'state': 'immediate_charging', }) # --- # name: test_entity_state_attrs[select.ix_xdrive50_ac_charging_limit-entry] @@ -276,8 +276,8 @@ 'area_id': None, 'capabilities': dict({ 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'config_entry_id': , @@ -313,8 +313,8 @@ 'attribution': 'Data provided by MyBMW', 'friendly_name': 'iX xDrive50 Charging Mode', 'options': list([ - 'IMMEDIATE_CHARGING', - 'DELAYED_CHARGING', + 'immediate_charging', + 'delayed_charging', ]), }), 'context': , @@ -322,6 +322,6 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'IMMEDIATE_CHARGING', + 'state': 'immediate_charging', }) # --- diff --git a/tests/components/bmw_connected_drive/snapshots/test_sensor.ambr b/tests/components/bmw_connected_drive/snapshots/test_sensor.ambr index 3455a4599b5..eaa33038baf 100644 --- a/tests/components/bmw_connected_drive/snapshots/test_sensor.ambr +++ b/tests/components/bmw_connected_drive/snapshots/test_sensor.ambr @@ -191,7 +191,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'WAITING_FOR_CHARGING', + 'state': 'waiting_for_charging', }) # --- # name: test_entity_state_attrs[sensor.i3_rex_charging_target-entry] @@ -822,7 +822,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'NOT_CHARGING', + 'state': 'not_charging', }) # --- # name: test_entity_state_attrs[sensor.i4_edrive40_charging_target-entry] @@ -1350,7 +1350,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'CHARGING', + 'state': 'charging', }) # --- # name: test_entity_state_attrs[sensor.ix_xdrive50_charging_target-entry] diff --git a/tests/components/bmw_connected_drive/test_select.py b/tests/components/bmw_connected_drive/test_select.py index 37aea4e0839..55e19482ef6 100644 --- a/tests/components/bmw_connected_drive/test_select.py +++ b/tests/components/bmw_connected_drive/test_select.py @@ -42,15 +42,15 @@ async def test_entity_state_attrs( [ ( "select.i3_rex_charging_mode", - "IMMEDIATE_CHARGING", - "DELAYED_CHARGING", + "immediate_charging", + "delayed_charging", "charging-profile", ), ("select.i4_edrive40_ac_charging_limit", "12", "16", "charging-settings"), ( "select.i4_edrive40_charging_mode", - "DELAYED_CHARGING", - "IMMEDIATE_CHARGING", + "delayed_charging", + "immediate_charging", "charging-profile", ), ], @@ -87,7 +87,7 @@ async def test_service_call_success( ("entity_id", "value"), [ ("select.i4_edrive40_ac_charging_limit", "17"), - ("select.i4_edrive40_charging_mode", "BONKERS_MODE"), + ("select.i4_edrive40_charging_mode", "bonkers_mode"), ], ) async def test_service_call_invalid_input(