Skip to content

Commit

Permalink
feat: add aux_dynamic_colour: closes #357
Browse files Browse the repository at this point in the history
  • Loading branch information
slipx06 committed Apr 4, 2024
1 parent c45e9bd commit c313812
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 51 deletions.
16 changes: 8 additions & 8 deletions dist/sunsynk-power-flow-card.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ These attributes are only needed if `show_solar` is set to `true`
| aux_name: | Optional | `Auxilary` | Set the display name for the AUX Load
| aux_type: | Optional | `default` | Sets the AUX image using preset or any mdi icon e.g. `mdi:ev-station`. Presets are: `gen`, `inverter` `default`, `oven`, `pump`, `aircon` and `boiler`.
| aux_colour: | Optional | `the load colour` | Sets the colour of all the AUX card objects. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) |
| aux_dynamic_colour:| Optional | `true` | The respective aux elements on the card will be greyed out if aux power = 0W. |
| aux_off_colour: | Optional | `the load colour` | Sets the colour of the AUX icon and label when disconnected. Hex codes (`'#66ff00'` etc) or names (`red`, `green`, `blue` etc) |
| aux_loads: | Optional | `0` | Display additional loads on the AUX side (`0/1/2`)
| aux_load1_name: | Optional | | Set the display name for the AUX load 1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunsynk-power-flow-card",
"version": "4.27.0",
"version": "4.28.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 Down
85 changes: 48 additions & 37 deletions src/cards/full-card.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default {
colour: '#5fb6ad',
dynamic_colour: true,
dynamic_icon: true,
aux_dynamic_colour: true,
show_daily: false,
show_aux: false,
show_daily_aux: false,
Expand Down
1 change: 1 addition & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class SunSynkCardEditor extends ScopedRegistryHost(LitElement) implements
{name: 'aux_type', selector: {icon: {}}},
{name: 'invert_aux', selector: {boolean: {}}},
{name: 'show_absolute_aux', selector: {boolean: {}}},
{name: 'aux_dynamic_colour', selector: {boolean: {}}},
{name: 'aux_colour', selector: {color_rgb: {}}},
{name: 'aux_off_colour', selector: {color_rgb: {}}},
{name: 'aux_loads', selector: {number: {mode: 'box', min: 0, max: 2,}}},
Expand Down
21 changes: 17 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ export class SunsynkPowerFlowCard extends LitElement {
let genericInverterImage = config.inverter?.modern;

let loadColour = this.colourConvert(config.load?.colour);
let auxColour = this.colourConvert(config.load?.aux_colour || loadColour);
let auxOffColour = this.colourConvert(config.load?.aux_off_colour || auxColour);
//let auxColour = this.colourConvert(config.load?.aux_colour || loadColour);
let auxDynamicColour = this.calculateAuxLoadColour(stateAuxPower, 0) || loadColour;
let auxOffColour = this.colourConvert(config.load?.aux_off_colour || auxDynamicColour);
let auxDynamicColourLoad1 = this.calculateAuxLoadColour(stateAuxLoad1, 0) || loadColour;
let auxDynamicColourLoad2 = this.calculateAuxLoadColour(stateAuxLoad2, 0) || loadColour;

config.title_colour = this.colourConvert(config.title_colour);

Expand Down Expand Up @@ -927,7 +930,6 @@ export class SunsynkPowerFlowCard extends LitElement {
isFloating,
inverterColour,
solarColour,
auxColour,
auxOffColour,
batteryEnergy,
largeFont,
Expand Down Expand Up @@ -1074,7 +1076,10 @@ export class SunsynkPowerFlowCard extends LitElement {
stateNonessentialLoad2,
stateNonessentialLoad3,
autoScaledInverterPower,
autoScaledGridPower
autoScaledGridPower,
auxDynamicColour,
auxDynamicColourLoad1,
auxDynamicColourLoad2
};

if (this.isFullCard) {
Expand Down Expand Up @@ -1153,6 +1158,14 @@ export class SunsynkPowerFlowCard extends LitElement {
return lineWidth;
}

calculateAuxLoadColour(state, threshold) {
return !this._config.load.aux_dynamic_colour
? this.colourConvert(this._config.load?.aux_colour)
: Math.abs(state.toNum(0)) > threshold
? this.colourConvert(this._config.load?.aux_colour)
: 'grey';
}

setConfig(config) {
if (config.show_battery && !config.battery) {
throw Error(localize('errors.battery.bat'));
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 @@ -138,6 +138,7 @@
"auto_scale": "Auto Scale",
"three_phase": "Three Phase",
"dynamic_colour": "Dynamic Colour",
"aux_dynamic_colour": "Aux Dynamic Colour",
"dynamic_icon": "Dynamic Icon",
"invert_power": "Invert Power",
"show_absolute": "Show Absolute",
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 @@ -88,6 +88,7 @@
"autarky": "Autarky",
"cardstyle": "Card Style",
"large_font": "Large Font",
"aux_dynamic_colour": "Aux Dynamic Colour",
"modern": "Modern",
"show_solar": "Show Solar",
"show_battery": "Show Battery",
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 @@ -129,6 +129,7 @@
"charge_colour": "Charge Colour",
"linear_gradient": "Linear Gradient",
"aux_colour": "Colour",
"aux_dynamic_colour": "Aux Dynamic Colour",
"aux_off_colour": "Off Colour",
"panel_mode": "Panel Mode",
"invert_grid": "Invert Values",
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 @@ -135,6 +135,7 @@
"invert_load": "Invert Values",
"shutdown_soc": "Shutdown SOC",
"energy": "Energy",
"aux_dynamic_colour": "Aux Dynamic Colour",
"auto_scale": "Auto Scale",
"three_phase": "Three Phase",
"dynamic_colour": "Dynamic Colour",
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 @@ -118,6 +118,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -120,6 +120,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -120,6 +120,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -121,6 +121,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -120,6 +120,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -120,6 +120,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
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 @@ -118,6 +118,7 @@
"aux_load2_name": "Nome Aux_Uso2",
"aux_load1_icon": "Nome Aux_Uso3",
"aux_load2_icon": "Nome Aux_Uso4",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Consumo Diário",
"show_daily_sell": "Produção Diária",
"no_grid_colour": "Cor No_Grid",
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 @@ -120,6 +120,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"aux_load2_name": "Load 2 Name",
"aux_load1_icon": "Load 1 Icon",
"aux_load2_icon": "Load 2 Icon",
"aux_dynamic_colour": "Aux Dynamic Colour",
"show_daily_buy": "Show Daily Buy",
"show_daily_sell": "Show Daily Sell",
"no_grid_colour": "No Grid Colour",
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface sunsynkPowerFlowCardConfig extends LovelaceCardConfig {
load: {
colour: string;
dynamic_colour: boolean;
aux_dynamic_colour: boolean;
dynamic_icon: boolean;
show_daily: boolean;
invert_aux: boolean;
Expand Down Expand Up @@ -273,7 +274,6 @@ export interface DataDto {
isFloating,
inverterColour,
solarColour,
auxColour,
auxOffColour,
batteryEnergy,
largeFont,
Expand Down Expand Up @@ -374,6 +374,9 @@ export interface DataDto {
iconAuxLoad2,
autoScaledInverterPower,
autoScaledGridPower,
auxDynamicColour,
auxDynamicColourLoad1,
auxDynamicColourLoad2,
stateDayLoadEnergy: CustomEntity,
stateDayBatteryDischarge: CustomEntity,
stateDayGridImport: CustomEntity,
Expand Down

0 comments on commit c313812

Please sign in to comment.