fix: Should faithfully use WebRTC card PTZ format data_* (#2396)
- Closes: #2385 BREAKING CHANGE: Requires configuration change (automatic upgrade offered) to move from (e.g.) `data_left_stop` to `data_end_left`
This commit is contained in:
@@ -3766,5 +3766,85 @@ describe('should handle version specific upgrades', () => {
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
describe('ptz data_*_start/stop -> data_start/end_* (WebRTC ordering)', () => {
|
||||
it('in cameras_global.ptz', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{}],
|
||||
cameras_global: {
|
||||
ptz: {
|
||||
service: 'service.ptz',
|
||||
data_left_start: { cmd: 'left_start' },
|
||||
data_left_stop: { cmd: 'left_stop' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.cameras_global.ptz).toEqual({
|
||||
service: 'service.ptz',
|
||||
data_start_left: { cmd: 'left_start' },
|
||||
data_end_left: { cmd: 'left_stop' },
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('in cameras[n].ptz', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [
|
||||
{
|
||||
ptz: {
|
||||
service: 'service.ptz',
|
||||
data_right_start: { cmd: 'right_start' },
|
||||
data_right_stop: { cmd: 'right_stop' },
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.cameras[0].ptz).toEqual({
|
||||
service: 'service.ptz',
|
||||
data_start_right: { cmd: 'right_start' },
|
||||
data_end_right: { cmd: 'right_stop' },
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('ignores non-object ptz value', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{}],
|
||||
cameras_global: {
|
||||
ptz: 'not-an-object',
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('does not overwrite existing WebRTC key', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{}],
|
||||
cameras_global: {
|
||||
ptz: {
|
||||
service: 'service.ptz',
|
||||
data_left_stop: { cmd: 'old' },
|
||||
data_end_left: { cmd: 'new' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.cameras_global.ptz).toEqual({
|
||||
service: 'service.ptz',
|
||||
data_end_left: { cmd: 'new' },
|
||||
});
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1332,12 +1332,12 @@ describe('should convert webrtc card PTZ to Advanced Camera Card PTZ', () => {
|
||||
cameraConfigSchema.parse({
|
||||
ptz: {
|
||||
service: 'foo',
|
||||
[`data_${action}_start`]: {
|
||||
[`data_start_${action}`]: {
|
||||
device: '048123',
|
||||
cmd: action,
|
||||
phase: 'start',
|
||||
},
|
||||
[`data_${action}_stop`]: {
|
||||
[`data_end_${action}`]: {
|
||||
device: '048123',
|
||||
cmd: action,
|
||||
phase: 'stop',
|
||||
@@ -1371,7 +1371,7 @@ describe('should convert webrtc card PTZ to Advanced Camera Card PTZ', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('presets', () => {
|
||||
it('presets via presets sub-object', () => {
|
||||
expect(
|
||||
cameraConfigSchema.parse({
|
||||
ptz: {
|
||||
@@ -1414,6 +1414,93 @@ describe('should convert webrtc card PTZ to Advanced Camera Card PTZ', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('actions_left takes priority over data_left', () => {
|
||||
const result = cameraConfigSchema.parse({
|
||||
ptz: {
|
||||
service: 'foo',
|
||||
data_left: { cmd: 'from_data' },
|
||||
actions_left: {
|
||||
action: 'perform-action',
|
||||
perform_action: 'bar',
|
||||
data: { cmd: 'from_actions' },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
ptz: expect.objectContaining({
|
||||
actions_left: {
|
||||
action: 'perform-action',
|
||||
perform_action: 'bar',
|
||||
data: { cmd: 'from_actions' },
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('data_home creates a home preset', () => {
|
||||
expect(
|
||||
cameraConfigSchema.parse({
|
||||
ptz: {
|
||||
service: 'foo',
|
||||
data_home: {
|
||||
device: '048123',
|
||||
cmd: 'home',
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
ptz: expect.objectContaining({
|
||||
presets: {
|
||||
home: {
|
||||
action: 'perform-action',
|
||||
perform_action: 'foo',
|
||||
data: {
|
||||
device: '048123',
|
||||
cmd: 'home',
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('data_home does not overwrite existing home preset', () => {
|
||||
expect(
|
||||
cameraConfigSchema.parse({
|
||||
ptz: {
|
||||
service: 'foo',
|
||||
data_home: {
|
||||
device: '048123',
|
||||
cmd: 'home_data',
|
||||
},
|
||||
presets: {
|
||||
home: {
|
||||
action: 'perform-action',
|
||||
perform_action: 'bar',
|
||||
data: { cmd: 'home_preset' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
ptz: expect.objectContaining({
|
||||
presets: {
|
||||
home: {
|
||||
action: 'perform-action',
|
||||
perform_action: 'bar',
|
||||
data: { cmd: 'home_preset' },
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should lazy evaluate schemas', () => {
|
||||
|
||||
Reference in New Issue
Block a user