11 config_path = os.path.join(os.path.dirname(__file__),
"..",
"config",
"config.toml")
13 with open(config_path,
"rb")
as f:
14 config = tomli.load(f)
15 except Exception
as e:
16 print(f
"Error loading config: {e}", file=sys.stderr)
19 sensor_roles = config.get(
"sensor_roles_pt_board", config.get(
"sensor_roles", {}))
20 boards = config.get(
"boards", {})
28 for section_name, section_data
in config.items():
29 if section_name.startswith(
"sensor_roles_"):
35 if "tc" in section_name:
38 elif "rtd" in section_name:
41 elif "lc" in section_name:
45 for role_name, channel_id
in section_data.items():
46 if isinstance(channel_id, int):
47 entity_name = role_name.replace(
" ",
"_")
48 mapping[f
"0x{hi_byte:02x}_{channel_id}"] = f
"{prefix}.{entity_name}"
49 mapping[f
"0x{hi_byte:02x}_{0x10 + channel_id}"] = (
50 f
"{prefix}_Cal.{entity_name}"
54 actuator_roles = config.get(
"actuator_roles", {})
55 for role_name, act_info
in actuator_roles.items():
56 if isinstance(act_info, list)
and len(act_info) >= 2:
57 channel_id = act_info[1]
58 if isinstance(channel_id, int):
59 entity_name = role_name.replace(
" ",
"_")
60 mapping[f
"0x30_{channel_id}"] = f
"ACT.{entity_name}"
67 with open(
"/tmp/sensor_map.json",
"w")
as f:
68 json.dump(mapping, f, indent=2)
69 except Exception
as e:
70 print(f
"Error writing mapping: {e}", file=sys.stderr)