Skip to content

Commit

Permalink
Merge pull request #166 from artem-barysh-dev/updated-validation-script
Browse files Browse the repository at this point in the history
Updated validation script
  • Loading branch information
ViacheslavKlimov authored Dec 17, 2024
2 parents 551e5be + 858bc6a commit 9c3ff39
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 14 deletions.
5 changes: 0 additions & 5 deletions VENDORS/Decentlab/DL-SHT35-002/info.json

This file was deleted.

Binary file removed VENDORS/Decentlab/DL-SHT35-002/photo.png
Binary file not shown.
5 changes: 1 addition & 4 deletions VENDORS/Netvox/R718N3/info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"url": [
"http://www.netvox.com.tw/product.asp?pro=R718N3",
"http://www.netvox.com.cn:8888/cmddoc"
],
"url": "http://www.netvox.com.tw/product.asp?pro=R718N3",
"label": "R718N3: Wireless 3-Phase Current Meter",
"description": "The Netvox R718N3 3-Phase Current Meter is a LoRaWAN® end device with three external solid-core current transformers that can be used to obtain the current of a three-phase wiring system. R718N3 series have different measuring range for different variety of CT; 3 x 50A(Solid Core CT), 3 x 75A (Clamp-On CT), 3 x 150A (Clamp-On CT), 3 x 250A (Clamp-On CT), 3 x 630A (Clamp-On CT)."
}
87 changes: 82 additions & 5 deletions data_converters_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
client = RestClientPE(base_url=ENDPOINT)
client.login(username=USERNAME, password=PASSWORD)


def find_payload_and_result_pairs(directory):
payloads = sorted([f for f in os.listdir(directory) if re.match(r'payload(_\d+)?\.json', f)])
results = sorted([f for f in os.listdir(directory) if re.match(r'result(_\d+)?\.json', f)])
Expand Down Expand Up @@ -145,18 +144,96 @@ def validate_uplink_downlink(directory):
return success


def validate_device_files(device_path):
required_files = {'info.json', 'photo.png'}
found_files = set(file for file in os.listdir(device_path) if os.path.isfile(os.path.join(device_path, file)))
missing_files = required_files - found_files

if missing_files:
print(f"Validation failed: Missing required files {', '.join(missing_files)} in {device_path}")
return False

info_path = os.path.join(device_path, 'info.json')
if os.path.getsize(info_path) == 0:
print(f"Validation failed: {info_path} is empty.")
return False

with open(info_path, 'r', encoding='utf-8') as info_file:
info_data = json.load(info_file)

required_keys = {'url', 'label', 'description'}
missing_keys = required_keys - info_data.keys()
if missing_keys:
print(f"Validation failed: Missing keys {', '.join(missing_keys)} in {info_path}")
return False

empty_keys = [
key for key in required_keys
if not isinstance(info_data[key], str) or not info_data[key].strip()
]
if empty_keys:
print(f"Validation failed: Keys {', '.join(empty_keys)} in {info_path} have empty or invalid values.")
return False

if empty_keys:
print(f"Validation failed: Keys {', '.join(empty_keys)} in {info_path} have empty values.")
return False

return True


def walk_vendors_directory(root_dir):
all_success = True

for root, dirs, files in os.walk(root_dir):
if root.endswith('uplink') or root.endswith('downlink'):
success = validate_uplink_downlink(root)
if not success:
for company in os.listdir(root_dir):
company_path = os.path.join(root_dir, company)

if not os.path.isdir(company_path):
continue

for device in os.listdir(company_path):
device_path = os.path.join(company_path, device)

if not os.path.isdir(device_path):
continue

if not validate_device_files(device_path):
all_success = False
continue

integrations = [item for item in os.listdir(device_path) if os.path.isdir(os.path.join(device_path, item))]
if not integrations:
print(f"Validation failed: No integration directories found in {device_path}")
all_success = False
continue

for integration in integrations:
integration_path = os.path.join(device_path, integration)

if not os.path.isdir(integration_path):
continue

uplink_path = os.path.join(integration_path, 'uplink')
downlink_path = os.path.join(integration_path, 'downlink')

if not os.path.exists(uplink_path) and not os.path.exists(downlink_path):
print(f"Validation failed: Both 'uplink' and 'downlink' are missing in {integration_path}")
all_success = False

if os.path.exists(uplink_path):
success = validate_uplink_downlink(uplink_path)
if not success:
all_success = False

if os.path.exists(downlink_path):
success = validate_uplink_downlink(downlink_path)
if not success:
all_success = False

return all_success



if __name__ == "__main__":
root_directory = "VENDORS"
all_success = walk_vendors_directory(root_directory)
Expand Down

0 comments on commit 9c3ff39

Please sign in to comment.