Skip to content

Commit

Permalink
Merge branch 'v0.2.0' into fix-watt-threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
flixlix authored Apr 14, 2024
2 parents 40d3771 + 0f3e59a commit 2072e63
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 53 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"watch": "rollup -c --watch",
"typecheck": "tsc --noEmit",
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache"
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
"precommit": "pnpm typecheck && pnpm format:write"
},
"dependencies": {
"@material/mwc-ripple": "^0.19.1",
Expand Down
28 changes: 20 additions & 8 deletions src/components/spans/generalSecondarySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ export const generalSecondarySpan = (
main: PowerFlowCardPlus,
config: PowerFlowCardPlusConfig,
templatesObj: TemplatesObj,
field,
field: {
secondary: {
has: any;
template: any;
entity: any;
icon: any;
state: string | number | null;
unit: string | undefined;
unit_white_space: boolean | undefined;
decimals: number | undefined;
accept_negative: boolean | undefined;
};
},
key: string
) => {
return html` ${field?.secondary?.has || field?.secondary?.template
Expand All @@ -20,14 +32,14 @@ export const generalSecondarySpan = (
className: key,
entityId: field.secondary.entity,
icon: field.secondary.icon,
value: displayValue({
value: displayValue(
hass,
value: field.secondary.state,
unit: field.secondary.unit,
unitWhiteSpace: field.secondary.unit_white_space,
decimals: field.secondary.decimals,
watt_threshold: config.watt_threshold,
}),
field.secondary.state,
field.secondary.unit,
field.secondary.unit_white_space,
field.secondary.decimals,
field.secondary.accept_negative
),
template: templatesObj[`${key}Secondary`],
})}`
: ""}`;
Expand Down
19 changes: 11 additions & 8 deletions src/components/spans/individualSecondarySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export const individualSecondarySpan = (
const templateResult: string | undefined = templatesObj.individual[index];

const value = individual?.secondary?.has
? displayValue({
? displayValue(
hass,
value: individual.secondary.state,
unit: individual.secondary?.unit ?? undefined,
unitWhiteSpace: individual.secondary.unit_white_space,
decimals: individual.secondary.decimals ?? undefined,
watt_threshold: config.watt_threshold,
})
individual?.secondary?.state,
individual?.secondary?.unit || undefined,
individual?.secondary.unit_white_space,
individual?.secondary.decimals || 0,
individual?.secondary.accept_negative || false
)
: undefined;

const shouldShowSecondary = () => {
Expand All @@ -39,7 +39,10 @@ export const individualSecondarySpan = (
if (individual?.secondary?.displayZero === true) return true;

const toleranceSet = individual?.secondary?.displayZeroTolerance ?? 0;
return Number(individual.secondary.state) >= toleranceSet;
return (
Number(individual.secondary.state) >= toleranceSet ||
(individual.secondary.accept_negative && typeof Number(+individual.secondary.state) === "number")
);
};

return html` ${shouldShowSecondary()
Expand Down
3 changes: 2 additions & 1 deletion src/localize/languages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fosilní palivo",
"home": "Dům",
"individual": "Individuální",
"accept_negative": "Přijmout záporné hodnoty",
"advanced": "Pokročilá nastavení",
"decimals": "Desetinná místa",
"consumption": "Spotřeba",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Průhlednost",
"grey_color": "Šedá barva"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fossile Brennstoffe",
"home": "Zuhause",
"individual": "Individuell",
"accept_negative": "Negative Werte akzeptieren",
"advanced": "Erweiterte Optionen",
"decimals": "Dezimalstellen",
"consumption": "Verbrauch",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparenz",
"grey_color": "Graue Farbe"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/dk.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fossilt Brændstof",
"home": "Hjem",
"individual": "Individuel",
"accept_negative": "Accepter negative værdier",
"advanced": "Avancerede indstillinger",
"decimals": "Decimaler",
"consumption": "Forbrug",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparens",
"grey_color": "Grå Farve"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fossil Fuel",
"home": "Home",
"individual": "Individual",
"accept_negative": "Accept Negative",
"advanced": "Advanced Options",
"decimals": "Decimals",
"consumption": "Consumption",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparency",
"grey_color": "Grey Color"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Combustible Fósil",
"home": "Inicio",
"individual": "Individual",
"accept_negative": "Aceptar valores negativos",
"advanced": "Opciones Avanzadas",
"decimals": "Decimales",
"consumption": "Consumo",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparencia",
"grey_color": "Color Gris"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fossiilinen polttoaine",
"home": "Koti",
"individual": "Yksittäinen",
"accept_negative": "Hyväksy negatiiviset arvot",
"advanced": "Lisäasetukset",
"decimals": "Desimaalit",
"consumption": "Kulutus",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Läpinäkyvyys",
"grey_color": "Harmaa väri"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Carburant fossile",
"home": "Domicile",
"individual": "Individuel",
"accept_negative": "Accepter les valeurs négatives",
"advanced": "Options avancées",
"decimals": "Décimales",
"consumption": "Consommation",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparence",
"grey_color": "Couleur grise"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Carburante Fossile",
"home": "Casa",
"individual": "Individuale",
"accept_negative": "Accetta Valori Negativi",
"advanced": "Opzioni Avanzate",
"decimals": "Decimali",
"consumption": "Consumo",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Trasparenza",
"grey_color": "Colore Sfumato"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fossiele Brandstof",
"home": "Thuis",
"individual": "Individueel",
"accept_negative": "Negatieve waarden accepteren",
"advanced": "Geavanceerde Opties",
"decimals": "Decimalen",
"consumption": "Verbruik",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparantie",
"grey_color": "Grijstint"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Paliwo kopalne",
"home": "Dom",
"individual": "Indywidualne",
"accept_negative": "Akceptuj wartości ujemne",
"advanced": "Zaawansowane opcje",
"decimals": "Miejsca po przecinku",
"consumption": "Zużycie",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Przezroczystość",
"grey_color": "Kolor szary"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Combustíveis Fósseis",
"home": "Casa",
"individual": "Individual",
"accept_negative": "Aceitar Valores Negativos",
"advanced": "Opções Avançadas",
"decimals": "Casas Decimais",
"consumption": "Consumo",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparência",
"grey_color": "Cor do Cinza"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Combustíveis Fósseis",
"home": "Casa",
"individual": "Individual",
"accept_negative": "Aceitar Valores Negativos",
"advanced": "Opções Avançadas",
"decimals": "Casas Decimais",
"consumption": "Consumo",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparência",
"grey_color": "Cor Cinzenta"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Полный объем ископаемого топлива",
"home": "Домашняя",
"individual": "Индивидуальная",
"accept_negative": "Принять отрицательные значения",
"advanced": "Расширенные настройки",
"decimals": "Десятичные",
"consumption": "Потребление",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Прозрачность",
"grey_color": "Серый цвет"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fossil_fuel_percentage": "Fosílne palivo",
"home": "Doma",
"individual": "Individuálne",
"accept_negative": "Povoliť záporné hodnoty",
"advanced": "Pokročilé nastavenia",
"decimals": "Desatinné",
"consumption": "Spotreba",
Expand Down Expand Up @@ -71,4 +72,4 @@
"transparency": "Transparentnosť",
"grey_color": "Šedá farba"
}
}
}
4 changes: 4 additions & 0 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class PowerFlowCardPlus extends LitElement {
icon: entities.grid?.secondary_info?.icon,
unit: entities.grid?.secondary_info?.unit_of_measurement,
unit_white_space: entities.grid?.secondary_info?.unit_white_space,
accept_negative: entities.grid?.secondary_info?.accept_negative || false,
color: {
type: entities.grid?.secondary_info?.color_value,
},
Expand All @@ -206,6 +207,7 @@ export class PowerFlowCardPlus extends LitElement {
decimals: entities.solar?.secondary_info?.decimals,
template: entities.solar?.secondary_info?.template,
has: entities.solar?.secondary_info?.entity !== undefined,
accept_negative: entities.solar?.secondary_info?.accept_negative || false,
state: getSolarSecondaryState(this.hass, this._config),
icon: entities.solar?.secondary_info?.icon,
unit: entities.solar?.secondary_info?.unit_of_measurement,
Expand Down Expand Up @@ -256,6 +258,7 @@ export class PowerFlowCardPlus extends LitElement {
template: entities.home?.secondary_info?.template,
has: entities.home?.secondary_info?.entity !== undefined,
state: getHomeSecondaryState(this.hass, this._config),
accept_negative: entities.home?.secondary_info?.accept_negative || false,
unit: entities.home?.secondary_info?.unit_of_measurement,
unit_white_space: entities.home?.secondary_info?.unit_white_space,
icon: entities.home?.secondary_info?.icon,
Expand Down Expand Up @@ -283,6 +286,7 @@ export class PowerFlowCardPlus extends LitElement {
template: entities.fossil_fuel_percentage?.secondary_info?.template,
has: entities.fossil_fuel_percentage?.secondary_info?.entity !== undefined,
state: getNonFossilSecondaryState(this.hass, this._config),
accept_negative: entities.fossil_fuel_percentage?.secondary_info?.accept_negative || false,
icon: entities.fossil_fuel_percentage?.secondary_info?.icon,
unit: entities.fossil_fuel_percentage?.secondary_info?.unit_of_measurement,
unit_white_space: entities.fossil_fuel_percentage?.secondary_info?.unit_white_space,
Expand Down
2 changes: 1 addition & 1 deletion src/states/raw/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getSecondaryState = (hass: HomeAssistant, config: PowerFlowCardPlus
const entityObj = hass.states[entity];
const secondaryState = entityObj.state;

if (isNumberValue(secondaryState)) return Math.abs(Number(secondaryState));
if (isNumberValue(secondaryState)) return Number(secondaryState);

return secondaryState;
};
Expand Down
3 changes: 3 additions & 0 deletions src/states/raw/individual/getIndividualObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const fallbackIndividualObject: IndividualObject = {
unit: null,
unit_white_space: false,
displayZero: false,
accept_negative: false,
displayZeroTolerance: 0,
decimals: null,
},
Expand Down Expand Up @@ -57,6 +58,7 @@ export type IndividualObject = {
unit: string | null;
unit_white_space: boolean;
displayZero: boolean;
accept_negative: boolean;
displayZeroTolerance: number;
decimals: number | null;
};
Expand Down Expand Up @@ -94,6 +96,7 @@ export const getIndividualObject = (hass: HomeAssistant, field: IndividualDevice
template: field?.secondary_info?.template || null,
has: field?.secondary_info?.entity !== undefined,
state: getIndividualSecondaryState(hass, field) || null,
accept_negative: field?.secondary_info?.accept_negative || false,
icon: field?.secondary_info?.icon || null,
unit: field?.secondary_info?.unit_of_measurement || null,
unit_white_space: field?.secondary_info?.unit_white_space || false,
Expand Down
2 changes: 1 addition & 1 deletion src/states/raw/individual/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getIndividualSecondaryState = (hass: HomeAssistant, field: Individu
const entityObj = getEntityStateObj(hass, field?.secondary_info?.entity);
const secondaryState = entityObj?.state;

if (isNumberValue(secondaryState)) return Math.abs(Number(secondaryState));
if (isNumberValue(secondaryState)) return Number(secondaryState);

return secondaryState;
};
3 changes: 0 additions & 3 deletions src/style/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ export const allDynamicStyles = (
const colors = ["#d0cc5b", "#964cb5", "#b54c9d", "#5bd0cc"];
const fieldNames: string[] = ["left-top", "left-bottom", "right-top", "right-bottom"];

if (!fieldNames?.[index]) {
console.log("\x1b[41m%s\x1b[0m", "src/style/all.ts:230 field, index", field, index);
}
const fieldName = fieldNames?.[index] || "left-top";

let individualColor = field?.color;
Expand Down
2 changes: 2 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type SecondaryInfoType = {
display_zero_tolerance?: number;
color_value?: boolean | "production" | "consumption";
template?: string;
accept_negative?: boolean;
decimals?: number;
};

Expand Down Expand Up @@ -130,6 +131,7 @@ export type GridObject = {
icon?: string;
unit?: string;
unit_white_space?: boolean;
accept_negative?: boolean;
color?: {
type?: boolean | "production" | "consumption";
};
Expand Down
Loading

0 comments on commit 2072e63

Please sign in to comment.