mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Fix errors in duration data processing in Automation UI Editor (#15422)
Fix errors in duration data processing
This commit is contained in:
parent
404199bb19
commit
76f90e1449
@ -10,11 +10,19 @@ export const createDurationData = (
|
||||
if (typeof duration !== "object") {
|
||||
if (typeof duration === "string" || isNaN(duration)) {
|
||||
const parts = duration?.toString().split(":") || [];
|
||||
if (parts.length === 1) {
|
||||
return { seconds: Number(parts[0]) };
|
||||
}
|
||||
if (parts.length > 3) {
|
||||
return undefined;
|
||||
}
|
||||
const seconds = Number(parts[2]) || 0;
|
||||
const seconds_whole = Math.floor(seconds);
|
||||
return {
|
||||
hours: Number(parts[0]) || 0,
|
||||
minutes: Number(parts[1]) || 0,
|
||||
seconds: Number(parts[2]) || 0,
|
||||
milliseconds: Number(parts[3]) || 0,
|
||||
seconds: seconds_whole,
|
||||
milliseconds: Math.floor((seconds - seconds_whole) * 1000),
|
||||
};
|
||||
}
|
||||
return { seconds: duration };
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
assert,
|
||||
boolean,
|
||||
literal,
|
||||
number,
|
||||
object,
|
||||
optional,
|
||||
string,
|
||||
@ -24,7 +25,7 @@ const stateConditionStruct = object({
|
||||
entity_id: optional(string()),
|
||||
attribute: optional(string()),
|
||||
state: optional(string()),
|
||||
for: optional(union([string(), forDictStruct])),
|
||||
for: optional(union([number(), string(), forDictStruct])),
|
||||
enabled: optional(boolean()),
|
||||
});
|
||||
|
||||
|
@ -5,6 +5,7 @@ import {
|
||||
assert,
|
||||
assign,
|
||||
literal,
|
||||
number,
|
||||
object,
|
||||
optional,
|
||||
string,
|
||||
@ -31,7 +32,7 @@ const stateTriggerStruct = assign(
|
||||
attribute: optional(string()),
|
||||
from: optional(string()),
|
||||
to: optional(string()),
|
||||
for: optional(union([string(), forDictStruct])),
|
||||
for: optional(union([number(), string(), forDictStruct])),
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user