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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user