forked from Github/frigate
change MQTT to toggle recordings instead of clips
This commit is contained in:
committed by
Blake Blackshear
parent
181a504a14
commit
c527b1ca5d
@@ -107,12 +107,12 @@ describe('MqttProvider', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('prefills the clips/detect/snapshots state from config', async () => {
|
||||
test('prefills the recordings/detect/snapshots state from config', async () => {
|
||||
jest.spyOn(Date, 'now').mockReturnValue(123456);
|
||||
const config = {
|
||||
cameras: {
|
||||
front: { name: 'front', detect: { enabled: true }, clips: { enabled: false }, snapshots: { enabled: true } },
|
||||
side: { name: 'side', detect: { enabled: false }, clips: { enabled: false }, snapshots: { enabled: false } },
|
||||
front: { name: 'front', detect: { enabled: true }, record: { enabled: false }, snapshots: { enabled: true } },
|
||||
side: { name: 'side', detect: { enabled: false }, record: { enabled: false }, snapshots: { enabled: false } },
|
||||
},
|
||||
};
|
||||
render(
|
||||
@@ -122,10 +122,10 @@ describe('MqttProvider', () => {
|
||||
);
|
||||
await screen.findByTestId('data');
|
||||
expect(screen.getByTestId('front/detect/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"ON"}');
|
||||
expect(screen.getByTestId('front/clips/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
expect(screen.getByTestId('front/recordings/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
expect(screen.getByTestId('front/snapshots/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"ON"}');
|
||||
expect(screen.getByTestId('side/detect/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
expect(screen.getByTestId('side/clips/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
expect(screen.getByTestId('side/recordings/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
expect(screen.getByTestId('side/snapshots/state')).toHaveTextContent('{"lastUpdate":123456,"payload":"OFF"}');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,8 +41,8 @@ export function MqttProvider({
|
||||
|
||||
useEffect(() => {
|
||||
Object.keys(config.cameras).forEach((camera) => {
|
||||
const { name, clips, detect, snapshots } = config.cameras[camera];
|
||||
dispatch({ topic: `${name}/clips/state`, payload: clips.enabled ? 'ON' : 'OFF' });
|
||||
const { name, record, detect, snapshots } = config.cameras[camera];
|
||||
dispatch({ topic: `${name}/recordings/state`, payload: record.enabled ? 'ON' : 'OFF' });
|
||||
dispatch({ topic: `${name}/detect/state`, payload: detect.enabled ? 'ON' : 'OFF' });
|
||||
dispatch({ topic: `${name}/snapshots/state`, payload: snapshots.enabled ? 'ON' : 'OFF' });
|
||||
});
|
||||
@@ -101,12 +101,12 @@ export function useDetectState(camera) {
|
||||
return { payload, send, connected };
|
||||
}
|
||||
|
||||
export function useClipsState(camera) {
|
||||
export function useRecordingsState(camera) {
|
||||
const {
|
||||
value: { payload },
|
||||
send,
|
||||
connected,
|
||||
} = useMqtt(`${camera}/clips/state`, `${camera}/clips/set`);
|
||||
} = useMqtt(`${camera}/recordings/state`, `${camera}/recordings/set`);
|
||||
return { payload, send, connected };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user