Skip to content

Commit

Permalink
Add entity translations to BMW Connected Drive (#95142)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Jun 26, 2023
1 parent d95c241 commit 844a1eb
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 31 deletions.
16 changes: 8 additions & 8 deletions homeassistant/components/bmw_connected_drive/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -177,22 +177,22 @@ 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
value_fn=lambda v: v.fuel_and_battery.charging_status == ChargingState.CHARGING,
),
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
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/bmw_connected_drive/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bmw_connected_drive/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bmw_connected_drive/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/bmw_connected_drive/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
24 changes: 12 additions & 12 deletions homeassistant/components/bmw_connected_drive/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,89 +55,89 @@ 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",
entity_registry_enabled_default=False,
),
"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,
),
# --- 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,
value=lambda x, hass: convert_and_round(x, hass.config.units.length, 2),
),
"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,
value=lambda x, hass: convert_and_round(x, hass.config.units.length, 2),
),
"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,
value=lambda x, hass: convert_and_round(x, hass.config.units.length, 2),
),
"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,
value=lambda x, hass: convert_and_round(x, hass.config.units.volume, 2),
),
"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,
Expand Down
109 changes: 109 additions & 0 deletions homeassistant/components/bmw_connected_drive/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
4 changes: 2 additions & 2 deletions homeassistant/components/bmw_connected_drive/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 844a1eb

Please sign in to comment.