Skip to content

Commit

Permalink
feat: add decimal_places_energy attribute and SMA Solar support
Browse files Browse the repository at this point in the history
  • Loading branch information
slipx06 committed Apr 20, 2024
1 parent 56b2c9e commit 3d6e99f
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 35 deletions.
12 changes: 6 additions & 6 deletions dist/sunsynk-power-flow-card.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions docs/configuration.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunsynk-power-flow-card",
"version": "4.31.0",
"version": "4.32.0",
"description": "A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.",
"main": "sunsynk-power-flow-card.js",
"scripts": {
Expand All @@ -17,7 +17,7 @@
"type": "git",
"url": "git+https://github.com/slipx06/sunsynk-power-flow-card.git"
},
"author": "marksie1988 <marksie1988@users.noreply.github.com>",
"author": "slipx06 <slipx06@users.noreply.github.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/slipx06/sunsynk-power-flow-card/issues"
Expand Down
16 changes: 8 additions & 8 deletions src/cards/compact-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,36 +779,36 @@ export const compactCard = (config: sunsynkPowerFlowCardConfig, inverterImg: str
class="st10 left-align"
display="${data.batteryShowDaily !== true || !config.show_battery || !data.stateDayBatteryCharge.isValid() ? 'none' : ''}"
fill="${data.batteryColour}">
${data.stateDayBatteryCharge?.toPowerString(true, 1)}
${data.stateDayBatteryCharge?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_pv_energy_108)}>
<text id="daily_solar_value" x="200" y="26" class="st10 left-align"
display="${config.solar.display_mode === 1 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy?.toPowerString(true, 1)}
${data.stateDayPVEnergy?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_pv_energy_108)}>
<text id="remaining_solar_value" x="200" y="26" class="st10 left-align"
display="${config.solar.display_mode === 2 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy?.toPowerString(true, 1) + ' / ' + data.remainingSolar}
${data.stateDayPVEnergy?.toPowerString(true, data.decimalPlacesEnergy) + ' / ' + data.remainingSolar}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_pv_energy_108)}>
<text id="total_solar_value" x="200" y="26" class="st10 left-align"
display="${config.solar.display_mode === 3 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy?.toPowerString(true, 1) + ' / ' + data.totalSolarGeneration}
${data.stateDayPVEnergy?.toPowerString(true, data.decimalPlacesEnergy) + ' / ' + data.totalSolarGeneration}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_battery_discharge_71)}>
<text id="daily_bat_discharge_value" x="${data.compactMode ? '132' : '77.2'}" y="380.1"
class="st10 left-align"
display="${data.batteryShowDaily !== true || !config.show_battery || !data.stateDayBatteryDischarge.isValid() ? 'none' : ''}"
fill="${data.batteryColour}">
${data.stateDayBatteryDischarge?.toPowerString(true, 1)}
${data.stateDayBatteryDischarge?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_load_energy_84)}>
Expand All @@ -817,21 +817,21 @@ export const compactCard = (config: sunsynkPowerFlowCardConfig, inverterImg: str
y="${[2, 3, 4].includes(data.additionalLoad) ? '175' : '267.9'}"
class="st10 left-align" display="${!data.loadShowDaily || !data.stateDayLoadEnergy.isValid() ? 'none' : ''}"
fill="${data.loadColour}">
${data.stateDayLoadEnergy?.toPowerString(true, 1)}
${data.stateDayLoadEnergy?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_grid_import_76)}>
<text id="daily_grid_buy_value" x="5" y="267.9" class="st10 left-align"
display="${!config.show_grid || data.gridShowDailyBuy !== true || !data.stateDayGridImport.isValid() ? 'none' : ''}"
fill="${data.gridColour}">
${data.stateDayGridImport?.toPowerString(true, 1)}
${data.stateDayGridImport?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_grid_export_77)}>
<text id="daily_grid_sell_value" x="5" y="165" class="st10 left-align"
display="${!config.show_grid || data.gridShowDailySell !== true || !data.stateDayGridExport.isValid() ? 'none' : ''}"
fill="${data.gridColour}">
${data.stateDayGridExport?.toPowerString(true, 1)}
${data.stateDayGridExport?.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.max_sell_power)}>
Expand Down
20 changes: 10 additions & 10 deletions src/cards/full-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,21 +1407,21 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
<text id="daily_solar_value" x="43.5" y="15" class="st10 left-align"
display="${config.solar.display_mode === 1 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy.toPowerString(true, 1)}
${data.stateDayPVEnergy.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_pv_energy_108)}>
<text id="remaining_solar_value" x="43.5" y="15" class="st10 left-align"
display="${config.solar.display_mode === 2 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy.toPowerString(true, 1)} / ${data.remainingSolar}
${data.stateDayPVEnergy.toPowerString(true, data.decimalPlacesEnergy)} / ${data.remainingSolar}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_pv_energy_108)}>
<text id="total_solar_value" x="43.5" y="15" class="st10 left-align"
display="${config.solar.display_mode === 3 && data.stateDayPVEnergy.isValid() ? '' : 'none'}"
fill="${!data.solarShowDaily || !config.show_solar ? 'transparent' : `${data.solarColour}`}">
${data.stateDayPVEnergy.toPowerString(true, 1)} /
${data.stateDayPVEnergy.toPowerString(true, data.decimalPlacesEnergy)} /
${data.totalSolarGeneration}
</text>
</a>
Expand All @@ -1430,29 +1430,29 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
class="st10 left-align"
display="${!data.loadShowDaily || !data.showAux || !data.stateDayLoadEnergy.isValid() ? 'none' : ''}"
fill="${data.loadColour}">
${data.stateDayLoadEnergy.toPowerString(true, 1)}
${data.stateDayLoadEnergy.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_load_energy_84)}>
<text id="daily_load_value" x="${data.additionalLoad === 0 ? '377' : '306'}"
y="${data.additionalLoad === 0 ? '57' : '80'}" class="st10 left-align"
display="${!data.loadShowDaily || data.showAux || !data.stateDayLoadEnergy.isValid() ? 'none' : ''}"
fill="${data.loadColour}">
${data.stateDayLoadEnergy.toPowerString(true, 1)}
${data.stateDayLoadEnergy.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_battery_charge_70)}>
<text id="daily_bat_charge_value" x="4.5" y="237" class="st10 left-align"
display="${data.batteryShowDaily !== true || !config.show_battery || !data.stateDayBatteryCharge.isValid() ? 'none' : ''}"
fill="${data.batteryColour}">
${data.stateDayBatteryCharge.toPowerString(true, 1)}
${data.stateDayBatteryCharge.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_battery_discharge_71)}>
<text id="daily_bat_discharge_value" x="4.5" y="271" class="st10 left-align"
display="${data.batteryShowDaily !== true || !config.show_battery || !data.stateDayBatteryDischarge.isValid()? 'none' : ''}"
fill="${data.batteryColour}">
${data.stateDayBatteryDischarge.toPowerString(true, 1)}
${data.stateDayBatteryDischarge.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_grid_import_76)}>
Expand All @@ -1464,7 +1464,7 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
class="st10 left-align"
display="${!config.show_grid || data.gridShowDailyBuy !== true || !data.stateDayGridImport.isValid() ? 'none' : ''}"
fill="${data.gridColour}">
${data.stateDayGridImport.toPowerString(true, 1)}
${data.stateDayGridImport.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.day_grid_export_77)}>
Expand All @@ -1476,7 +1476,7 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
class="st10 left-align"
display="${!config.show_grid || data.gridShowDailySell !== true || !data.stateDayGridExport.isValid() ? 'none' : ''}"
fill="${data.gridColour}">
${data.stateDayGridExport.toPowerString(true, 1)}
${data.stateDayGridExport.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.max_sell_power)}>
Expand All @@ -1493,7 +1493,7 @@ export const fullCard = (config: sunsynkPowerFlowCardConfig, inverterImg: string
y="12" class="st10 left-align"
display="${!data.showAux || data.showDailyAux !== true || !data.stateDayAuxEnergy.isValid() ? 'none' : ''}"
fill="${data.auxDynamicColour}">
${data.stateDayAuxEnergy.toPowerString(true, 1)}
${data.stateDayAuxEnergy.toPowerString(true, data.decimalPlacesEnergy)}
</text>
</a>
<a href="#" @click=${(e) => Utils.handlePopup(e, config.entities.essential_load1_extra)}>
Expand Down
1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
card_height: '396px',
card_width: '100%',
decimal_places: 2,
decimal_places_energy: 1,
dynamic_line_width: true,
max_line_width: 4,
min_line_width: 1,
Expand Down
1 change: 1 addition & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class SunSynkCardEditor extends ScopedRegistryHost(LitElement) implements
{name: "show_battery", selector: {boolean: {}}},
{name: "show_grid", selector: {boolean: {}}},
{name: "decimal_places", selector: {number: {}}},
{name: "decimal_places_energy", selector: {number: {}}},
{name: "dynamic_line_width", selector: {boolean: {}}},
{name: "max_line_width", selector: {number: {}}},
{name: "min_line_width", selector: {number: {}}},
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export class SunsynkPowerFlowCard extends LitElement {
const iconNonessentialLoad3 = this.getEntity('grid.load3_icon', {state: config.grid?.load3_icon?.toString() ?? ''}).state;

let decimalPlaces = config.decimal_places;
let decimalPlacesEnergy = config.decimal_places_energy;
let remainingSolar = config.entities.remaining_solar ? Utils.convertValueNew(stateRemainingSolar.state, stateRemainingSolar.attributes?.unit_of_measurement, decimalPlaces) : false;
let totalSolarGeneration = config.entities.total_pv_generation ? Utils.convertValueNew(stateTotalPVGeneration.state, stateTotalPVGeneration.attributes?.unit_of_measurement, 2) : false;
let largeFont = config.large_font;
Expand Down Expand Up @@ -960,6 +961,7 @@ export class SunsynkPowerFlowCard extends LitElement {
gridPowerL2,
gridPowerL3,
decimalPlaces,
decimalPlacesEnergy,
stateEssentialLoad1Extra,
stateEssentialLoad2Extra,
stateNonEssentialLoad1Extra,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {InverterSettingsDto} from '../dto/inverter-settings.dto';
import {InverterModel} from '../../types';
import {localize} from '../../localize/localize';

export class SMA extends InverterSettingsDto {
brand = InverterModel.SMA;
export class SMASolar extends InverterSettingsDto {
brand = InverterModel.SMASolar;
statusGroups = {
standby: {states: ['0', 'standby', 'stand-by'], color: 'blue', message: localize('common.standby')},
selftest: {states: ['1', 'selftest', 'self-checking'], color: 'yellow', message: localize('common.selftest')},
Expand Down
3 changes: 3 additions & 0 deletions src/inverters/inverter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {SolarEdge} from './brands/solar-edge';
import {Deye} from './brands/deye';
import {Azzurro} from './brands/azzurro';
import {MPPSolar} from './brands/mpp-solar';
import {SMASolar} from './brands/sma-solar';



Expand Down Expand Up @@ -67,6 +68,8 @@ export class InverterFactory {
return new PowMr();
case InverterModel.MPPSolar:
return new MPPSolar();
case InverterModel.SMASolar:
return new SMASolar();
case InverterModel.Sunsynk:
default:
return new Sunsynk()
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"title_colour": "Title Colour",
"title_size": "Title Size (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"model": "Model",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Højde (px)",
"card_width": "Card Bredde (px)",
"decimal_places": "Antal viste Decimaler",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Kortstil",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Casas decimais",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Modelo",
"autarky": "Autoconsumo",
"cardstyle": "Estilo do Cartão",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"card_height": "Card Height (px)",
"card_width": "Card Width (px)",
"decimal_places": "Decimal Places",
"decimal_places_energy": "Decimal Places (Daily Energy)",
"model": "Model",
"autarky": "Autarky",
"cardstyle": "Card Style",
Expand Down
Loading

0 comments on commit 3d6e99f

Please sign in to comment.