@enerlence/suntropy-cli 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -140,14 +140,17 @@ suntropy inventory panels delete <id>
140
140
  # kits, charger-kits, heatpump-kits, manufacturers
141
141
  ```
142
142
 
143
- **Kit assembly:**
143
+ **Kit assembly (create kit components first, then assemble):**
144
144
 
145
145
  ```bash
146
- suntropy inventory kits panels create --data '{"name":"Panel Kit","peakPower":450}'
147
- suntropy inventory kits inverters create --data '{"name":"Inversor Kit","nominalPower":5000}'
146
+ # 1. Create kit-specific panel and inverter
147
+ suntropy inventory kits panels create --data '{"name":"Panel Kit 450W","peakPower":450}'
148
+ suntropy inventory kits inverters create --data '{"name":"Inversor Kit 5kW","nominalPower":5000}'
149
+
150
+ # 2. Assemble kit referencing component IDs
148
151
  suntropy inventory kits assemble \
149
152
  --name "Kit Solar 5kW" \
150
- --panel <panelId> --inverter <inverterId> \
153
+ --panel <kitPanelId> --inverter <kitInverterId> \
151
154
  --panels-count 12 --peak-power 5.4 --price 3500
152
155
  ```
153
156
 
@@ -632,6 +632,8 @@ function registerKitsCommands(inventory) {
632
632
  batchDeletePath: "delete-batch-solar-kits",
633
633
  getViaFilter: true
634
634
  });
635
+ const kitsCreateIdx = kits.commands.findIndex((c) => c.name() === "create");
636
+ if (kitsCreateIdx !== -1) kits.commands.splice(kitsCreateIdx, 1);
635
637
  kits.command("archive <kitId>").description("Archive a solar kit (soft-disable)").action(async (kitId) => {
636
638
  try {
637
639
  const global = getGlobalOpts3(kits);
@@ -788,10 +790,71 @@ function registerKitsCommands(inventory) {
788
790
  });
789
791
  kits.command("assemble").description(
790
792
  'Assemble a solar kit from existing components by ID.\nReferences kit panels, inverters, batteries, and custom assets by their IDs.\n\nCustom assets format: --custom-asset <assetId>:<units> (repeatable)\n\nExamples:\n suntropy inventory kits assemble --name "Kit 5kW" --panel 123 --inverter 456 --panels-count 12 --price 6500\n suntropy inventory kits assemble --name "Kit Premium" --panel 123 --inverter 456 --battery 789 \\\n --panels-count 12 --inverters-count 1 --batteries-count 1 --peak-power 5.4 --price 8500 \\\n --custom-asset 100:12 --custom-asset 200:1 --phase single_phase'
791
- ).requiredOption("--name <identifier>", "Kit name/identifier").option("--panel <kitPanelId>", "Kit panel ID (idKitSolarPanel)").option("--inverter <kitInverterId>", "Kit inverter ID (idKitInverter)").option("--battery <batteryId>", "Battery ID from inventory (batteryId)").option("--panels-count <n>", "Number of panels", "12").option("--inverters-count <n>", "Number of inverters", "1").option("--batteries-count <n>", "Number of batteries", "0").option("--peak-power <kW>", "Total peak power in kW").option("--price <eur>", "Kit price in EUR").option("--phase <type>", "Phase: single_phase or three_phase", "single_phase").option("--coplanar", "Coplanar mounting").option("--taxes <pct>", "Default tax percentage", "21").option("--custom-asset <id:units>", "Custom asset as id:units (repeatable)", collectCustomAssets, []).action(async (opts) => {
793
+ ).requiredOption("--name <identifier>", "Kit name/identifier").option("--panel <kitPanelId>", "Kit panel ID (idKitSolarPanel)").option("--inverter <kitInverterId>", "Kit inverter ID (idKitInverter)").option("--battery <batteryId>", "Battery ID from inventory (batteryId)").option("--panels-count <n>", "Number of panels", "12").option("--inverters-count <n>", "Number of inverters", "1").option("--batteries-count <n>", "Number of batteries", "0").option("--peak-power <kW>", "Total peak power in kW").requiredOption("--price <eur>", "Kit price in EUR (required)").option("--phase <type>", "Phase: single_phase or three_phase", "single_phase").option("--coplanar", "Coplanar mounting").option("--taxes <pct>", "Default tax percentage", "21").option("--custom-asset <id:units>", "Custom asset as id:units (repeatable)", collectCustomAssets, []).action(async (opts) => {
792
794
  try {
793
795
  const global = getGlobalOpts3(kits);
794
796
  const client = createServiceClient("solar", global);
797
+ const validationErrors = [];
798
+ if (opts.panel) {
799
+ try {
800
+ const res2 = await client.post("/solar-kits/solar-panels/filter", { idKitSolarPanel: parseInt(opts.panel) });
801
+ const data = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
802
+ if (data.length === 0) {
803
+ validationErrors.push(
804
+ `Panel ID ${opts.panel} is not a KitSolarPanel. Use "suntropy inventory kits panels list" to see available kit panels, or "suntropy inventory kits panels create --data '{...}'" to create one first.`
805
+ );
806
+ }
807
+ } catch {
808
+ validationErrors.push(
809
+ `Could not validate panel ID ${opts.panel}. Make sure it is a KitSolarPanel ID (not a regular inventory panel). Use "suntropy inventory kits panels list" to see available kit panels.`
810
+ );
811
+ }
812
+ }
813
+ if (opts.inverter) {
814
+ try {
815
+ const res2 = await client.get("/solar-kits/inverters", { params: { limit: 200 } });
816
+ const inverters = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
817
+ const found = inverters.find(
818
+ (inv) => String(inv.idKitInverter) === String(opts.inverter)
819
+ );
820
+ if (!found) {
821
+ validationErrors.push(
822
+ `Inverter ID ${opts.inverter} is not a KitInverter. Use "suntropy inventory kits inverters list" to see available kit inverters, or "suntropy inventory kits inverters create --data '{...}'" to create one first.`
823
+ );
824
+ }
825
+ } catch {
826
+ validationErrors.push(
827
+ `Could not validate inverter ID ${opts.inverter}. Make sure it is a KitInverter ID (not a regular inventory inverter). Use "suntropy inventory kits inverters list" to see available kit inverters.`
828
+ );
829
+ }
830
+ }
831
+ if (opts.battery) {
832
+ try {
833
+ const res2 = await client.get("/solar-kits/batteries", { params: { limit: 200 } });
834
+ const batteries = Array.isArray(res2.data) ? res2.data : res2.data?.data || [];
835
+ const found = batteries.find(
836
+ (bat) => String(bat.idKitBattery) === String(opts.battery)
837
+ );
838
+ if (!found) {
839
+ validationErrors.push(
840
+ `Battery ID ${opts.battery} is not a KitBattery. Use "suntropy inventory kits batteries list" to see available kit batteries, or "suntropy inventory kits batteries create --data '{...}'" to create one first.`
841
+ );
842
+ }
843
+ } catch {
844
+ validationErrors.push(
845
+ `Could not validate battery ID ${opts.battery}. Make sure it is a KitBattery ID (not a regular inventory battery). Use "suntropy inventory kits batteries list" to see available kit batteries.`
846
+ );
847
+ }
848
+ }
849
+ if (validationErrors.length > 0) {
850
+ outputError({
851
+ error: true,
852
+ message: "Kit assembly validation failed",
853
+ issues: validationErrors,
854
+ hint: "The assemble command requires KitSolarPanel, KitInverter, and KitBattery IDs \u2014 these are kit-specific entities, not regular inventory items."
855
+ });
856
+ return;
857
+ }
795
858
  const body = {
796
859
  identifier: opts.name,
797
860
  panelNumber: parseInt(opts.panelsCount),
@@ -805,7 +868,7 @@ function registerKitsCommands(inventory) {
805
868
  if (opts.inverter) body.kitInverter = { idKitInverter: parseInt(opts.inverter) };
806
869
  if (opts.battery) body.battery = { batteryId: parseInt(opts.battery) };
807
870
  if (opts.peakPower) body.peakPower = parseFloat(opts.peakPower);
808
- if (opts.price) body.price = parseFloat(opts.price);
871
+ body.price = parseFloat(opts.price);
809
872
  if (opts.coplanar) body.coplanar = true;
810
873
  if (opts.customAsset && opts.customAsset.length > 0) {
811
874
  body.solarKitCustomAssets = opts.customAsset.map((ca) => ({