fix: Assume conditions are state conditions unless otherwise specified (#1552)
This commit is contained in:
@@ -212,8 +212,10 @@ export class ConditionsManager {
|
||||
};
|
||||
|
||||
const conditions = getAllConditions();
|
||||
this._hasHAStateConditions = conditions.some((conditionObj) =>
|
||||
['state', 'numeric_state', 'user'].includes(conditionObj.condition),
|
||||
this._hasHAStateConditions = conditions.some(
|
||||
(conditionObj) =>
|
||||
!conditionObj.condition ||
|
||||
['state', 'numeric_state', 'user'].includes(conditionObj.condition),
|
||||
);
|
||||
conditions.forEach((conditionObj) => {
|
||||
if (conditionObj.condition === 'screen') {
|
||||
@@ -263,16 +265,7 @@ export class ConditionsManager {
|
||||
};
|
||||
|
||||
switch (conditionObj.condition) {
|
||||
case 'view':
|
||||
return !!state?.view && conditionObj.views.includes(state.view);
|
||||
case 'fullscreen':
|
||||
return (
|
||||
state.fullscreen !== undefined && conditionObj.fullscreen === state.fullscreen
|
||||
);
|
||||
case 'expand':
|
||||
return state.expand !== undefined && conditionObj.expand === state.expand;
|
||||
case 'camera':
|
||||
return !!state.camera && conditionObj.cameras.includes(state.camera);
|
||||
case undefined:
|
||||
case 'state':
|
||||
return (
|
||||
!!state.state &&
|
||||
@@ -289,6 +282,16 @@ export class ConditionsManager {
|
||||
)
|
||||
: conditionObj.state_not !== state.state[conditionObj.entity].state))))
|
||||
);
|
||||
case 'view':
|
||||
return !!state?.view && conditionObj.views.includes(state.view);
|
||||
case 'fullscreen':
|
||||
return (
|
||||
state.fullscreen !== undefined && conditionObj.fullscreen === state.fullscreen
|
||||
);
|
||||
case 'expand':
|
||||
return state.expand !== undefined && conditionObj.expand === state.expand;
|
||||
case 'camera':
|
||||
return !!state.camera && conditionObj.cameras.includes(state.camera);
|
||||
case 'numeric_state':
|
||||
return (
|
||||
!!state.state &&
|
||||
|
||||
+4
-1
@@ -518,7 +518,10 @@ const imageSchema = elementsBaseSchema.extend({
|
||||
|
||||
// https://www.home-assistant.io/dashboards/conditional/#state
|
||||
const stateConditionSchema = z.object({
|
||||
condition: z.literal('state'),
|
||||
// If the condition is not specified, a state condition is assumed. This
|
||||
// allows the syntax to match a picture elements conditional:
|
||||
// https://www.home-assistant.io/dashboards/picture-elements/#conditional-element
|
||||
condition: z.literal('state').optional(),
|
||||
entity: z.string(),
|
||||
state: z.string().or(z.string().array()).optional(),
|
||||
state_not: z.string().or(z.string().array()).optional(),
|
||||
|
||||
Reference in New Issue
Block a user