Add entity name translations to Picnic (#91362)
* Add translatable entities for Picnic * Apply fixes
This commit is contained in:
parent
473cbf7f9b
commit
77a445ee16
2 changed files with 69 additions and 5 deletions
|
@ -68,12 +68,14 @@ class PicnicSensorEntityDescription(SensorEntityDescription, PicnicRequiredKeysM
|
|||
SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_CART_ITEMS_COUNT,
|
||||
translation_key=SENSOR_CART_ITEMS_COUNT,
|
||||
icon="mdi:format-list-numbered",
|
||||
data_type="cart_data",
|
||||
value_fn=lambda cart: cart.get("total_count", 0),
|
||||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_CART_TOTAL_PRICE,
|
||||
translation_key=SENSOR_CART_TOTAL_PRICE,
|
||||
native_unit_of_measurement=CURRENCY_EURO,
|
||||
icon="mdi:currency-eur",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -82,6 +84,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_SELECTED_SLOT_START,
|
||||
translation_key=SENSOR_SELECTED_SLOT_START,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-start",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -90,6 +93,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_SELECTED_SLOT_END,
|
||||
translation_key=SENSOR_SELECTED_SLOT_END,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-end",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -98,6 +102,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_SELECTED_SLOT_MAX_ORDER_TIME,
|
||||
translation_key=SENSOR_SELECTED_SLOT_MAX_ORDER_TIME,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:clock-alert-outline",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -106,6 +111,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_SELECTED_SLOT_MIN_ORDER_VALUE,
|
||||
translation_key=SENSOR_SELECTED_SLOT_MIN_ORDER_VALUE,
|
||||
native_unit_of_measurement=CURRENCY_EURO,
|
||||
icon="mdi:currency-eur",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -118,6 +124,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_SLOT_START,
|
||||
translation_key=SENSOR_LAST_ORDER_SLOT_START,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-start",
|
||||
data_type="last_order_data",
|
||||
|
@ -127,6 +134,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_SLOT_END,
|
||||
translation_key=SENSOR_LAST_ORDER_SLOT_END,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-end",
|
||||
data_type="last_order_data",
|
||||
|
@ -136,12 +144,14 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_STATUS,
|
||||
translation_key=SENSOR_LAST_ORDER_STATUS,
|
||||
icon="mdi:list-status",
|
||||
data_type="last_order_data",
|
||||
value_fn=lambda last_order: last_order.get("status"),
|
||||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_MAX_ORDER_TIME,
|
||||
translation_key=SENSOR_LAST_ORDER_MAX_ORDER_TIME,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:clock-alert-outline",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -152,6 +162,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_DELIVERY_TIME,
|
||||
translation_key=SENSOR_LAST_ORDER_DELIVERY_TIME,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:timeline-clock",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -162,6 +173,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_LAST_ORDER_TOTAL_PRICE,
|
||||
translation_key=SENSOR_LAST_ORDER_TOTAL_PRICE,
|
||||
native_unit_of_measurement=CURRENCY_EURO,
|
||||
icon="mdi:cash-marker",
|
||||
data_type="last_order_data",
|
||||
|
@ -169,6 +181,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_NEXT_DELIVERY_ETA_START,
|
||||
translation_key=SENSOR_NEXT_DELIVERY_ETA_START,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:clock-start",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -179,6 +192,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_NEXT_DELIVERY_ETA_END,
|
||||
translation_key=SENSOR_NEXT_DELIVERY_ETA_END,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:clock-end",
|
||||
entity_registry_enabled_default=True,
|
||||
|
@ -189,6 +203,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_NEXT_DELIVERY_SLOT_START,
|
||||
translation_key=SENSOR_NEXT_DELIVERY_SLOT_START,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-start",
|
||||
data_type="next_delivery_data",
|
||||
|
@ -198,6 +213,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = (
|
|||
),
|
||||
PicnicSensorEntityDescription(
|
||||
key=SENSOR_NEXT_DELIVERY_SLOT_END,
|
||||
translation_key=SENSOR_NEXT_DELIVERY_SLOT_END,
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:calendar-end",
|
||||
data_type="next_delivery_data",
|
||||
|
@ -226,6 +242,7 @@ async def async_setup_entry(
|
|||
class PicnicSensor(SensorEntity, CoordinatorEntity):
|
||||
"""The CoordinatorEntity subclass representing Picnic sensors."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_attribution = ATTRIBUTION
|
||||
entity_description: PicnicSensorEntityDescription
|
||||
|
||||
|
@ -242,7 +259,6 @@ class PicnicSensor(SensorEntity, CoordinatorEntity):
|
|||
self.entity_id = f"sensor.picnic_{description.key}"
|
||||
self._service_unique_id = config_entry.unique_id
|
||||
|
||||
self._attr_name = self._to_capitalized_name(description.key)
|
||||
self._attr_unique_id = f"{config_entry.unique_id}.{description.key}"
|
||||
|
||||
@property
|
||||
|
@ -270,7 +286,3 @@ class PicnicSensor(SensorEntity, CoordinatorEntity):
|
|||
model=self._service_unique_id,
|
||||
name=f"Picnic: {self.coordinator.data[ADDRESS]}",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _to_capitalized_name(name: str) -> str:
|
||||
return name.replace("_", " ").capitalize()
|
||||
|
|
|
@ -19,5 +19,57 @@
|
|||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"cart_items_count": {
|
||||
"name": "Cart items count"
|
||||
},
|
||||
"cart_total_price": {
|
||||
"name": "Cart total price"
|
||||
},
|
||||
"selected_slot_start": {
|
||||
"name": "Start of selected slot"
|
||||
},
|
||||
"selected_slot_end": {
|
||||
"name": "End of selected slot"
|
||||
},
|
||||
"selected_slot_max_order_time": {
|
||||
"name": "Max order time of selected slot"
|
||||
},
|
||||
"selected_slot_min_order_value": {
|
||||
"name": "Minimum order value for selected slot"
|
||||
},
|
||||
"last_order_slot_start": {
|
||||
"name": "Start of last order's slot"
|
||||
},
|
||||
"last_order_slot_end": {
|
||||
"name": "End of last order's slot"
|
||||
},
|
||||
"last_order_status": {
|
||||
"name": "Status of last order"
|
||||
},
|
||||
"last_order_max_order_time": {
|
||||
"name": "Max order time of last slot"
|
||||
},
|
||||
"last_order_delivery_time": {
|
||||
"name": "Last order delivery time"
|
||||
},
|
||||
"last_order_total_price": {
|
||||
"name": "Total price of last order"
|
||||
},
|
||||
"next_delivery_eta_start": {
|
||||
"name": "Expected start of next delivery"
|
||||
},
|
||||
"next_delivery_eta_end": {
|
||||
"name": "Expected end of next delivery"
|
||||
},
|
||||
"next_delivery_slot_start": {
|
||||
"name": "Start of next delivery's slot"
|
||||
},
|
||||
"next_delivery_slot_end": {
|
||||
"name": "End of next delivery's slot"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue