Skip to content

Commit

Permalink
Remove blank before percent
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Nov 22, 2024
1 parent b2e4fef commit de3c1c1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/cards/chips-card/chips/weather-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class WeatherChip extends LitElement implements LovelaceChip {
>
${weatherIcon}
${displayLabels.length > 0
? html`<span>${displayLabels.join(" / ")}</span>`
? html`<span>${displayLabels.join(" ")}</span>`
: nothing}
</mushroom-chip>
`;
Expand Down
2 changes: 1 addition & 1 deletion src/cards/climate-card/climate-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class ClimateCard
stateObj,
"current_temperature"
);
stateDisplay += ` - ${temperature}`;
stateDisplay += ` ${temperature}`;
}
const rtl = computeRTL(this.hass);

Expand Down
8 changes: 6 additions & 2 deletions src/cards/cover-card/cover-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
CoverEntity,
handleAction,
Expand Down Expand Up @@ -196,7 +195,12 @@ export class CoverCard

let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.position) {
stateDisplay += ` - ${this.position}${blankBeforePercent(this.hass.locale)}%`;
const position = this.hass.formatEntityAttributeValue(
stateObj,
"current_position",
this.position
);
stateDisplay += ` ⸱ ${position}`;
}

const rtl = computeRTL(this.hass);
Expand Down
8 changes: 6 additions & 2 deletions src/cards/fan-card/fan-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
handleAction,
hasAction,
Expand Down Expand Up @@ -138,7 +137,12 @@ export class FanCard

let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.percentage != null && stateObj.state === "on") {
stateDisplay = `${this.percentage}${blankBeforePercent(this.hass.locale)}%`;
const percentage = this.hass.formatEntityAttributeValue(
stateObj,
"percentage",
this.percentage
);
stateDisplay = percentage;
}

const rtl = computeRTL(this.hass);
Expand Down
8 changes: 6 additions & 2 deletions src/cards/humidifier-card/humidifier-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { classMap } from "lit/directives/class-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
handleAction,
hasAction,
Expand Down Expand Up @@ -111,7 +110,12 @@ export class HumidifierCard

let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.humidity) {
stateDisplay = `${this.humidity}${blankBeforePercent(this.hass.locale)}%`;
const humidity = this.hass.formatEntityAttributeValue(
stateObj,
"current_humidity",
this.humidity
);
stateDisplay = humidity;
}

const rtl = computeRTL(this.hass);
Expand Down
13 changes: 8 additions & 5 deletions src/cards/light-card/light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { styleMap } from "lit/directives/style-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
handleAction,
hasAction,
Expand Down Expand Up @@ -45,7 +44,6 @@ import "./controls/light-color-control";
import "./controls/light-color-temp-control";
import { LightCardConfig } from "./light-card-config";
import {
getBrightness,
getRGBColor,
isColorLight,
isColorSuperLight,
Expand Down Expand Up @@ -157,12 +155,12 @@ export class LightCard
const stateObj = this._stateObj;

if (!stateObj) return;
this.brightness = getBrightness(stateObj);
this.brightness = stateObj.attributes.brightness;
}

private onCurrentBrightnessChange(e: CustomEvent<{ value?: number }>): void {
if (e.detail.value != null) {
this.brightness = e.detail.value;
this.brightness = (e.detail.value * 255) / 100;
}
}

Expand Down Expand Up @@ -197,7 +195,12 @@ export class LightCard

let stateDisplay = this.hass.formatEntityState(stateObj);
if (this.brightness != null) {
stateDisplay = `${this.brightness}${blankBeforePercent(this.hass.locale)}%`;
const brightness = this.hass.formatEntityAttributeValue(
stateObj,
"brightness",
this.brightness
);
stateDisplay = brightness;
}

const rtl = computeRTL(this.hass);
Expand Down
27 changes: 14 additions & 13 deletions src/cards/media-player-card/media-player-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { classMap } from "lit/directives/class-map.js";
import {
actionHandler,
ActionHandlerEvent,
blankBeforePercent,
computeRTL,
handleAction,
hasAction,
Expand Down Expand Up @@ -45,7 +44,6 @@ import {
computeMediaIcon,
computeMediaNameDisplay,
computeMediaStateDisplay,
getVolumeLevel,
} from "./utils";

type MediaPlayerCardControl = "media_control" | "volume_control";
Expand Down Expand Up @@ -137,13 +135,12 @@ export class MediaPlayerCard
const stateObj = this._stateObj;

if (!stateObj) return;
const volume = getVolumeLevel(stateObj);
this.volume = volume != null ? Math.round(volume) : volume;
this.volume = stateObj.attributes.volume_level;
}

private onCurrentVolumeChange(e: CustomEvent<{ value?: number }>): void {
if (e.detail.value != null) {
this.volume = e.detail.value;
this.volume = e.detail.value / 100;
}
}

Expand Down Expand Up @@ -173,18 +170,22 @@ export class MediaPlayerCard

const icon = computeMediaIcon(this._config, stateObj);
const nameDisplay = computeMediaNameDisplay(this._config, stateObj);
const stateDisplay = computeMediaStateDisplay(
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);
let stateDisplay = computeMediaStateDisplay(
this._config,
stateObj,
this.hass
);
const appearance = computeAppearance(this._config);
const picture = computeEntityPicture(stateObj, appearance.icon_type);

const stateValue =
this.volume != null && this._config.show_volume_level
? `${stateDisplay} - ${this.volume}${blankBeforePercent(this.hass.locale)}%`
: stateDisplay;
if (this.volume != null && this._config.show_volume_level) {
const volume = this.hass.formatEntityAttributeValue(
stateObj,
"volume_level",
this.volume
);
stateDisplay += ` ⸱ ${volume}`;
}

const rtl = computeRTL(this.hass);

Expand Down Expand Up @@ -216,7 +217,7 @@ export class MediaPlayerCard
stateObj,
appearance,
nameDisplay,
stateValue
stateDisplay
)};
</mushroom-state-item>
${isControlVisible
Expand Down
18 changes: 0 additions & 18 deletions src/ha/common/translations/blank_before_percent.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/ha/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export interface HomeAssistant {
formatEntityAttributeValue(
stateObj: HassEntity,
attribute: string,
value?: string
value?: any
): string;
formatEntityAttributeName(stateObj: HassEntity, attribute: string): string;
}
Expand Down

0 comments on commit de3c1c1

Please sign in to comment.