Skip to content

Commit

Permalink
Merge pull request #69 from flixlix/feat-mwh
Browse files Browse the repository at this point in the history
feat: ✨ create Mwh unit
  • Loading branch information
flixlix committed Aug 11, 2023
2 parents 6684b11 + 4b13303 commit a5a2061
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "energy-flow-card-plus",
"version": "0.1.1",
"version": "0.1.2",
"description": "Energy Flow Card Plus",
"keywords": [
"home-assistant",
Expand Down
4 changes: 3 additions & 1 deletion src/energy-flow-card-plus-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { ComboEntity, IndividualDeviceType, SecondaryInfoType, baseConfigEntity,
interface mainConfigOptions {
dashboard_link?: string;
dashboard_link_label?: string;
kwh_decimals?: number;
min_flow_rate?: number;
max_flow_rate?: number;
wh_decimals?: number;
kwh_decimals?: number;
mwh_decimals?: number;
wh_kwh_threshold?: number;
kwh_mwh_threshold?: number;
clickable_entities?: boolean;
max_expected_energy?: number;
min_expected_energy?: number;
Expand Down
14 changes: 11 additions & 3 deletions src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
}
this._config = {
...config,
kwh_decimals: coerceNumber(config.kwh_decimals, defaultValues.kilowatthourDecimals),
min_flow_rate: coerceNumber(config.min_flow_rate, defaultValues.minFlowRate),
max_flow_rate: coerceNumber(config.max_flow_rate, defaultValues.maxFlowRate),
wh_decimals: coerceNumber(config.wh_decimals, defaultValues.watthourDecimals),
kwh_decimals: coerceNumber(config.kwh_decimals, defaultValues.kilowatthourDecimals),
mwh_decimals: coerceNumber(config.mwh_decimals, defaultValues.megawatthourDecimals),
wh_kwh_threshold: coerceNumber(config.wh_kwh_threshold, defaultValues.whkWhThreshold),
kwh_mwh_threshold: coerceNumber(config.kwh_mwh_threshold, defaultValues.kwhMwhThreshold),
max_expected_energy: coerceNumber(config.max_expected_energy, defaultValues.maxExpectedEnergy),
min_expected_energy: coerceNumber(config.min_expected_energy, defaultValues.minExpectedEnergy),
};
Expand Down Expand Up @@ -236,6 +238,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
}
const value = coerceNumber(stateObj?.state);
if (stateObj?.attributes.unit_of_measurement?.toUpperCase().startsWith('KWH')) return value * 1000; // case insensitive check `KWH`
else if (stateObj?.attributes.unit_of_measurement?.toUpperCase().startsWith('MWH')) return value * 1000000; // case insensitive check `MWH`
return value;
});
const sum = valuesArr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
Expand All @@ -258,12 +261,17 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
if (value === null) return '0';
if (Number.isNaN(+value)) return value.toString();
const valueInNumber = Number(value);
const isMwh = unit === undefined && valueInNumber * 1000 >= this._config!.kwh_mwh_threshold!;
const isKWh = unit === undefined && valueInNumber >= this._config!.wh_kwh_threshold!;
const v = formatNumber(
isKWh ? round(valueInNumber / 1000, this._config!.kwh_decimals) : round(valueInNumber, decimals ?? this._config!.wh_decimals),
isMwh
? round(valueInNumber / 1000000, this._config!.mwh_decimals)
: isKWh
? round(valueInNumber / 1000, this._config!.kwh_decimals)
: round(valueInNumber, decimals ?? this._config!.wh_decimals),
this.hass.locale,
);
return `${v}${unitWhiteSpace === false ? '' : ' '}${unit || (isKWh ? 'kWh' : 'Wh')}`;
return `${v}${unitWhiteSpace === false ? '' : ' '}${unit || (isMwh ? 'MWh' : isKWh ? 'kWh' : 'Wh')}`;
};

private openDetails(event: { stopPropagation: any; key?: string }, entityId?: string | undefined): void {
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Name des Dashboard-Links",
"wh_decimals": "Wattstunden-Dezimalstellen",
"kwh_decimals": "Kilowattstunden-Dezimalstellen",
"mwh_decimals": "Megawattstunden-Dezimalstellen",
"max_flow_rate": "Maximale Flussrate",
"min_flow_rate": "Minimale Flussrate",
"max_expected_energy": "Maximale erwartete Energie",
"min_expected_energy": "Minimale erwartete Energie",
"wh_kwh_threshold": "Wattstunden-zu-Kilowattstunden-Schwelle",
"kwh_mwh_threshold": "Kilowattstunden-zu-Megawattstunden-Schwelle",
"display_zero_lines": "Nulllinien anzeigen",
"clickable_entities": "Klickbare Entitäten",
"use_new_flow_rate_model": "Neues Fluss-Modell verwenden",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Dashboard Link Name",
"wh_decimals": "Watthours Decimals",
"kwh_decimals": "Kilowatthours Decimals",
"mwh_decimals": "Megawatthours Decimals",
"max_flow_rate": "Max Flow Rate",
"min_flow_rate": "Min Flow Rate",
"max_expected_energy": "Max Expected Energy",
"min_expected_energy": "Min Expected Energy",
"wh_kwh_threshold": "Watthours to Kilowatthours Threshold",
"kwh_mwh_threshold": "Kilowatthours to Megawatthours Threshold",
"display_zero_lines": "Display Zero Lines",
"clickable_entities": "Clickable Entities",
"use_new_flow_rate_model": "New Flow Rate Model",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nombre del Enlace al Panel de Control",
"wh_decimals": "Decimales de Watthoras",
"kwh_decimals": "Decimales de Kilowatthoras",
"mwh_decimals": "Decimales de Megawatthoras",
"max_flow_rate": "Tasa Máxima de Flujo",
"min_flow_rate": "Tasa Mínima de Flujo",
"max_expected_energy": "Energía Máxima Esperada",
"min_expected_energy": "Energía Mínima Esperada",
"wh_kwh_threshold": "Umbral de Watthoras a Kilowatthoras",
"kwh_mwh_threshold": "Umbral de Kilowatthoras a Megawatthoras",
"display_zero_lines": "Mostrar Líneas Cero",
"clickable_entities": "Entidades Clicables",
"use_new_flow_rate_model": "Nuevo Modelo de Tasa de Flujo",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Ohjauspaneelin linkin nimi",
"wh_decimals": "Watittunnin desimaalit",
"kwh_decimals": "Kilowattitunnin desimaalit",
"mwh_decimals": "Megawattitunnin desimaalit",
"max_flow_rate": "Suurin virtausnopeus",
"min_flow_rate": "Pienin virtausnopeus",
"max_expected_energy": "Suurin odotettu energia",
"min_expected_energy": "Pienin odotettu energia",
"wh_kwh_threshold": "Watittuntien ja kilowattituntien raja-arvo",
"kwh_mwh_threshold": "Kilowattituntien ja megawattituntien raja-arvo",
"display_zero_lines": "Näytä nollalinjat",
"clickable_entities": "Napsautettavat yksiköt",
"use_new_flow_rate_model": "Käytä uutta virtausnopeuden mallia",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nom du lien du tableau de bord",
"wh_decimals": "Décimales des Wattheures",
"kwh_decimals": "Décimales des Kilowattheures",
"mwh_decimals": "Décimales des Mégawattheures",
"max_flow_rate": "Débit maximal",
"min_flow_rate": "Débit minimal",
"max_expected_energy": "Énergie maximale attendue",
"min_expected_energy": "Énergie minimale attendue",
"wh_kwh_threshold": "Seuil de Wattheures à Kilowattheures",
"kwh_mwh_threshold": "Seuil de Kilowattheures à Mégawattheures",
"display_zero_lines": "Afficher les lignes zéro",
"clickable_entities": "Entités cliquables",
"use_new_flow_rate_model": "Nouveau modèle de débit",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nome del collegamento al cruscotto",
"wh_decimals": "Decimali di watthora",
"kwh_decimals": "Decimali di chilowatthora",
"mwh_decimals": "Decimali di megawatthora",
"max_flow_rate": "Flusso massimo",
"min_flow_rate": "Flusso minimo",
"max_expected_energy": "Energia massima prevista",
"min_expected_energy": "Energia minima prevista",
"wh_kwh_threshold": "Soglia di wattora a chilowattora",
"kwh_mwh_threshold": "Soglia di chilowattora a megawatthora",
"display_zero_lines": "Mostra linee zero",
"clickable_entities": "Entità cliccabili",
"use_new_flow_rate_model": "Usa nuovo modello di flusso",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Naam van de dashboardlink",
"wh_decimals": "Decimalen van watthours",
"kwh_decimals": "Decimalen van kilowatthours",
"mwh_decimals": "Decimalen van megawatthours",
"max_flow_rate": "Maximale stroomsterkte",
"min_flow_rate": "Minimale stroomsterkte",
"max_expected_energy": "Maximale verwachte energie",
"min_expected_energy": "Minimale verwachte energie",
"wh_kwh_threshold": "Watthour naar kilowatthour drempel",
"kwh_mwh_threshold": "Kilowatthour naar megawatthour drempel",
"display_zero_lines": "Nullijnen weergeven",
"clickable_entities": "Klikbare entiteiten",
"use_new_flow_rate_model": "Nieuw stroomsterktemodel gebruiken",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nazwa linku do pulpitu",
"wh_decimals": "Miejsca dziesiętne watogodzin",
"kwh_decimals": "Miejsca dziesiętne kilowatogodzin",
"mwh_decimals": "Miejsca dziesiętne megawatogodzin",
"max_flow_rate": "Maksymalna szybkość przepływu",
"min_flow_rate": "Minimalna szybkość przepływu",
"max_expected_energy": "Maksymalna spodziewana energia",
"min_expected_energy": "Minimalna spodziewana energia",
"wh_kwh_threshold": "Próg watogodzin na kilowatogodziny",
"kwh_mwh_threshold": "Próg kilowatogodzin na megawatogodziny",
"display_zero_lines": "Wyświetl linie zera",
"clickable_entities": "Klikalne jednostki",
"use_new_flow_rate_model": "Użyj nowego modelu szybkości przepływu",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nome do link do painel",
"wh_decimals": "Casas decimais de watt-hora",
"kwh_decimals": "Casas decimais de quilowatt-hora",
"mwh_decimals": "Casas decimais de megawatt-hora",
"max_flow_rate": "Taxa de fluxo máxima",
"min_flow_rate": "Taxa de fluxo mínima",
"max_expected_energy": "Energia máxima esperada",
"min_expected_energy": "Energia mínima esperada",
"wh_kwh_threshold": "Limiar de watt-hora para quilowatt-hora",
"kwh_mwh_threshold": "Limiar de quilowatt-hora para megawatt-hora",
"display_zero_lines": "Exibir linhas zero",
"clickable_entities": "Entidades clicáveis",
"use_new_flow_rate_model": "Usar novo modelo de taxa de fluxo",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Nome do link do painel de controle",
"wh_decimals": "Casas decimais de watt-hora",
"kwh_decimals": "Casas decimais de quilowatt-hora",
"mwh_decimals": "Casas decimais de megawatt-hora",
"max_flow_rate": "Taxa máxima de fluxo",
"min_flow_rate": "Taxa mínima de fluxo",
"max_expected_energy": "Energia máxima esperada",
"min_expected_energy": "Energia mínima esperada",
"wh_kwh_threshold": "Limiar de watt-hora para quilowatt-hora",
"kwh_mwh_threshold": "Limiar de quilowatt-hora para megawatt-hora",
"display_zero_lines": "Mostrar linhas de zero",
"clickable_entities": "Entidades clicáveis",
"use_new_flow_rate_model": "Usar novo modelo de taxa de fluxo",
Expand Down
2 changes: 2 additions & 0 deletions src/localize/languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"dashboard_link_label": "Название ссылки на панель управления",
"wh_decimals": "Десятичные знаки ватт-часов",
"kwh_decimals": "Десятичные знаки киловатт-часов",
"mwh_decimals": "Десятичные знаки мегаватт-часов",
"max_flow_rate": "Максимальная скорость потока",
"min_flow_rate": "Минимальная скорость потока",
"max_expected_energy": "Максимальная ожидаемая энергия",
"min_expected_energy": "Минимальная ожидаемая энергия",
"wh_kwh_threshold": "Порог ватт-часов к киловатт-часам",
"kwh_mwh_threshold": "Порог киловатт-часов к мегаватт-часам",
"display_zero_lines": "Отображать нулевые линии",
"clickable_entities": "Кликабельные сущности",
"use_new_flow_rate_model": "Использовать новую модель скорости потока",
Expand Down
18 changes: 15 additions & 3 deletions src/ui-editor/schema/_schema-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const cardConfigStruct = assign(
dashboard_link_label: optional(string()),
wh_decimals: optional(integer()),
kwh_decimals: optional(integer()),
mwh_decimals: optional(integer()),
min_flow_rate: optional(number()),
max_flow_rate: optional(number()),
min_expected_energy: optional(number()),
max_expected_energy: optional(number()),
wh_kwh_threshold: optional(number()),
kwh_mwh_threshold: optional(number()),
clickable_entities: optional(boolean()),
display_zero_lines: optional(boolean()),
use_new_flow_rate_model: optional(boolean()),
Expand Down Expand Up @@ -123,12 +125,17 @@ export const advancedOptionsSchema = memoizeOne(localize => [
},
{
name: 'wh_decimals',
label: 'Watt Decimals',
label: 'Wh Decimals',
selector: { number: { mode: 'box', min: 0, max: 5, step: 1 } },
},
{
name: 'kwh_decimals',
label: 'kW Decimals',
label: 'kWh Decimals',
selector: { number: { mode: 'box', min: 0, max: 5, step: 1 } },
},
{
name: 'mwh_decimals',
label: 'MWh Decimals',
selector: { number: { mode: 'box', min: 0, max: 5, step: 1 } },
},
{
Expand All @@ -153,7 +160,12 @@ export const advancedOptionsSchema = memoizeOne(localize => [
},
{
name: 'wh_kwh_threshold',
label: 'Watt to Kilowatt Threshold',
label: 'Wh/kWh Threshold',
selector: { number: { mode: 'box', min: 0, max: 1000000, step: 1 } },
},
{
name: 'kwh_mwh_threshold',
label: 'kWh/MWh Threshold',
selector: { number: { mode: 'box', min: 0, max: 1000000, step: 1 } },
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/utils/get-default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export const defaultValues = {
minFlowRate: 1,
watthourDecimals: 1,
kilowatthourDecimals: 0,
megawatthourDecimals: 0,
minExpectedEnergy: 10,
maxExpectedEnergy: 2000,
whkWhThreshold: 1000,
kwhMwhThreshold: 1000,
};

export function getDefaultConfig(hass: HomeAssistant): EnergyFlowCardPlusConfig {
Expand Down

0 comments on commit a5a2061

Please sign in to comment.