-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtool_recalc_hash.py
More file actions
38 lines (33 loc) · 1.19 KB
/
tool_recalc_hash.py
File metadata and controls
38 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
TOOL to recalculate the hash value of the keys in the JSON configuration file.
This key is also stored in the plugin settings (hardware table of the domoticz.db).
Author: Filip Demaertelaere
Version: 5.0.0
License: MIT
"""
import sys, os
import hashlib
import json
# Streaming key filename
_STREAMING_KEY_FILE = 'Bmw_keys_streaming.json'
try:
with open(f"{_STREAMING_KEY_FILE}", "r") as json_file:
streamingKeys = json.load(json_file)
for vin_number, vehicle_data in streamingKeys.items():
print(f"\n VIN: {vin_number}")
# Iterate over the values in the dictionary (parent.streamingKeys)
container_keys = []
for value, key in vehicle_data.items():
if isinstance(key, str):
container_keys.append(key)
elif isinstance(key, list):
container_keys.extend(key)
print(f" {key}")
sorted_keys = str(tuple(sorted(set(container_keys))))
key_hash = hashlib.sha256(sorted_keys.encode('utf-8')).hexdigest()
print(f" CONTAINER: {sorted_keys}")
print(f" HASH: {key_hash}")
except Exception as e:
print(f"Problem: {e})!")