Skip to content

Commit

Permalink
Humanise adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Sep 15, 2024
1 parent 338622b commit 5e2f004
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/irrigation-unlimited-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
LovelaceCardEditor,
} from "./types";
import { CARD_VERSION } from "./const";
import { date_to_str } from "./util";
import { date_to_str, humanise_adjustment } from "./util";
import { localise } from "./localize";

const loc = new localise(window.navigator.language);
Expand Down Expand Up @@ -336,7 +336,7 @@ export class IrrigationUnlimitedCard extends LitElement {
</div>
<div class="iu-td6 iu-adjustment">
<div ?hidden=${!isEnabled || isBlocked || suspended || isManual}>
${adjustment}
${humanise_adjustment(adjustment)}
</div>
</div>
<div class="iu-td7">
Expand Down Expand Up @@ -403,7 +403,9 @@ export class IrrigationUnlimitedCard extends LitElement {
<div class="iu-td3">${startStr}</div>
<div class="iu-td4 iu-schedule">${schedule_name}</div>
<div class="iu-td5 iu-duration">${duration}</div>
<div class="iu-td6 iu-adjustment">${timeline.adjustment}</div>
<div class="iu-td6 iu-adjustment">
${humanise_adjustment(timeline.adjustment)}
</div>
<div class="iu-td7"></div>
</div>
</div>
Expand Down Expand Up @@ -497,7 +499,7 @@ export class IrrigationUnlimitedCard extends LitElement {
</div>
</div>
<div class="iu-td6 iu-adjustment">
<div ?hidden=${isManual}>${adjustment}</div>
<div ?hidden=${isManual}>${humanise_adjustment(adjustment)}</div>
</div>
<div class="iu-td7">
${this._renderMenu(
Expand Down Expand Up @@ -589,7 +591,9 @@ export class IrrigationUnlimitedCard extends LitElement {
</div>
</div>
<div class="iu-td6 iu-adjustment">
<div ?hidden=${isManual}>${sequenceZone.adjustment}</div>
<div ?hidden=${isManual}>
${humanise_adjustment(sequenceZone.adjustment ?? "")}
</div>
</div>
<div class="iu-td7">
${this._renderMenu(
Expand Down
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ export function elapsed_secs(d1: Date, d2: Date): number {
export function percent_completed(elapsed: number, total: number): number {
return Math.round((elapsed / total) * 100);
}

export function humanise_adjustment(value: string): string {
if (value && value.length > 0 && value[0] === "%")
return value.substring(1) + "%";
return value;
}

0 comments on commit 5e2f004

Please sign in to comment.