CEC-222, CEC-214 Send car commands and log filtering (#41)

* Send car commands

* Log filter control

* Fix message format

* Move VehicleContext
This commit is contained in:
John Wu
2021-05-18 12:51:24 -07:00
committed by GitHub
parent 0d71a3f235
commit 64995ef7a6
9 changed files with 811 additions and 190 deletions

View File

@@ -84,6 +84,30 @@ export const VehicleProvider = ({ children }) => {
}
};
const sendCommand = async (vin, command, token) => {
try {
setBusy(true);
const result = await api.sendCommand(vin, command, token);
if (result.error)
throw new Error(`Send command error. ${result.message}`);
return result;
} finally {
setBusy(false);
}
};
const sendLogFilter = async (vin, filter, token) => {
try {
setBusy(true);
const result = await api.sendLog(vin, filter, token);
if (result.error)
throw new Error(`Send log filter error. ${result.message}`);
return result;
} finally {
setBusy(false);
}
};
return (
<VehicleContext.Provider
value={{
@@ -96,6 +120,8 @@ export const VehicleProvider = ({ children }) => {
addVehicle,
getModels,
getYears,
sendCommand,
sendLogFilter,
}}
>
{children}