slipx06 / sunsynk-power-flow-card

⚡A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.
MIT License
161 stars 48 forks source link

Improve custom entity handling and add more unit handling #309

Closed Pho3niX90 closed 3 months ago

Pho3niX90 commented 3 months ago

This commit improves the handling of custom entities, particularly focusing on ensuring the state is not null, undefined, or unknown. It also adds various system features such as conversion from a state to power and auto conversion from a state to kilowatts. In addition, units of electrical current, energy, and power were added to provide spatial and time recognizability context to the measures. This enhancement results in a more detailed and accurate representation of data. It also includes adjustments in energy conversion for better precision and clarity.

possibly fixes: #299

slipx06 commented 3 months ago

Nice improvements. Working through it. Thanks

slipx06 commented 3 months ago

Note to check logic when autoscale is false as it shows units in kWh image When true it shows W image

It should default to the unit of measurement provided by the entity

pv1_power_186: sensor.sunsynk_pv1_power image

${data.statePV1Power?.toPowerString(config.solar.auto_scale, data.decimalPlaces)}

toPowerString: (scale?: boolean, decimals?: number, invert?: boolean) =>
            scale ?
                Utils.convertValueNew(entity?.state, entity?.attributes?.unit_of_measurement, decimals || 1) :
                `${Utils.toNum(entity?.state, decimals, invert)} ${UnitOfEnergy.KILO_WATT_HOUR}`,

Change to

toPowerString: (scale?: boolean, decimals?: number, invert?: boolean) =>
            scale ?
                Utils.convertValueNew(entity?.state, entity?.attributes?.unit_of_measurement, decimals || 1) :
                `${Utils.toNum(entity?.state, decimals, invert)} ${entity?.attributes?.unit_of_measurement}`,
slipx06 commented 3 months ago

Have applied changes and checked both full and compact cards. Please can you also confirm everything working on your end.

Pho3niX90 commented 3 months ago

Soz just seeing everything now, will quickly test on my end

Pho3niX90 commented 3 months ago

Okay all seems good my side as well