-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/custom_entity #305
Conversation
The new CustomEntity interface allows for streamlined handling of state-related tasks and boilerplate code reduction. Additionally, the full battery capacity computation logic is now encapsulated within the `getBatteryCapacity` method. This promotes better organization and clarity throughout the codebase, particularly in `sunsynk-power-flow-card.js`.
The updated version of sunsynk-power-flow-card.js now incorporates the CustomEntity interface for improved state management and reduced boilerplate code. A part of this change is the enclosed battery capacity computation logic within the `getBatteryCapacity` method, leading to cleaner and more maintainable code. Co-authored-by: Pho3niX90 <[email protected]> Co-authored-by: slipx06 <[email protected]>
The CustomEntity methods were refactored and simplified, reducing the overall complexity and remove unnecessary namespace. This update improves state management and decreases boilerplate code, providing for a cleaner, more maintainable code base. The changes include enclosing battery capacity computation inside the `getBatteryCapacity` method and implementing convertToCustomEntity as a direct export function. Co-authored-by: Pho3niX90 <[email protected]> Co-authored-by: slipx06 <[email protected]>
Co-authored-by: Pho3niX90 <[email protected]> Co-authored-by: slipx06 <[email protected]>
Co-authored-by: Pho3niX90 <[email protected]> Co-authored-by: slipx06 <[email protected]>
Updated the code in src/index.ts by removing the default states for various entities. Default states for 'aux_power_166' and several 'pvX_voltage/current' entities were removed, since they were unnecessary. Additionally, removed the unused 'dynamicConfig' option from sunsynkPowerFlowCardConfig in src/types.ts. Co-authored-by: Pho3niX90 <[email protected]> Co-authored-by: slipx06 <[email protected]>
energy: number; | ||
shutdown_soc: number; | ||
shutdown_soc_offgrid: number; | ||
energy: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm that I am corrct to change this to any
where you can provide a number or sensor
@slipx06 should be fixed now, was because I have fixed the state, by changing it to back to string (HassEntity type). |
The last update broke battery energy. Its a problem with state_battery_rated_capacity |
battery_energy = Utils.toNum(battery_voltage * state_battery_rated_capacity, 0) | ||
const battenergy = this.getEntity('battery.energy', {state: config.battery.energy.toString() ?? ''}); | ||
let battery_energy = battenergy.toNum(0); | ||
if (battery_voltage && state_battery_rated_capacity.notEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if state is empty
That should fix it. The optional chaining operator fixes these issues |
The new CustomEntity interface allows for streamlined handling of state-related tasks and boilerplate code reduction. Additionally, the full battery capacity computation logic is now encapsulated within the
getBatteryCapacity
method. This promotes better organization and clarity throughout the codebase.I added the co-authored tag. Although I "think" I got all the logic, I might not have understood the intent at all of the calculations, so just need another pair of eyes.