Skip to content

Commit

Permalink
started to show and hide units
Browse files Browse the repository at this point in the history
  • Loading branch information
t1gr0u committed Oct 27, 2023
1 parent 24cd212 commit 226991a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class RainGaugeCardEditor extends ScopedRegistryHost(LitElement) implemen
return this._config?.entity || '';
}

get _hide_units(): boolean {
return this._config?.hide_units || false;
}

get _is_imperial(): boolean {
return this._config?.is_imperial || false;
}
Expand Down Expand Up @@ -117,6 +121,13 @@ export class RainGaugeCardEditor extends ScopedRegistryHost(LitElement) implemen
.configValue=${'fill_drop_colour'}
@input=${this._valueChanged}
></mwc-textfield>
<mwc-formfield .label=${`Show units?`}>
<mwc-switch
.checked=${this._hide_units !== false}
.configValue=${'hide_units'}
@change=${this._valueChanged}
></mwc-switch>
</mwc-formfield>
<mwc-formfield .label=${`Is imperial?`}>
<mwc-switch
.checked=${this._is_imperial !== false}
Expand Down
29 changes: 18 additions & 11 deletions src/rain-gauge-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export class RainGaugeCard extends LitElement {

let maxLevel = 40

const hideUnits = this.config.hide_units || false

let unitOfMeasurement = 'mm'
if (this.config.is_imperial) {
unitOfMeasurement = 'in'
Expand Down Expand Up @@ -164,17 +166,7 @@ export class RainGaugeCard extends LitElement {
</div>
</div>
</div>
<div>
<div>
<p>
<span style="font-weight: bold;">${localize('common.total', '', '', this.config.language)}</span><br/>
${stateValue} ${unitOfMeasurement}
</p>
</div>
<div>
${this._showHourlyRate(hourlyRateEntityState, hourlyRateStateValue, unitOfMeasurement)}
</div>
</div>
${this._showUnits(hideUnits, stateValue, hourlyRateEntityState, hourlyRateStateValue, unitOfMeasurement)}
</div>
</ha-card>
`;
Expand All @@ -188,6 +180,21 @@ export class RainGaugeCard extends LitElement {
</p>`
}

private _showUnits(hide: boolean, stateValue: number, hourlyRateEntityState: any | undefined, hourlyRateStateValue: number, unitOfMeasurement: string): TemplateResult | void {
if (hide) return
return html`<div>
<div>
<p>
<span style="font-weight: bold;">${localize('common.total', '', '', this.config.language)}</span><br/>
${stateValue} ${unitOfMeasurement}
</p>
</div>
<div>
${this._showHourlyRate(hourlyRateEntityState, hourlyRateStateValue, unitOfMeasurement)}
</div>
</div>`
}

private _handleAction(ev: ActionHandlerEvent): void {
if (this.hass && this.config && ev.detail.action) {
handleAction(this, this.hass, this.config, ev.detail.action);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface RainGaugeCardConfig extends LovelaceCardConfig {
test_gui?: boolean;
entity?: string;
language?: string;
hide_units?: boolean;
is_imperial?: boolean;
max_level?: number;
hourly_rate_entity?: string;
Expand Down

0 comments on commit 226991a

Please sign in to comment.