Skip to content

Commit

Permalink
Merge pull request #215 from sparkmicro/1.0.x
Browse files Browse the repository at this point in the history
1.0.7
  • Loading branch information
eeintech authored Mar 5, 2024
2 parents c2f27fe + 4d12268 commit d1a59de
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 64 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ CATEGORY_NAME:
- SUPPLIER_2_PARAMETER_NAME_1
```
It is also possible to cross reference the mappings of different categories. To define one or multiple parent categories a parameter named `parent` can be added where the items then are the desired parent categories. If a parameter name is present in both parent and child, the childs definition will override the parent.

A template image for an category can be set by using the `image` parameter. The sole item in this parameter must the filename of an already existing part image on the the InvenTree server.

Refer to [this file](https://github.com/sparkmicro/Ki-nTree/blob/main/kintree/config/inventree/supplier_parameters.yaml) as a starting point / example.

#### Part Number Search
Expand Down
48 changes: 32 additions & 16 deletions kintree/config/config_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import copy
import os
from sys import platform

import yaml
from ..common.tools import cprint
Expand Down Expand Up @@ -28,7 +29,10 @@ def dump_file(data: dict, file_path: str) -> bool:
''' Safe dump YAML file '''
with open(file_path, 'w') as file:
try:
yaml.safe_dump(data, file, default_flow_style=False, allow_unicode=True)
if platform == "win32":
yaml.safe_dump(data, file, default_flow_style=False)
else:
yaml.safe_dump(data, file, default_flow_style=False, allow_unicode=True)
except yaml.YAMLError as exc:
print(exc)
return False
Expand Down Expand Up @@ -433,27 +437,39 @@ def add_supplier_category(categories: dict, supplier_config_path: str) -> bool:

def load_category_parameters(categories: list, supplier_config_path: str) -> dict:
''' Load Supplier parameters mapping from Supplier settings file '''
def find_parameters(output_dict, category_list):
category_parameters = None
combined = ''
for category in reversed(category_list):
if category:
combined = category + combined
if combined in category_file:
category_parameters = category_file[combined]
break
if category in category_file:
category_parameters = category_file[category]
break
combined = '/' + combined
if not category_parameters:
return
if 'parent' in category_parameters:
for parent in category_parameters['parent']:
find_parameters(output_dict, [parent])
del category_parameters['parent']

for parameter in category_parameters.keys():
if category_parameters[parameter]:
for supplier_parameter in category_parameters[parameter]:
output_dict[supplier_parameter] = parameter

try:
category_file = load_file(supplier_config_path)
except:
return None
category_parameters = None
for category in reversed(categories):
try:
category_parameters = category_file[category]
break
except:
pass
if not category_parameters:
return None

category_parameters_inversed = {}
for parameter in category_parameters.keys():
if category_parameters[parameter]:
for supplier_parameter in category_parameters[parameter]:
category_parameters_inversed[supplier_parameter] = parameter

# print(category_parameters_inversed)
find_parameters(category_parameters_inversed, categories)

return category_parameters_inversed


Expand Down
1 change: 1 addition & 0 deletions kintree/config/inventree/stock_locations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STOCK_LOCATIONS: null
65 changes: 30 additions & 35 deletions kintree/config/inventree/supplier_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,43 @@
# Each template parameter can match to multiple suppliers parameters
# Categories (main keys) should match categories in the categories.yaml file
# Parameter template names should match those found in the parameters.yaml file
Base:
Temperature Range:
- Operating Temperature
Package Type:
- Package / Case
Passives:
Tolerance:
- Tolerance
Capacitors:
parent:
- Base
- Passives
ESR:
- ESR (Equivalent Series Resistance)
Package Height:
- Height - Seated (Max)
- Thickness (Max)
Package Size:
- Size / Dimension
Package Type:
- Package / Case
Rated Voltage:
- Voltage - Rated
- Voltage Rated
Temperature Grade:
- Temperature Coefficient
Temperature Range:
- Operating Temperature
Tolerance:
- Tolerance
Value:
- Capacitance
Circuit Protections:
parent:
- Base
Breakdown Voltage:
- Voltage - Breakdown (Min)
Capacitance:
- Capacitance @ Frequency
Clamping Voltage:
- Voltage - Clamping (Max) @ Ipp
Package Type:
- Package / Case
Rated Current:
- Current Rating (Amps)
- Current - Max
Expand All @@ -42,8 +49,6 @@ Circuit Protections:
- Voltage - Max
Standoff Voltage:
- Voltage - Reverse Standoff (Typ)
Temperature Range:
- Operating Temperature
Value:
- Manufacturer Part Number
Connectors:
Expand Down Expand Up @@ -81,6 +86,8 @@ Connectors:
Value:
- Manufacturer Part Number
Crystals and Oscillators:
parent:
- Base
Frequency Stability:
- Frequency Stability
Frequency Tolerance:
Expand All @@ -91,26 +98,22 @@ Crystals and Oscillators:
- Height - Seated (Max)
Package Size:
- Size / Dimension
Package Type:
- Package / Case
Rated Current:
- Current - Supply (Max)
Rated Voltage:
- Voltage - Supply
Temperature Range:
- Operating Temperature
Value:
- Frequency
Diodes:
parent:
- Base
Forward Voltage:
- Voltage - Forward (Vf) (Max) @ If
- Voltage - Forward (Vf) (Typ)
Function Type:
- Diode Type
LED Color:
- Color
Package Type:
- Package / Case
Rated Current:
- Current - Average Rectified (Io)
Rated Power:
Expand All @@ -119,11 +122,13 @@ Diodes:
- Voltage - DC Reverse (Vr) (Max)
- Voltage - Zener (Nom) (Vz)
Temperature Range:
- Operating Temperature
- Operating Temperature - Junction
Value:
- Manufacturer Part Number
Inductors:
parent:
- Base
- Passives
ESR:
- DC Resistance (DCR)
- DC Resistance (DCR) (Max)
Expand All @@ -132,23 +137,19 @@ Inductors:
- Height (Max)
Package Size:
- Size / Dimension
Package Type:
- Package / Case
Rated Current:
- Current Rating (Max)
- Current Rating (Amps)
Saturation Current:
- Current - Saturation
Shielding:
- Shielding
Temperature Range:
- Operating Temperature
Tolerance:
- Tolerance
Value:
- Inductance
- Impedance @ Frequency
Integrated Circuits:
parent:
- Base
Frequency:
- Clock Frequency
- Speed
Expand All @@ -166,20 +167,18 @@ Integrated Circuits:
- Memory Size
Number of Channels:
- Channels per Circuit
Package Type:
- Package / Case
Rated Voltage:
- Voltage - VCCA
- Voltage - VCCB
- Voltage - Supply
- Voltage - Supply (Vcc/Vdd)
- Voltage - Supply, Digital
- Voltage - Supply, Single (V+)
Temperature Range:
- Operating Temperature
Value:
- Manufacturer Part Number
Mechanicals:
parent:
- Base
Function Type:
- Circuit
- Type
Expand All @@ -195,11 +194,11 @@ Mechanicals:
- Screw, Thread Size
Rated Current:
- Contact Rating @ Voltage
Temperature Range:
- Operating Temperature
Value:
- Manufacturer Part Number
Power Management:
parent:
- Base
(Min) Output Voltage:
- Voltage - Output (Min/Fixed)
Frequency:
Expand All @@ -220,30 +219,26 @@ Power Management:
- Current - Quiescent (Iq)
Rated Current:
- Current - Output
Temperature Range:
- Operating Temperature
Value:
- Manufacturer Part Number
RF:
parent:
- Base
Frequency:
- Frequency Range
Function Type: null
Package Type:
- Package / Case
Rated Voltage: null
Temperature Range:
- Operating Temperature
Value:
- Manufacturer Part Number
Resistors:
parent:
- Passives
Package Type:
- Supplier Device Package
Rated Power:
- Power (Watts)
Temperature Range:
- Operating Temperature
Tolerance:
- Tolerance
Value:
- Resistance
Transistors:
Expand Down
1 change: 1 addition & 0 deletions kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def load_user_config():

# Inventree
CONFIG_CATEGORIES = os.path.join(CONFIG_USER_FILES, 'categories.yaml')
CONFIG_STOCK_LOCATIONS = os.path.join(CONFIG_USER_FILES, 'stock_locations.yaml')
CONFIG_PARAMETERS = os.path.join(CONFIG_USER_FILES, 'parameters.yaml')
CONFIG_PARAMETERS_FILTERS = os.path.join(
CONFIG_USER_FILES, 'parameters_filters.yaml')
Expand Down
Loading

0 comments on commit d1a59de

Please sign in to comment.