mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 10:16:46 +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 !== "object") {
|
||||||
if (typeof duration === "string" || isNaN(duration)) {
|
if (typeof duration === "string" || isNaN(duration)) {
|
||||||
const parts = duration?.toString().split(":") || [];
|
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 {
|
return {
|
||||||
hours: Number(parts[0]) || 0,
|
hours: Number(parts[0]) || 0,
|
||||||
minutes: Number(parts[1]) || 0,
|
minutes: Number(parts[1]) || 0,
|
||||||
seconds: Number(parts[2]) || 0,
|
seconds: seconds_whole,
|
||||||
milliseconds: Number(parts[3]) || 0,
|
milliseconds: Math.floor((seconds - seconds_whole) * 1000),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return { seconds: duration };
|
return { seconds: duration };
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
assert,
|
assert,
|
||||||
boolean,
|
boolean,
|
||||||
literal,
|
literal,
|
||||||
|
number,
|
||||||
object,
|
object,
|
||||||
optional,
|
optional,
|
||||||
string,
|
string,
|
||||||
@ -24,7 +25,7 @@ const stateConditionStruct = object({
|
|||||||
entity_id: optional(string()),
|
entity_id: optional(string()),
|
||||||
attribute: optional(string()),
|
attribute: optional(string()),
|
||||||
state: optional(string()),
|
state: optional(string()),
|
||||||
for: optional(union([string(), forDictStruct])),
|
for: optional(union([number(), string(), forDictStruct])),
|
||||||
enabled: optional(boolean()),
|
enabled: optional(boolean()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
assert,
|
assert,
|
||||||
assign,
|
assign,
|
||||||
literal,
|
literal,
|
||||||
|
number,
|
||||||
object,
|
object,
|
||||||
optional,
|
optional,
|
||||||
string,
|
string,
|
||||||
@ -31,7 +32,7 @@ const stateTriggerStruct = assign(
|
|||||||
attribute: optional(string()),
|
attribute: optional(string()),
|
||||||
from: optional(string()),
|
from: optional(string()),
|
||||||
to: 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