Skip to content

Commit

Permalink
Add multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Aug 29, 2023
1 parent 3f6af70 commit eb9502a
Show file tree
Hide file tree
Showing 25 changed files with 191 additions and 122 deletions.
4 changes: 3 additions & 1 deletion components/charts/AllAreaChartLongTerm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export default function AllAreaChartLongTerm(props: AllAreaLongTermChartProps) {
{props.priceFactor && (
<>
<p>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart1"} lang={props.lang}>Elpriset som visas i tabellen baseras på följande formel: ([spotpris] +</span>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart1"} lang={props.lang}>Elpriset som visas i tabellen baseras på följande formel: (([spotpris]*</span>
<span>{props.multiplicator}</span>
<span>) +</span>
<span>{props.extra}</span>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart2"} lang={props.lang}>(avgifter)) *</span>
<span>{props.factor}</span>
Expand Down
5 changes: 3 additions & 2 deletions components/charts/SingleAreaChartLongTerm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ export default function SingleAreaLongTermChart(props: SingleAreaLongTermChartPr
{props.priceFactor && (
<>
<p>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart1"} lang={props.lang}>Elpriset som visas i tabellen baseras på följande formel: ([spotpris] +</span>
<span>{props.extra}</span>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart1"} lang={props.lang}>Elpriset som visas i tabellen baseras på följande formel: (([spotpris]*</span>
<span>{props.multiplicator}</span>
<span>) +</span>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart2"} lang={props.lang}>(avgifter)) *</span>
<span>{props.factor}</span>
<span data-t-key={"common.longtermchart.priceFactorDescriptionPart3"} lang={props.lang}>(moms). Detta är justerat efter dina nuvarande inställningar.</span>
Expand Down
20 changes: 20 additions & 0 deletions components/layout/Customize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { useCallback, useState } from "preact/hooks";
interface CustomizeProps {
extra: number;
factor: number;
multiplier: number;
setUnit: Function;
setFactor: Function;
setMultiplier: Function;
setExtra: Function;
decimals: number;
setDecimals: Function;
Expand All @@ -27,6 +29,11 @@ export default function Table(props: CustomizeProps) {
props.setFactor(parseFloat(f));
};

const setMultiplierStored = (f: string) => {
localStorage.setItem("sw_multiplier", f);
props.setMultiplier(parseFloat(f));
};

const setExtraStored = (e: string) => {
localStorage.setItem("sw_extra", e);
props.setExtra(parseFloat(e));
Expand Down Expand Up @@ -75,6 +82,19 @@ export default function Table(props: CustomizeProps) {
>
</input>
</div>
<div class="sidebar-content">
<label for="multiplier" data-toggle="tooltip" data-t-key="common.customize.multiplier" lang={props.lang}>Multiplikator</label>
<input
class="form-control"
type="text"
name="multiplier"
disabled={!props.disabled}
value={props.multiplier}
onChange={(e) => setMultiplierStored((e.target as HTMLInputElement).value)}
placeholder="Multiplikator (t.ex. 1.02 för 2% prispåslag)"
>
</input>
</div>
<div class="sidebar-content">
<label for="factor" data-toggle="tooltip" data-t-key="common.customize.factor" lang={props.lang}>Faktor</label>
<input
Expand Down
1 change: 1 addition & 0 deletions components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommonProps } from "utils/common.ts";
interface SidebarProps extends CommonProps {
setUnit: Function;
setFactor: Function;
setMultiplier: Function;
setExtra: Function;
setDecimals: Function;
setPriceFactor: Function;
Expand Down
1 change: 1 addition & 0 deletions components/layout/SwHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function SwHead(props: HeadProps) {
const priceProps = {
currency: preferences.currency(props.data.lang),
unit: preferences.unit(),
multiplier: 1,
factor: 1,
extra: 0,
decimals: 5,
Expand Down
1 change: 1 addition & 0 deletions components/partials/PriceFactorWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "preact/hooks";
interface PriceFactorWarningProps {
extra: number;
factor: number;
multiplier: number;
priceFactor: boolean;
lang: string;
}
Expand Down
5 changes: 5 additions & 0 deletions config/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const defaultFactor = () => {
return "1";
};

const defaultMultiplier = () => {
return "1";
};

const defaultDecimals = (lang) => {
const usedCurrency = localStorage.getItem("sw_currency") ?? defaultCurrency(lang);
if (usedCurrency === "öre") {
Expand All @@ -42,6 +46,7 @@ const preferences = {
lang: (lang) => localStorage.getItem("sw_lang") ?? lang,
currency: (lang) => localStorage.getItem("sw_currency") ?? defaultCurrency(lang),
unit: () => localStorage.getItem("sw_unit") ?? "kWh",
multiplier: () => parseFloat(localStorage.getItem("sw_multiplier") ?? defaultMultiplier()),
factor: (lang) => parseFloat(localStorage.getItem("sw_factor") ?? defaultFactor(lang)),
extra: (lang) => parseFloat(localStorage.getItem("sw_extra") ?? defaultExtra(lang)),
decimals: (lang) => parseInt(localStorage.getItem("sw_decimals") ?? defaultDecimals(lang), 10),
Expand Down
1 change: 1 addition & 0 deletions config/translations/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const de = {
"fees": "Gebühren",
"factor": "Faktor",
"decimals": "Dezimalstellen",
"multiplier": "Multiplikator"
},
"countries": {
"sv": "Schweden",
Expand Down
1 change: 1 addition & 0 deletions config/translations/dk.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const dk = {
"fees": "Afgifter",
"factor": "Faktor",
"decimals": "Decimaler",
"multiplier": "Multiplikator"
},
"countries": {
"sv": "Sverige",
Expand Down
1 change: 1 addition & 0 deletions config/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const en = {
"fees": "Fees",
"factor": "Factor",
"decimals": "Decimals",
"multiplier": "Multiplier"
},
"countries": {
"sv": "Sweden",
Expand Down
1 change: 1 addition & 0 deletions config/translations/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const es = {
"fees": "Tarifas",
"factor": "Factor",
"decimals": "decimales",
"multiplier": "Multiplicador"
},
"countries": {
"sv": "Suecia",
Expand Down
1 change: 1 addition & 0 deletions config/translations/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const fi = {
"fees": "Maksut",
"factor": "Tekijä",
"decimals": "Desimaalit",
"multiplier": "Kerroin"
},
"countries": {
"sv": "Ruotsi",
Expand Down
1 change: 1 addition & 0 deletions config/translations/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const fr = {
"fees": "Frais",
"factor": "Facteur",
"decimals": "Décimales",
"multiplier": "Multiplikator"
},
"countries": {
"sv": "Suède",
Expand Down
1 change: 1 addition & 0 deletions config/translations/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const nl = {
"fees": "kosten",
"factor": "Factor",
"decimals": "Decimalen",
"multiplier": "Vermenigvuldiger"
},
"countries": {
"sv": "Sweden",
Expand Down
1 change: 1 addition & 0 deletions config/translations/no.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const no = {
"fees": "Avgifter",
"factor": "Faktor",
"decimals": "Desimaler",
"multiplier": "Multiplikator"
},
"countries": {
"sv": "Sverige",
Expand Down
1 change: 1 addition & 0 deletions config/translations/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const sv = {
"fees": "Avgifter",
"factor": "Faktor",
"decimals": "Decimaler",
"multiplier": "Multiplikator"
},
"countries": {
"sv": "Sverige",
Expand Down
3 changes: 3 additions & 0 deletions islands/AreaIsland.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import SingleAreaChartLongTerm from "components/charts/SingleAreaChartLongTerm.t
export default function AreaIsland({ data }: PageProps<AreaPageProps>) {
const [currency, setCurrency] = useState(() => preferences.currency(data.lang));
const [unit, setUnit] = useState(preferences.unit);
const [multiplier, setMultiplier] = useState(() => preferences.multiplier(data.lang));
const [factor, setFactor] = useState(() => preferences.factor(data.lang));
const [extra, setExtra] = useState(() => preferences.extra(data.lang));
const [decimals, setDecimals] = useState(() => preferences.decimals(data.lang));
Expand All @@ -42,6 +43,7 @@ export default function AreaIsland({ data }: PageProps<AreaPageProps>) {
const commonprops: CommonProps = {
unit,
factor,
multiplier,
extra,
decimals,
currency,
Expand Down Expand Up @@ -75,6 +77,7 @@ export default function AreaIsland({ data }: PageProps<AreaPageProps>) {
setUnit={setUnit}
setExtra={setExtra}
setFactor={setFactor}
setMultiplier={setMultiplier}
setDecimals={setDecimals}
setPriceFactor={setPriceFactorStored}
setCurrency={setCurrency}
Expand Down
3 changes: 3 additions & 0 deletions islands/CountryIsland.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function CountryIsland({ data }: PageProps<CountryPageProps>) {
const [currency, setCurrency] = useState(() => preferences.currency(data.lang));
const [unit, setUnit] = useState(preferences.unit);
const [factor, setFactor] = useState(() => preferences.factor(data.lang));
const [multiplier, setMultiplier] = useState(() => preferences.multiplier(data.lang));
const [extra, setExtra] = useState(() => preferences.extra(data.lang));
const [decimals, setDecimals] = useState(() => preferences.decimals(data.lang));
const [priceFactor, setPriceFactor] = useState(() => preferences.pricefactor(data.lang));
Expand All @@ -39,6 +40,7 @@ export default function CountryIsland({ data }: PageProps<CountryPageProps>) {
const commonprops: CommonProps = {
unit,
factor,
multiplier,
extra,
decimals,
currency,
Expand Down Expand Up @@ -85,6 +87,7 @@ export default function CountryIsland({ data }: PageProps<CountryPageProps>) {
setUnit={setUnit}
setExtra={setExtra}
setFactor={setFactor}
setMultiplier={setMultiplier}
setDecimals={setDecimals}
setPriceFactor={setPriceFactorStored}
setCurrency={setCurrency}
Expand Down
3 changes: 3 additions & 0 deletions islands/CustomIsland.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function CustomIsland({ data }: PageProps) {
const [currency, setCurrency] = useState(() => preferences.currency(data.lang));
const [unit, setUnit] = useState(preferences.unit);
const [factor, setFactor] = useState(() => preferences.factor(data.lang));
const [multiplier, setMultiplier] = useState(() => preferences.multiplier(data.lang));
const [extra, setExtra] = useState(() => preferences.extra(data.lang));
const [decimals, setDecimals] = useState(() => preferences.decimals(data.lang));
const [priceFactor, setPriceFactor] = useState(() => preferences.pricefactor(data.lang));
Expand All @@ -21,6 +22,7 @@ export default function CustomIsland({ data }: PageProps) {

const commonprops: CommonProps = {
unit,
multiplier,
factor,
extra,
decimals,
Expand All @@ -41,6 +43,7 @@ export default function CustomIsland({ data }: PageProps) {
setUnit={setUnit}
setExtra={setExtra}
setFactor={setFactor}
setMultiplier={setMultiplier}
setDecimals={setDecimals}
setPriceFactor={setPriceFactorStored}
setCurrency={setCurrency}
Expand Down
8 changes: 7 additions & 1 deletion islands/HassIsland.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function HassIsland(props: PageProps<HassPageProps>) {
const [currency, setCurrency] = useState(preferences.currency(props.data.lang));
const [unit, setUnit] = useState(preferences.unit());
const [factor, setFactor] = useState(preferences.factor(props.data.lang));
const [multiplier, setMultiplier] = useState(() => preferences.multiplier(data.lang));
const [extra, setExtra] = useState(preferences.extra(props.data.lang));
const [decimals, setDecimals] = useState(preferences.decimals(props.data.lang));
const [priceFactor, setPriceFactor] = useState(preferences.pricefactor(props.data.lang));
Expand All @@ -26,6 +27,7 @@ export default function HassIsland(props: PageProps<HassPageProps>) {

const commonprops: CommonProps = {
unit,
multiplier,
factor,
extra,
decimals,
Expand Down Expand Up @@ -92,7 +94,7 @@ export default function HassIsland(props: PageProps<HassPageProps>) {
return [[new Date(),entity.attributes.avg_tomorrow]]`;
const hassConf = `rest:
- scan_interval: 180
resource: https://spot.56k.guru/api/v2/hass?currency=${currency}&area=SE2&extra=${extra}&factor=${factor}&decimals=${decimals}
resource: https://spot.56k.guru/api/v2/hass?currency=${currency}&area=SE2&multiplier=${multiplier}&extra=${extra}&factor=${factor}&decimals=${decimals}
sensor:
- name: "Spotprice Now"
unique_id: "56k_spotprice_now"
Expand Down Expand Up @@ -130,6 +132,7 @@ export default function HassIsland(props: PageProps<HassPageProps>) {
setUnit={setUnit}
setExtra={setExtra}
setFactor={setFactor}
setMultiplier={setMultiplier}
setDecimals={setDecimals}
setPriceFactor={setPriceFactorStored}
setCurrency={setCurrency}
Expand Down Expand Up @@ -173,6 +176,9 @@ export default function HassIsland(props: PageProps<HassPageProps>) {
<li>
<strong>extra</strong><span> - Your fees per kWh in chosen currency, before VAT. Example: <code class="code">0.05</code> for 5 cents per kWh</span>
</li>
<li>
<strong>multiplier</strong><span> - Multiplier for spot price before adding fees and VAT. <code class="code">1</code> is no multiplier, <code class="code">1.02</code> is 2% added fee on spot price before adding extra fees and VAT.</span>
</li>
<li>
<strong>factor</strong><span> - Factor for VAT. <code class="code">1</code> is no VAT, <code class="code">1.25</code> is 25% VAT and so on.</span>
</li>
Expand Down
Loading

0 comments on commit eb9502a

Please sign in to comment.