Skip to content

Commit

Permalink
Add support for Price Injection (Surplus) (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Martin Gonzalez <[email protected]>
  • Loading branch information
sargue and danimart1991 committed Apr 2, 2024
1 parent 67f6e2b commit 86a4764
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion dist/pvpc-hourly-pricing-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const locale = {
show_graph: "Mostrar Gràfic",
show_info: "Mostrar Informació",
graph_baseline_zero: "Línia base zero (Gràfic)",
optionInjection: "Entitat preu injecció (Opcional)",
},
da: {
minPrice: "Minimumspris i dag:",
Expand All @@ -33,6 +34,7 @@ const locale = {
show_graph: "Vis graf",
show_info: "Vis information",
graph_baseline_zero: "Nul baseline (graf)",
optionInjection: "Injektionsprisenhed (valgfrit)",
},
de: {
minPrice: "Minimalpreis heute:",
Expand All @@ -47,6 +49,7 @@ const locale = {
show_graph: "Grafik anzeigen",
show_info: "Informationen anzeigen",
graph_baseline_zero: "Null-Basislinie (Grafik)",
optionInjection: "Injektionspreiseinheit (optional)",
},
en: {
minPrice: "Lowest price today:",
Expand All @@ -61,6 +64,7 @@ const locale = {
show_graph: "Show Graph",
show_info: "Show Info",
graph_baseline_zero: "Baseline zero (Graph)",
optionInjection: "Injection price entity (Optional)",
},
es: {
minPrice: "Precio mínimo hoy:",
Expand All @@ -75,6 +79,7 @@ const locale = {
show_graph: "Mostrar Gráfico",
show_info: "Mostrar Información",
graph_baseline_zero: "Línea base cero (Gráfico)",
entity_injection: "Entidad precio inyección (Opcional)",
},
fr: {
minPrice: "Prix minimum aujourd'hui:",
Expand All @@ -89,6 +94,7 @@ const locale = {
show_graph: "Afficher le graphique",
show_info: "Afficher les informations",
graph_baseline_zero: "Référence zéro (graphique)",
entity_injection: "Entité de prix d'injection (facultatif)",
},
nl: {
minPrice: "Minimumspris i dag:",
Expand All @@ -103,6 +109,7 @@ const locale = {
show_graph: "Show Graph",
show_info: "Informatie weergeven",
graph_baseline_zero: "Nul basislijn (Graph)",
entity_injection: "Injectieprijsentiteit (optioneel)",
},
pt: {
minPrice: "Preço mínimo hoje:",
Expand All @@ -117,6 +124,7 @@ const locale = {
show_graph: "Mostrar Gráfico",
show_info: "Mostrar Informação",
graph_baseline_zero: "Linha de base zero (Gráfico)",
entity_injection: "Entidade de preço de injeção (opcional)",
},
ru: {
minPrice: "Минимальная цена сегодня:",
Expand All @@ -131,6 +139,7 @@ const locale = {
show_graph: "Показать график",
show_info: "Показать информацию",
graph_baseline_zero: "Нулевая базовая линия (график)",
entity_injection: "Объект цены впрыска (необязательно)",
},
sk: {
minPrice: "Najnižšia cena dnes:",
Expand All @@ -145,6 +154,7 @@ const locale = {
show_graph: "Zobraziť graf",
show_info: "Zobraziť informácie",
graph_baseline_zero: "Východisková nula (graf)",
entity_injection: "Entidad precio inyección (Opcional)",
},
sv: {
minPrice: "Lägsta pris idag:",
Expand All @@ -160,6 +170,7 @@ const locale = {
show_graph: "Visa graf",
show_info: "Visa information",
graph_baseline_zero: "Noll baslinje (graf)",
entity_injection: "Subjekt ceny vstrekovania (voliteľné)",
},
};

Expand Down Expand Up @@ -250,6 +261,16 @@ class PVPCHourlyPricingCard extends LitElement {
if (!this.pvpcHourlyPricingObj) return;

this.despiction = this.getDespiction(this.pvpcHourlyPricingObj.attributes);

this.injectionHourlyPricingObj =
this._config.entity_injection in this.hass.states
? this.hass.states[this._config.entity_injection]
: null;
if (!this.injectionHourlyPricingObj) return;

this.despictionInjection = this.getDespiction(
this.injectionHourlyPricingObj.attributes
);
}

shouldUpdate(changedProps) {
Expand Down Expand Up @@ -458,11 +479,15 @@ class PVPCHourlyPricingCard extends LitElement {
const todayColor = "#377eb8";
const tomorrowColor = "#ff7f00";
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const minIndex = this.despiction.minIndex;
const maxIndex = this.despiction.maxIndex;
const minIndexNextDay = this.despiction.minIndexNextDay;
const maxIndexNextDay = this.despiction.maxIndexNextDay;
const hasNextDayData = this.despiction.pricesNextDay[0] !== undefined;
const hasNextDayInjectionData =
this.despictionInjection.pricesNextDay[0] !== undefined;
const minIcon = "▼";
const maxIcon = "▲";

Expand Down Expand Up @@ -657,7 +682,7 @@ class PVPCHourlyPricingCard extends LitElement {

if (hasNextDayData) {
chartOptions.data.datasets.push({
label: that.getDateString(today.setDate(today.getDate() + 1)),
label: that.getDateString(tomorrow),
data: this.despiction.pricesNextDay,
pointRadius: 0,
borderColor: tomorrowColor,
Expand All @@ -668,6 +693,34 @@ class PVPCHourlyPricingCard extends LitElement {
});
}

if (this.despictionInjection) {
chartOptions.data.datasets.push({
label: that.getDateString(today),
data: this.despictionInjection.prices,
pointRadius: 0,
borderColor: todayColor,
backgroundColor: todayColor + "7F",
fill: false,
stepped: "before",
spanGaps: true,
borderDash: [4, 4],
});

if (hasNextDayInjectionData) {
chartOptions.data.datasets.push({
label: that.getDateString(tomorrow),
data: this.despictionInjection.pricesNextDay,
pointRadius: 0,
borderColor: tomorrowColor,
backgroundColor: tomorrowColor + "7F",
fill: false,
stepped: "before",
spanGaps: true,
borderDash: [4, 4],
});
}
}

if (this._config.graph_baseline_zero) {
chartOptions.options.scales.y.suggestedMin = 0;
}
Expand Down Expand Up @@ -860,6 +913,11 @@ export class PVPCHourlyPricingCardEditor extends LitElement {
required: true,
selector: { entity: { domain: "sensor" } },
},
{
name: "entity_injection",
required: false,
selector: { entity: { domain: "sensor" } },
},
{
name: "",
type: "expandable",
Expand Down

0 comments on commit 86a4764

Please sign in to comment.