CEC-3916 Fix digital twin (#294)

* CEC-3916 Fix digital twin

* Mileage
This commit is contained in:
John Wu
2023-03-17 13:41:51 -07:00
committed by GitHub
parent 19bc054343
commit fd177b2656
2 changed files with 50 additions and 19 deletions

View File

@@ -35,13 +35,27 @@ exports[`DigitalTwinTab Render 1`] = `
true true
</div> </div>
<div> <div>
<p> <div
<b> class="makeStyles-popupSection-0"
>
<h3>
Battery Battery
</b> </h3>
: <p>
95% <b>
</p> Percentage
</b>
:
95%
</p>
<p>
<b>
Total Mileage
</b>
:
unknown
</p>
</div>
<div <div
class="makeStyles-popupSection-0" class="makeStyles-popupSection-0"
> >
@@ -102,14 +116,14 @@ exports[`DigitalTwinTab Render 1`] = `
driver driver
</b> </b>
: :
Closed Unlocked
</p> </p>
<p> <p>
<b> <b>
all all
</b> </b>
: :
Locked Unlocked
</p> </p>
</div> </div>
<div <div

View File

@@ -4,6 +4,10 @@ import { LocalDateTimeString } from "../../utils/dates";
import { ValidateLocationByParam } from "../../utils/locations"; import { ValidateLocationByParam } from "../../utils/locations";
import useStyles from "../useStyles"; import useStyles from "../useStyles";
const UNKNOWN = "unknown";
const LOCKED = "Locked";
const UNLOCKED = "Unlocked";
const keyValueTemplate = (key, value) => ( const keyValueTemplate = (key, value) => (
<p key={key}> <p key={key}>
<b>{key}</b>: {value} <b>{key}</b>: {value}
@@ -23,33 +27,46 @@ const windowState = (value) => {
const DigitalTwin = (props) => { const DigitalTwin = (props) => {
const classes = useStyles(); const classes = useStyles();
const { battery, doors, location, trex_version, ip, updated, windows, misc_windows, sunroof, dbc_version, door_locks } = props; const { battery, doors, location, trex_version, ip, updated, windows, misc_windows, sunroof, dbc_version, door_locks, vcu0x260, charging_metrics } = props;
return ( return (
<div> <div>
{!battery && !doors && !location && !windows && ( {!battery && !doors && !location && !windows && !vcu0x260 && !charging_metrics && (
<p>No vehicle data to display.</p> <p>No vehicle data to display.</p>
)} )}
{battery != null && keyValueTemplate("Battery", `${battery.percent}%`)} {battery && (
{doors != null && ( <div className={classes.popupSection}>
<h3>Battery</h3>
{keyValueTemplate("Percentage", `${battery.percent || 0}%`)}
{keyValueTemplate("Total Mileage", `${battery.total_mileage_odometer || UNKNOWN}`)}
</div>
)}
{(vcu0x260 || charging_metrics) && (
<div className={classes.popupSection}>
<h3>Charging</h3>
{keyValueTemplate("Charge Type", vcu0x260?.charge_type || UNKNOWN)}
{keyValueTemplate("Remaining Time", charging_metrics?.remaining_charging_time || UNKNOWN)}
</div>
)}
{doors && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Doors</h3> <h3>Doors</h3>
{Object.entries(doors).map(mapOpenCloseState)} {Object.entries(doors).map(mapOpenCloseState)}
</div> </div>
)} )}
{door_locks != null && ( {door_locks && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Door Locks</h3> <h3>Door Locks</h3>
{Object.entries(door_locks).map((value) => { {Object.entries(door_locks).map((value) => {
if (value[0] === "driver") { if (value[0] === "driver") {
return keyValueTemplate(value[0], value[1] ? "Open" : "Closed"); return keyValueTemplate(value[0], value[1] ? LOCKED : UNLOCKED);
} else { } else {
return keyValueTemplate(value[0], value[1] ? "Unlocked" : "Locked"); return keyValueTemplate(value[0], value[1] ? LOCKED : UNLOCKED);
} }
})} })}
</div> </div>
)} )}
{windows != null && ( {windows && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Windows</h3> <h3>Windows</h3>
{Object.entries(windows).map((value) => { {Object.entries(windows).map((value) => {
@@ -57,7 +74,7 @@ const DigitalTwin = (props) => {
})} })}
</div> </div>
)} )}
{misc_windows != null && ( {misc_windows && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Misc Windows</h3> <h3>Misc Windows</h3>
{Object.entries(misc_windows).map((value) => { {Object.entries(misc_windows).map((value) => {
@@ -65,7 +82,7 @@ const DigitalTwin = (props) => {
})} })}
</div> </div>
)} )}
{sunroof != null && ( {sunroof && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Sunroof</h3> <h3>Sunroof</h3>
{Object.entries(sunroof).map((value) => { {Object.entries(sunroof).map((value) => {
@@ -73,7 +90,7 @@ const DigitalTwin = (props) => {
})} })}
</div> </div>
)} )}
{location != null && ( {location && (
<div className={classes.popupSection}> <div className={classes.popupSection}>
<h3>Location</h3> <h3>Location</h3>
{Object.entries(location).map((value) => { {Object.entries(location).map((value) => {