Skip to content

Commit

Permalink
Fix kW dispaly
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualzone committed Apr 21, 2024
1 parent 01e63ea commit 4bd326c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend-node/src/app/vehicle/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function PageVehicle() {
const [tibberToken, setTibberToken] = useState('')
const [vehicleState, setVehicleState] = useState({} as any)
const [chargingEvents, setChargingEvents] = useState([] as any)
const [maxChargingPower, setMaxChargingPower] = useState('0 kW')

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -82,6 +83,7 @@ export default function PageVehicle() {
const e = await getAPI("/api/1/tesla/my_vehicle/" + vin);
setVehicleDetails(e.vehicle);
setVehicleState(e.state);
updateMaxChargingPower(e.vehicle.max_amps, e.vehicle.num_phases);
//loadVehicleState(e.vin);
loadLatestChargingEvents(e.vehicle.vin);
setVehicle(e.vehicle);
Expand Down Expand Up @@ -138,7 +140,7 @@ export default function PageVehicle() {
return 'Unknown';
}

function getMaxChargingPower() {
function updateMaxChargingPower(maxAmps: number, numPhases: number) {
let i = 0;
if (maxAmps !== undefined && maxAmps !== undefined) {
i = maxAmps!;
Expand All @@ -149,9 +151,10 @@ export default function PageVehicle() {
}
let p = i * phases * 230;
if (p > 1000) {
return Math.round(p / 1000) + " kW";
setMaxChargingPower(Math.round(p / 1000) + " kW");
return;
}
return p + " W";
setMaxChargingPower(p + " W");
}

function manualControlTestDrive() {
Expand Down Expand Up @@ -209,7 +212,7 @@ export default function PageVehicle() {
</Form.Group>
<Form.Group as={Row}>
<Form.Label column={true} className="sm-4">Max. Amps: {maxAmps} A</Form.Label>
<Col sm={8} style={{ 'paddingTop': '7px', 'paddingBottom': '7px' }}><Form.Range min={1} max={32} value={maxAmps} onChange={e => setMaxAmps(Number(e.target.value))} /></Col>
<Col sm={8} style={{ 'paddingTop': '7px', 'paddingBottom': '7px' }}><Form.Range min={1} max={32} value={maxAmps} onChange={e => { setMaxAmps(Number(e.target.value)); updateMaxChargingPower(Number(e.target.value), numPhases) }} /></Col>
</Form.Group>
<Form.Group as={Row}>
<Form.Label column={true} className="sm-4">Num. Phases:</Form.Label>
Expand All @@ -218,7 +221,7 @@ export default function PageVehicle() {
aria-label="Number of Phases"
required={chargingEnabled}
value={numPhases}
onChange={e => setNumPhases(Number(e.target.value))}>
onChange={e => { setNumPhases(Number(e.target.value)); updateMaxChargingPower(maxAmps, Number(e.target.value)) }}>
<option value="1">uniphase</option>
<option value="3">three-phase</option>
</Form.Select>
Expand All @@ -227,7 +230,7 @@ export default function PageVehicle() {
<Form.Group as={Row}>
<Form.Label column={true} className="sm-4"></Form.Label>
<Col sm={8}>
<Form.Control plaintext={true} readOnly={true} defaultValue={'Up to ' + getMaxChargingPower()} />
<Form.Control plaintext={true} readOnly={true} value={'Up to ' + maxChargingPower} />
</Col>
</Form.Group>
<Form.Group as={Row}>
Expand Down

0 comments on commit 4bd326c

Please sign in to comment.