From 844a1ebbc6c16b612bb3ebb4ab388ed90577864f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 26 Jun 2023 18:57:56 +0200 Subject: [PATCH] Add entity translations to BMW Connected Drive (#95142) --- .../bmw_connected_drive/binary_sensor.py | 16 +-- .../components/bmw_connected_drive/button.py | 10 +- .../components/bmw_connected_drive/lock.py | 2 +- .../components/bmw_connected_drive/number.py | 2 +- .../components/bmw_connected_drive/select.py | 4 +- .../components/bmw_connected_drive/sensor.py | 24 ++-- .../bmw_connected_drive/strings.json | 109 ++++++++++++++++++ .../components/bmw_connected_drive/switch.py | 4 +- 8 files changed, 140 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/bmw_connected_drive/binary_sensor.py b/homeassistant/components/bmw_connected_drive/binary_sensor.py index 6fd5f3e76938d8..c3be7ae189b6df 100644 --- a/homeassistant/components/bmw_connected_drive/binary_sensor.py +++ b/homeassistant/components/bmw_connected_drive/binary_sensor.py @@ -123,7 +123,7 @@ class BMWBinarySensorEntityDescription( SENSOR_TYPES: tuple[BMWBinarySensorEntityDescription, ...] = ( BMWBinarySensorEntityDescription( key="lids", - name="Lids", + translation_key="lids", device_class=BinarySensorDeviceClass.OPENING, icon="mdi:car-door-lock", # device class opening: On means open, Off means closed @@ -134,7 +134,7 @@ class BMWBinarySensorEntityDescription( ), BMWBinarySensorEntityDescription( key="windows", - name="Windows", + translation_key="windows", device_class=BinarySensorDeviceClass.OPENING, icon="mdi:car-door", # device class opening: On means open, Off means closed @@ -145,7 +145,7 @@ class BMWBinarySensorEntityDescription( ), BMWBinarySensorEntityDescription( key="door_lock_state", - name="Door lock state", + translation_key="door_lock_state", device_class=BinarySensorDeviceClass.LOCK, icon="mdi:car-key", # device class lock: On means unlocked, Off means locked @@ -158,7 +158,7 @@ class BMWBinarySensorEntityDescription( ), BMWBinarySensorEntityDescription( key="condition_based_services", - name="Condition based services", + translation_key="condition_based_services", device_class=BinarySensorDeviceClass.PROBLEM, icon="mdi:wrench", # device class problem: On means problem detected, Off means no problem @@ -167,7 +167,7 @@ class BMWBinarySensorEntityDescription( ), BMWBinarySensorEntityDescription( key="check_control_messages", - name="Check control messages", + translation_key="check_control_messages", device_class=BinarySensorDeviceClass.PROBLEM, icon="mdi:car-tire-alert", # device class problem: On means problem detected, Off means no problem @@ -177,7 +177,7 @@ class BMWBinarySensorEntityDescription( # electric BMWBinarySensorEntityDescription( key="charging_status", - name="Charging status", + translation_key="charging_status", device_class=BinarySensorDeviceClass.BATTERY_CHARGING, icon="mdi:ev-station", # device class power: On means power detected, Off means no power @@ -185,14 +185,14 @@ class BMWBinarySensorEntityDescription( ), BMWBinarySensorEntityDescription( key="connection_status", - name="Connection status", + translation_key="connection_status", device_class=BinarySensorDeviceClass.PLUG, icon="mdi:car-electric", value_fn=lambda v: v.fuel_and_battery.is_charger_connected, ), BMWBinarySensorEntityDescription( key="is_pre_entry_climatization_enabled", - name="Pre entry climatization", + translation_key="is_pre_entry_climatization_enabled", icon="mdi:car-seat-heater", value_fn=lambda v: v.charging_profile.is_pre_entry_climatization_enabled if v.charging_profile diff --git a/homeassistant/components/bmw_connected_drive/button.py b/homeassistant/components/bmw_connected_drive/button.py index 5285820b32dd20..d221c011445175 100644 --- a/homeassistant/components/bmw_connected_drive/button.py +++ b/homeassistant/components/bmw_connected_drive/button.py @@ -37,32 +37,32 @@ class BMWButtonEntityDescription(ButtonEntityDescription): BUTTON_TYPES: tuple[BMWButtonEntityDescription, ...] = ( BMWButtonEntityDescription( key="light_flash", + translation_key="light_flash", icon="mdi:car-light-alert", - name="Flash lights", remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_light_flash(), ), BMWButtonEntityDescription( key="sound_horn", + translation_key="sound_horn", icon="mdi:bullhorn", - name="Sound horn", remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_horn(), ), BMWButtonEntityDescription( key="activate_air_conditioning", + translation_key="activate_air_conditioning", icon="mdi:hvac", - name="Activate air conditioning", remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_air_conditioning(), ), BMWButtonEntityDescription( key="find_vehicle", + translation_key="find_vehicle", icon="mdi:crosshairs-question", - name="Find vehicle", remote_function=lambda vehicle: vehicle.remote_services.trigger_remote_vehicle_finder(), ), BMWButtonEntityDescription( key="refresh", + translation_key="refresh", icon="mdi:refresh", - name="Refresh from cloud", account_function=lambda coordinator: coordinator.async_request_refresh(), enabled_when_read_only=True, ), diff --git a/homeassistant/components/bmw_connected_drive/lock.py b/homeassistant/components/bmw_connected_drive/lock.py index d20ccd1fbb4ba0..c7495e3145ae32 100644 --- a/homeassistant/components/bmw_connected_drive/lock.py +++ b/homeassistant/components/bmw_connected_drive/lock.py @@ -44,7 +44,7 @@ async def async_setup_entry( class BMWLock(BMWBaseEntity, LockEntity): """Representation of a MyBMW vehicle lock.""" - _attr_name = "Lock" + _attr_translation_key = "lock" def __init__( self, diff --git a/homeassistant/components/bmw_connected_drive/number.py b/homeassistant/components/bmw_connected_drive/number.py index c8f72b272c1645..f37f7627140c5f 100644 --- a/homeassistant/components/bmw_connected_drive/number.py +++ b/homeassistant/components/bmw_connected_drive/number.py @@ -45,7 +45,7 @@ class BMWNumberEntityDescription(NumberEntityDescription, BMWRequiredKeysMixin): NUMBER_TYPES: list[BMWNumberEntityDescription] = [ BMWNumberEntityDescription( key="target_soc", - name="Target SoC", + translation_key="target_soc", device_class=NumberDeviceClass.BATTERY, is_available=lambda v: v.is_remote_set_target_soc_enabled, native_max_value=100.0, diff --git a/homeassistant/components/bmw_connected_drive/select.py b/homeassistant/components/bmw_connected_drive/select.py index 0b20ed908732e1..7c2ef4fed3252a 100644 --- a/homeassistant/components/bmw_connected_drive/select.py +++ b/homeassistant/components/bmw_connected_drive/select.py @@ -39,7 +39,7 @@ class BMWSelectEntityDescription(SelectEntityDescription, BMWRequiredKeysMixin): SELECT_TYPES: dict[str, BMWSelectEntityDescription] = { "ac_limit": BMWSelectEntityDescription( key="ac_limit", - name="AC Charging Limit", + translation_key="ac_limit", is_available=lambda v: v.is_remote_set_ac_limit_enabled, dynamic_options=lambda v: [ str(lim) for lim in v.charging_profile.ac_available_limits # type: ignore[union-attr] @@ -53,7 +53,7 @@ class BMWSelectEntityDescription(SelectEntityDescription, BMWRequiredKeysMixin): ), "charging_mode": BMWSelectEntityDescription( key="charging_mode", - name="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] diff --git a/homeassistant/components/bmw_connected_drive/sensor.py b/homeassistant/components/bmw_connected_drive/sensor.py index 314ff47c14cf65..8f5b4fb8608a4c 100644 --- a/homeassistant/components/bmw_connected_drive/sensor.py +++ b/homeassistant/components/bmw_connected_drive/sensor.py @@ -55,7 +55,7 @@ def convert_and_round( # --- Generic --- "ac_current_limit": BMWSensorEntityDescription( key="ac_current_limit", - name="AC current limit", + translation_key="ac_current_limit", key_class="charging_profile", unit_type=UnitOfElectricCurrent.AMPERE, icon="mdi:current-ac", @@ -63,34 +63,34 @@ def convert_and_round( ), "charging_start_time": BMWSensorEntityDescription( key="charging_start_time", - name="Charging start time", + translation_key="charging_start_time", key_class="fuel_and_battery", device_class=SensorDeviceClass.TIMESTAMP, entity_registry_enabled_default=False, ), "charging_end_time": BMWSensorEntityDescription( key="charging_end_time", - name="Charging end time", + translation_key="charging_end_time", key_class="fuel_and_battery", device_class=SensorDeviceClass.TIMESTAMP, ), "charging_status": BMWSensorEntityDescription( key="charging_status", - name="Charging status", + translation_key="charging_status", key_class="fuel_and_battery", icon="mdi:ev-station", value=lambda x, y: x.value, ), "charging_target": BMWSensorEntityDescription( key="charging_target", - name="Charging target", + translation_key="charging_target", key_class="fuel_and_battery", icon="mdi:battery-charging-high", unit_type=PERCENTAGE, ), "remaining_battery_percent": BMWSensorEntityDescription( key="remaining_battery_percent", - name="Remaining battery percent", + translation_key="remaining_battery_percent", key_class="fuel_and_battery", unit_type=PERCENTAGE, device_class=SensorDeviceClass.BATTERY, @@ -98,14 +98,14 @@ def convert_and_round( # --- Specific --- "mileage": BMWSensorEntityDescription( key="mileage", - name="Mileage", + translation_key="mileage", icon="mdi:speedometer", unit_type=LENGTH, value=lambda x, hass: convert_and_round(x, hass.config.units.length, 2), ), "remaining_range_total": BMWSensorEntityDescription( key="remaining_range_total", - name="Remaining range total", + translation_key="remaining_range_total", key_class="fuel_and_battery", icon="mdi:map-marker-distance", unit_type=LENGTH, @@ -113,7 +113,7 @@ def convert_and_round( ), "remaining_range_electric": BMWSensorEntityDescription( key="remaining_range_electric", - name="Remaining range electric", + translation_key="remaining_range_electric", key_class="fuel_and_battery", icon="mdi:map-marker-distance", unit_type=LENGTH, @@ -121,7 +121,7 @@ def convert_and_round( ), "remaining_range_fuel": BMWSensorEntityDescription( key="remaining_range_fuel", - name="Remaining range fuel", + translation_key="remaining_range_fuel", key_class="fuel_and_battery", icon="mdi:map-marker-distance", unit_type=LENGTH, @@ -129,7 +129,7 @@ def convert_and_round( ), "remaining_fuel": BMWSensorEntityDescription( key="remaining_fuel", - name="Remaining fuel", + translation_key="remaining_fuel", key_class="fuel_and_battery", icon="mdi:gas-station", unit_type=VOLUME, @@ -137,7 +137,7 @@ def convert_and_round( ), "remaining_fuel_percent": BMWSensorEntityDescription( key="remaining_fuel_percent", - name="Remaining fuel percent", + translation_key="remaining_fuel_percent", key_class="fuel_and_battery", icon="mdi:gas-station", unit_type=PERCENTAGE, diff --git a/homeassistant/components/bmw_connected_drive/strings.json b/homeassistant/components/bmw_connected_drive/strings.json index 506175becd9187..af73417b1a93e8 100644 --- a/homeassistant/components/bmw_connected_drive/strings.json +++ b/homeassistant/components/bmw_connected_drive/strings.json @@ -26,5 +26,114 @@ } } } + }, + "entity": { + "binary_sensor": { + "lids": { + "name": "Lids" + }, + "windows": { + "name": "Windows" + }, + "door_lock_state": { + "name": "Door lock state" + }, + "condition_based_services": { + "name": "Condition based services" + }, + "check_control_messages": { + "name": "Check control messages" + }, + "charging_status": { + "name": "Charging status" + }, + "connection_status": { + "name": "Connection status" + }, + "is_pre_entry_climatization_enabled": { + "name": "Pre entry climatization" + } + }, + "button": { + "light_flash": { + "name": "Flash lights" + }, + "sound_horn": { + "name": "Sound horn" + }, + "activate_air_conditioning": { + "name": "Activate air conditioning" + }, + "find_vehicle": { + "name": "Find vehicle" + }, + "refresh": { + "name": "Refresh from cloud" + } + }, + "lock": { + "lock": { + "name": "[%key:component::lock::title%]" + } + }, + "number": { + "target_soc": { + "name": "Target SoC" + } + }, + "select": { + "ac_limit": { + "name": "AC Charging Limit" + }, + "charging_mode": { + "name": "Charging Mode" + } + }, + "sensor": { + "ac_current_limit": { + "name": "AC current limit" + }, + "charging_start_time": { + "name": "Charging start time" + }, + "charging_end_time": { + "name": "Charging end time" + }, + "charging_status": { + "name": "Charging status" + }, + "charging_target": { + "name": "Charging target" + }, + "remaining_battery_percent": { + "name": "Remaining battery percent" + }, + "mileage": { + "name": "Mileage" + }, + "remaining_range_total": { + "name": "Remaining range total" + }, + "remaining_range_electric": { + "name": "Remaining range electric" + }, + "remaining_range_fuel": { + "name": "Remaining range fuel" + }, + "remaining_fuel": { + "name": "Remaining fuel" + }, + "remaining_fuel_percent": { + "name": "Remaining fuel percent" + } + }, + "switch": { + "climate": { + "name": "Climate" + }, + "charging": { + "name": "Charging" + } + } } } diff --git a/homeassistant/components/bmw_connected_drive/switch.py b/homeassistant/components/bmw_connected_drive/switch.py index 41243ca932395e..298338dc9fa339 100644 --- a/homeassistant/components/bmw_connected_drive/switch.py +++ b/homeassistant/components/bmw_connected_drive/switch.py @@ -51,7 +51,7 @@ class BMWSwitchEntityDescription(SwitchEntityDescription, BMWRequiredKeysMixin): NUMBER_TYPES: list[BMWSwitchEntityDescription] = [ BMWSwitchEntityDescription( key="climate", - name="Climate", + translation_key="climate", is_available=lambda v: v.is_remote_climate_stop_enabled, value_fn=lambda v: v.climate.is_climate_on, remote_service_on=lambda v: v.remote_services.trigger_remote_air_conditioning(), @@ -60,7 +60,7 @@ class BMWSwitchEntityDescription(SwitchEntityDescription, BMWRequiredKeysMixin): ), BMWSwitchEntityDescription( key="charging", - name="Charging", + translation_key="charging", is_available=lambda v: v.is_remote_charge_stop_enabled, value_fn=lambda v: v.fuel_and_battery.charging_status in CHARGING_STATE_ON, remote_service_on=lambda v: v.remote_services.trigger_charge_start(),