Skip to content

Commit

Permalink
Revert "More flexible translation keys for logbook binary sensors" (#…
Browse files Browse the repository at this point in the history
…22687)

Revert "More flexible translation keys for logbook binary sensors (#22257)"

This reverts commit df3e457.
  • Loading branch information
piitaya authored Nov 6, 2024
1 parent 0488d19 commit c3b7ce8
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 77 deletions.
114 changes: 98 additions & 16 deletions src/data/logbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,114 @@ export const localizeStateMessage = (
const isOff = state === BINARY_STATE_OFF;
const device_class = stateObj.attributes.device_class;

if (device_class && (isOn || isOff)) {
return (
localize(
`${LOGBOOK_LOCALIZE_PATH}.${isOn ? "detected_device_classes" : "cleared_device_classes"}.${device_class}`,
{
switch (device_class) {
case "battery":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_low`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_normal`);
}
break;

case "connectivity":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_connected`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_disconnected`);
}
break;

case "door":
case "garage_door":
case "opening":
case "window":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_opened`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_closed`);
}
break;

case "lock":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_unlocked`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_locked`);
}
break;

case "plug":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_plugged_in`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_unplugged`);
}
break;

case "presence":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_at_home`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_away`);
}
break;

case "safety":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_unsafe`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.was_safe`);
}
break;

case "cold":
case "gas":
case "heat":
case "moisture":
case "motion":
case "occupancy":
case "power":
case "problem":
case "smoke":
case "sound":
case "vibration":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_device_class`, {
device_class: autoCaseNoun(
localize(
`component.binary_sensor.entity_component.${device_class}.name`
) || device_class,
),
hass.language
),
}
) ||
// If there's no key for a specific device class, fallback to generic string
localize(
`${LOGBOOK_LOCALIZE_PATH}.${isOn ? "detected_device_class" : "cleared_device_class"}`,
{
});
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.cleared_device_class`, {
device_class: autoCaseNoun(
localize(
`component.binary_sensor.entity_component.${device_class}.name`
) || device_class,
),
hass.language
),
}
)
);
});
}
break;

case "tamper":
if (isOn) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_tampering`);
}
if (isOff) {
return localize(`${LOGBOOK_LOCALIZE_PATH}.cleared_tampering`);
}
break;
}

break;
Expand Down
62 changes: 1 addition & 61 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,67 +486,7 @@
"cleared_tampering": "cleared tampering",
"detected_event": "{event_type} event detected",
"detected_event_no_type": "detected an event",
"detected_unknown_event": "detected an unknown event",
"detected_device_classes": {
"battery": "[%key:ui::components::logbook::messages::was_low%]",
"battery_charging": "started charging",
"carbon_monoxide": "[%key:ui::components::logbook::messages::detected_device_class%]",
"cold": "[%key:ui::components::logbook::messages::detected_device_class%]",
"connectivity": "[%key:ui::components::logbook::messages::was_connected%]",
"door": "[%key:ui::components::logbook::messages::was_opened%]",
"garage_door": "[%key:ui::components::logbook::messages::was_opened%]",
"gas": "[%key:ui::components::logbook::messages::detected_device_class%]",
"heat": "[%key:ui::components::logbook::messages::detected_device_class%]",
"light": "[%key:ui::components::logbook::messages::detected_device_class%]",
"lock": "[%key:ui::components::logbook::messages::was_unlocked%]",
"moisture": "[%key:ui::components::logbook::messages::detected_device_class%]",
"motion": "[%key:ui::components::logbook::messages::detected_device_class%]",
"moving": "[%key:ui::components::logbook::messages::detected_device_class%]",
"occupancy": "[%key:ui::components::logbook::messages::detected_device_class%]",
"opening": "[%key:ui::components::logbook::messages::was_opened%]",
"plug": "[%key:ui::components::logbook::messages::was_plugged_in%]",
"power": "[%key:ui::components::logbook::messages::detected_device_class%]",
"presence": "[%key:ui::components::logbook::messages::was_at_home%]",
"problem": "[%key:ui::components::logbook::messages::detected_device_class%]",
"running": "[%key:ui::components::logbook::messages::detected_device_class%]",
"safety": "[%key:ui::components::logbook::messages::was_unsafe%]",
"smoke": "[%key:ui::components::logbook::messages::detected_device_class%]",
"sound": "[%key:ui::components::logbook::messages::detected_device_class%]",
"tamper": "[%key:ui::components::logbook::messages::detected_tampering%]",
"update": "[%key:ui::components::logbook::messages::detected_device_class%]",
"vibration": "[%key:ui::components::logbook::messages::detected_device_class%]",
"window": "[%key:ui::components::logbook::messages::was_opened%]"
},
"cleared_device_classes": {
"battery": "[%key:ui::components::logbook::messages::was_normal%]",
"battery_charging": "stopped charging",
"carbon_monoxide": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"cold": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"connectivity": "[%key:ui::components::logbook::messages::was_disconnected%]",
"door": "[%key:ui::components::logbook::messages::was_closed%]",
"garage_door": "[%key:ui::components::logbook::messages::was_closed%]",
"gas": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"heat": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"light": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"lock": "[%key:ui::components::logbook::messages::was_locked%]",
"moisture": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"motion": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"moving": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"occupancy": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"opening": "[%key:ui::components::logbook::messages::was_closed%]",
"plug": "[%key:ui::components::logbook::messages::was_unplugged%]",
"power": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"presence": "[%key:ui::components::logbook::messages::was_away%]",
"problem": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"running": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"safety": "[%key:ui::components::logbook::messages::was_safe%]",
"smoke": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"sound": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"tamper": "[%key:ui::components::logbook::messages::cleared_tampering%]",
"update": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"vibration": "[%key:ui::components::logbook::messages::cleared_device_class%]",
"window": "[%key:ui::components::logbook::messages::was_closed%]"
}
"detected_unknown_event": "detected an unknown event"
}
},
"entity": {
Expand Down

0 comments on commit c3b7ce8

Please sign in to comment.