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
@@ -5,7 +5,7 @@ import CameraImage from '../components/CameraImage';
|
||||
import ClipIcon from '../icons/Clip';
|
||||
import MotionIcon from '../icons/Motion';
|
||||
import SnapshotIcon from '../icons/Snapshot';
|
||||
import { useDetectState, useClipsState, useSnapshotsState } from '../api/mqtt';
|
||||
import { useDetectState, useRecordingsState, useSnapshotsState } from '../api/mqtt';
|
||||
import { useConfig, FetchStatus } from '../api';
|
||||
import { useMemo } from 'preact/hooks';
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function Cameras() {
|
||||
|
||||
function Camera({ name, conf }) {
|
||||
const { payload: detectValue, send: sendDetect } = useDetectState(name);
|
||||
const { payload: clipValue, send: sendClips } = useClipsState(name);
|
||||
const { payload: recordValue, send: sendRecordings } = useRecordingsState(name);
|
||||
const { payload: snapshotValue, send: sendSnapshots } = useSnapshotsState(name);
|
||||
const href = `/cameras/${name}`;
|
||||
const buttons = useMemo(() => {
|
||||
@@ -46,11 +46,11 @@ function Camera({ name, conf }) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: `Toggle clips ${clipValue === 'ON' ? 'off' : 'on'}`,
|
||||
name: `Toggle recordings ${recordValue === 'ON' ? 'off' : 'on'}`,
|
||||
icon: ClipIcon,
|
||||
color: clipValue === 'ON' ? 'blue' : 'gray',
|
||||
color: recordValue === 'ON' ? 'blue' : 'gray',
|
||||
onClick: () => {
|
||||
sendClips(clipValue === 'ON' ? 'OFF' : 'ON');
|
||||
sendRecordings(recordValue === 'ON' ? 'OFF' : 'ON');
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -62,7 +62,7 @@ function Camera({ name, conf }) {
|
||||
},
|
||||
},
|
||||
],
|
||||
[detectValue, sendDetect, clipValue, sendClips, snapshotValue, sendSnapshots]
|
||||
[detectValue, sendDetect, recordValue, sendRecordings, snapshotValue, sendSnapshots]
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -51,13 +51,13 @@ describe('Cameras Route', () => {
|
||||
|
||||
test('buttons toggle detect, clips, and snapshots', async () => {
|
||||
const sendDetect = jest.fn();
|
||||
const sendClips = jest.fn();
|
||||
const sendRecordings = jest.fn();
|
||||
const sendSnapshots = jest.fn();
|
||||
jest.spyOn(Mqtt, 'useDetectState').mockImplementation(() => {
|
||||
return { payload: 'ON', send: sendDetect };
|
||||
});
|
||||
jest.spyOn(Mqtt, 'useClipsState').mockImplementation(() => {
|
||||
return { payload: 'OFF', send: sendClips };
|
||||
jest.spyOn(Mqtt, 'useRecordingsState').mockImplementation(() => {
|
||||
return { payload: 'OFF', send: sendRecordings };
|
||||
});
|
||||
jest.spyOn(Mqtt, 'useSnapshotsState').mockImplementation(() => {
|
||||
return { payload: 'ON', send: sendSnapshots };
|
||||
@@ -72,11 +72,11 @@ describe('Cameras Route', () => {
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle snapshots off')[0]);
|
||||
expect(sendSnapshots).toHaveBeenCalledWith('OFF');
|
||||
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle clips on')[0]);
|
||||
expect(sendClips).toHaveBeenCalledWith('ON');
|
||||
fireEvent.click(screen.getAllByLabelText('Toggle recordings on')[0]);
|
||||
expect(sendRecordings).toHaveBeenCalledWith('ON');
|
||||
|
||||
expect(sendDetect).toHaveBeenCalledTimes(1);
|
||||
expect(sendSnapshots).toHaveBeenCalledTimes(1);
|
||||
expect(sendClips).toHaveBeenCalledTimes(1);
|
||||
expect(sendRecordings).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user