fix: Match state trigger/condition semantics to HA (#2565)

* Closes #2530
This commit is contained in:
Dermot Duffy
2026-07-04 10:23:51 -07:00
committed by GitHub
parent 3494706225
commit 9f956fe89f
15 changed files with 825 additions and 69 deletions
@@ -31,4 +31,30 @@ describe('stateConditionSchema', () => {
}),
).toEqual({ condition: 'state', entity_id: 'binary_sensor.door', state_not: 'on' });
});
it('should accept a non-string state value when matching an attribute', () => {
expect(
stateConditionSchema.parse({
condition: 'state',
entity_id: 'sensor.battery',
attribute: 'battery_level',
state: 50,
}),
).toEqual({
condition: 'state',
entity_id: 'sensor.battery',
attribute: 'battery_level',
state: 50,
});
});
it('should reject a non-string state value without an attribute', () => {
expect(() =>
stateConditionSchema.parse({
condition: 'state',
entity_id: 'sensor.battery',
state: 50,
}),
).toThrow();
});
});
@@ -26,4 +26,25 @@ describe('stateTriggerSchema', () => {
}),
).toThrow();
});
it('should accept a non-string to value when watching an attribute', () => {
expect(
stateTriggerSchema.parse({
trigger: 'state',
entity_id: 'sensor.battery',
attribute: 'battery_level',
to: 50,
}),
).toMatchObject({ attribute: 'battery_level', to: 50 });
});
it('should reject a non-string to value without an attribute', () => {
expect(() =>
stateTriggerSchema.parse({
trigger: 'state',
entity_id: 'sensor.battery',
to: 50,
}),
).toThrow();
});
});