smartrack-sdk 1.0.0__py3-none-any.whl

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.

Potentially problematic release.


This version of smartrack-sdk might be problematic. Click here for more details.

@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 数据模型包
6
+ 包含所有枚举类、请求类、响应类和回调模型
7
+ """
8
+
9
+ # 导入枚举类
10
+ from .enums import (
11
+ LedColors,
12
+ CellStatus,
13
+ RackTestMode,
14
+ OperationResultCode,
15
+ TriggerState,
16
+ )
17
+
18
+ # 导入请求类
19
+ from .requests import (
20
+ BaseRequest,
21
+ ClearErrorRequest,
22
+ RackTestRequest,
23
+ StockInRequest,
24
+ StockOutRequest,
25
+ StockOutSheetRequest,
26
+ StockOutSheetCancelRequest,
27
+ StockOutSheetFinishRequest,
28
+ StockInFinishRequest,
29
+ ResetCellRequest,
30
+ GetStockByGRNListRequest,
31
+ )
32
+
33
+ # 导入响应类
34
+ from .responses import (
35
+ BaseResponse,
36
+ ClearErrorResponse,
37
+ StockDataResponse,
38
+ StockDataDto,
39
+ StockOutResponse,
40
+ StockOutResponseDto,
41
+ StockOutSheetResponse,
42
+ )
43
+
44
+ # 导入回调模型
45
+ from .callback import (
46
+ CellEventData,
47
+ CellEventHandleRequest,
48
+ CellEventHandleResponse,
49
+ )
50
+
51
+ __all__ = [
52
+ # 枚举类
53
+ "LedColors",
54
+ "CellStatus",
55
+ "RackTestMode",
56
+ "OperationResultCode",
57
+ "TriggerState",
58
+
59
+ # 请求类
60
+ "BaseRequest",
61
+ "ClearErrorRequest",
62
+ "RackTestRequest",
63
+ "StockInRequest",
64
+ "StockOutRequest",
65
+ "StockOutSheetRequest",
66
+ "StockOutSheetCancelRequest",
67
+ "StockOutSheetFinishRequest",
68
+ "StockInFinishRequest",
69
+ "ResetCellRequest",
70
+ "GetStockByGRNListRequest",
71
+
72
+ # 响应类
73
+ "BaseResponse",
74
+ "ClearErrorResponse",
75
+ "StockDataResponse",
76
+ "StockDataDto",
77
+ "StockOutResponse",
78
+ "StockOutResponseDto",
79
+ "StockOutSheetResponse",
80
+
81
+ # 回调模型
82
+ "CellEventData",
83
+ "CellEventHandleRequest",
84
+ "CellEventHandleResponse",
85
+ ]
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 回调模型类
6
+ 包含储位事件回调相关的数据模型
7
+ """
8
+
9
+ from dataclasses import dataclass, field
10
+ from typing import List, Optional, Any, Dict
11
+ from datetime import datetime
12
+
13
+ from .enums import LedColors, TriggerState, OperationResultCode
14
+
15
+
16
+ @dataclass
17
+ class CellEventData:
18
+ """储位事件回调数据"""
19
+
20
+ code: int = 0 # 操作结果
21
+ message: str = "" # 返回消息
22
+ cell_id: str = "" # 储位号
23
+ cell_state: TriggerState = TriggerState.TAKE_OUT # 触发状态
24
+ grn: Optional[str] = None # 朔源码
25
+ sheet_id: Optional[str] = None # 单号
26
+ led_color: LedColors = LedColors.OFF # 亮灯颜色
27
+ is_blink: bool = False # 是否闪烁
28
+ rack_id: Optional[str] = None # 料架编号
29
+
30
+ @property
31
+ def operation_result(self) -> OperationResultCode:
32
+ """获取操作结果枚举"""
33
+ return OperationResultCode.from_value(self.code)
34
+
35
+ @property
36
+ def is_success(self) -> bool:
37
+ """是否成功"""
38
+ return self.code == 0
39
+
40
+ @property
41
+ def is_put_in(self) -> bool:
42
+ """是否为放入操作"""
43
+ return self.cell_state == TriggerState.PUT_IN
44
+
45
+ @property
46
+ def is_take_out(self) -> bool:
47
+ """是否为取出操作"""
48
+ return self.cell_state == TriggerState.TAKE_OUT
49
+
50
+ @classmethod
51
+ def from_dict(cls, data: Dict[str, Any]) -> 'CellEventData':
52
+ """从字典创建实例"""
53
+ cell_state = data.get("CellState", 0)
54
+ led_color = data.get("LedColor", 0)
55
+
56
+ return cls(
57
+ code=data.get("Code", 0),
58
+ message=data.get("Message", ""),
59
+ cell_id=data.get("CellId", ""),
60
+ cell_state=TriggerState.from_value(cell_state),
61
+ grn=data.get("GRN"),
62
+ sheet_id=data.get("SheetId"),
63
+ led_color=LedColors.from_value(led_color),
64
+ is_blink=data.get("IsBlink", False),
65
+ rack_id=data.get("RackId"),
66
+ )
67
+
68
+ def to_dict(self) -> Dict[str, Any]:
69
+ """转换为字典"""
70
+ return {
71
+ "Code": self.code,
72
+ "Message": self.message,
73
+ "CellId": self.cell_id,
74
+ "CellState": self.cell_state.value,
75
+ "GRN": self.grn,
76
+ "SheetId": self.sheet_id,
77
+ "LedColor": self.led_color.value,
78
+ "IsBlink": self.is_blink,
79
+ "RackId": self.rack_id,
80
+ }
81
+
82
+ def __str__(self) -> str:
83
+ return (f"CellEventData(cell_id={self.cell_id}, grn={self.grn}, "
84
+ f"state={self.cell_state.name_en}, code={self.code})")
85
+
86
+
87
+ @dataclass
88
+ class CellEventHandleRequest:
89
+ """储位事件回调请求"""
90
+
91
+ user_id: str = "" # 操作人
92
+ client_id: str = "" # 客户端ID
93
+ session_id: str = "" # 会话ID
94
+ timestamp: str = field(default_factory=lambda: datetime.now().isoformat()) # 时间戳
95
+ data: List[CellEventData] = field(default_factory=list) # 数据集合
96
+
97
+ def add_event_data(self, event_data: CellEventData) -> None:
98
+ """添加事件数据"""
99
+ self.data.append(event_data)
100
+
101
+ @classmethod
102
+ def from_dict(cls, data: Dict[str, Any]) -> 'CellEventHandleRequest':
103
+ """从字典创建实例"""
104
+ event_list = []
105
+ for item in data.get("Data", []):
106
+ event_list.append(CellEventData.from_dict(item))
107
+
108
+ return cls(
109
+ user_id=data.get("UserId", ""),
110
+ client_id=data.get("ClientId", ""),
111
+ session_id=data.get("SessionId", ""),
112
+ timestamp=data.get("Timestamp", datetime.now().isoformat()),
113
+ data=event_list,
114
+ )
115
+
116
+ def to_dict(self) -> Dict[str, Any]:
117
+ """转换为字典"""
118
+ return {
119
+ "UserId": self.user_id,
120
+ "ClientId": self.client_id,
121
+ "SessionId": self.session_id,
122
+ "Timestamp": self.timestamp,
123
+ "Data": [event.to_dict() for event in self.data],
124
+ }
125
+
126
+ def __str__(self) -> str:
127
+ return (f"CellEventHandleRequest(user_id={self.user_id}, "
128
+ f"client_id={self.client_id}, events={len(self.data)})")
129
+
130
+
131
+ @dataclass
132
+ class CellEventHandleResponse:
133
+ """储位事件回调响应"""
134
+
135
+ code: int = 0 # 返回代码
136
+ message: str = "OK" # 返回消息
137
+ session_id: str = "" # 会话Id
138
+ timestamp: str = field(default_factory=lambda: datetime.now().isoformat()) # 时间戳
139
+
140
+ @property
141
+ def is_success(self) -> bool:
142
+ """是否成功"""
143
+ return self.code == 0
144
+
145
+ @classmethod
146
+ def success(cls, session_id: str) -> 'CellEventHandleResponse':
147
+ """创建成功响应"""
148
+ return cls(
149
+ code=0,
150
+ message="OK",
151
+ session_id=session_id,
152
+ )
153
+
154
+ @classmethod
155
+ def error(cls, code: int, message: str, session_id: str) -> 'CellEventHandleResponse':
156
+ """创建失败响应"""
157
+ return cls(
158
+ code=code,
159
+ message=message,
160
+ session_id=session_id,
161
+ )
162
+
163
+ @classmethod
164
+ def from_dict(cls, data: Dict[str, Any]) -> 'CellEventHandleResponse':
165
+ """从字典创建实例"""
166
+ return cls(
167
+ code=data.get("code", 0),
168
+ message=data.get("message", "OK"),
169
+ session_id=data.get("sessionId", ""),
170
+ timestamp=data.get("timestamp", datetime.now().isoformat()),
171
+ )
172
+
173
+ def to_dict(self) -> Dict[str, Any]:
174
+ """转换为字典"""
175
+ return {
176
+ "code": self.code,
177
+ "message": self.message,
178
+ "sessionId": self.session_id,
179
+ "timestamp": self.timestamp,
180
+ }
181
+
182
+ def __str__(self) -> str:
183
+ return (f"CellEventHandleResponse(code={self.code}, "
184
+ f"message={self.message}, session_id={self.session_id})")
@@ -0,0 +1,203 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 枚举类定义
6
+ 包含所有SmartRack API中使用的枚举类型
7
+ """
8
+
9
+ from enum import Enum, IntEnum
10
+ from typing import Dict, Any
11
+
12
+
13
+ class LedColors(IntEnum):
14
+ """LED灯颜色枚举"""
15
+
16
+ OFF = 0 # 关闭
17
+ RED = 1 # 红色
18
+ GREEN = 2 # 绿色
19
+ YELLOW = 3 # 黄色
20
+ BLUE = 4 # 蓝色
21
+ MAGENTA = 5 # 洋红色
22
+ CYAN = 6 # 青色
23
+ WHITE = 7 # 白色
24
+
25
+ BLINK = 128 # 闪烁
26
+ RED_BLINK = 129 # 红色闪烁
27
+ GREEN_BLINK = 130 # 绿色闪烁
28
+ YELLOW_BLINK = 131 # 黄色闪烁
29
+ BLUE_BLINK = 132 # 蓝色闪烁
30
+ MAGENTA_BLINK = 133 # 洋红色闪烁
31
+ CYAN_BLINK = 134 # 青色闪烁
32
+ WHITE_BLINK = 135 # 白色闪烁
33
+
34
+ @classmethod
35
+ def from_value(cls, value: int) -> 'LedColors':
36
+ """根据值获取枚举实例"""
37
+ try:
38
+ return cls(value)
39
+ except ValueError:
40
+ raise ValueError(f"Invalid LedColors value: {value}")
41
+
42
+ @property
43
+ def name_en(self) -> str:
44
+ """获取英文名称"""
45
+ names = {
46
+ 0: "Off",
47
+ 1: "Red",
48
+ 2: "Green",
49
+ 3: "Yellow",
50
+ 4: "Blue",
51
+ 5: "Magenta",
52
+ 6: "Cyan",
53
+ 7: "White",
54
+ 128: "Blink",
55
+ 129: "RedBlink",
56
+ 130: "GreenBlink",
57
+ 131: "YellowBlink",
58
+ 132: "BlueBlink",
59
+ 133: "MagentaBlink",
60
+ 134: "CyanBlink",
61
+ 135: "WhiteBlink",
62
+ }
63
+ return names.get(self.value, "Unknown")
64
+
65
+ def __str__(self) -> str:
66
+ return f"{self.name_en} ({self.value})"
67
+
68
+
69
+ class CellStatus(IntEnum):
70
+ """储位状态枚举"""
71
+
72
+ EMPTY = 0 # 空
73
+ HOLD = 1 # 非空
74
+ LOCKED = 2 # 预定状态
75
+ TAKE_OUT = 3 # 已取料
76
+ CHECKED = 4 # 已复核
77
+ MOVE = 5 # 移库已取出
78
+
79
+ ILLEGAL_TAKE_OUT = -3 # 非法取料
80
+ ILLEGAL_TAKE_IN = -2 # 非法上料
81
+ DISABLED = -1 # 禁用储位
82
+
83
+ @classmethod
84
+ def from_value(cls, value: int) -> 'CellStatus':
85
+ """根据值获取枚举实例"""
86
+ try:
87
+ return cls(value)
88
+ except ValueError:
89
+ raise ValueError(f"Invalid CellStatus value: {value}")
90
+
91
+ @property
92
+ def name_en(self) -> str:
93
+ """获取英文名称"""
94
+ names = {
95
+ 0: "Empty",
96
+ 1: "Hold",
97
+ 2: "Locked",
98
+ 3: "TakeOut",
99
+ 4: "Checked",
100
+ 5: "Move",
101
+ -3: "IllegalTakeOut",
102
+ -2: "IllegalTakeIn",
103
+ -1: "Disabled",
104
+ }
105
+ return names.get(self.value, "Unknown")
106
+
107
+ def __str__(self) -> str:
108
+ return f"{self.name_en} ({self.value})"
109
+
110
+
111
+ class RackTestMode(IntEnum):
112
+ """料架测试模式枚举"""
113
+
114
+ ALL_OFF = 0 # 全部灭灯
115
+ RGB_TEST = 1 # RGB测试
116
+ LIGHT_SEQUENCE_TEST = 2 # 灯序测试
117
+ WARNING_LIGHT_TEST = 3 # 警示灯测试
118
+ EMPTY_LIGHT = 4 # 空位亮灯
119
+ NON_EMPTY_LIGHT = 5 # 非空亮灯
120
+
121
+ @classmethod
122
+ def from_value(cls, value: int) -> 'RackTestMode':
123
+ """根据值获取枚举实例"""
124
+ try:
125
+ return cls(value)
126
+ except ValueError:
127
+ raise ValueError(f"Invalid RackTestMode value: {value}")
128
+
129
+ @property
130
+ def name_en(self) -> str:
131
+ """获取英文名称"""
132
+ names = {
133
+ 0: "AllOff",
134
+ 1: "RgbTest",
135
+ 2: "LightSequenceTest",
136
+ 3: "WarningLightTest",
137
+ 4: "EmptyLight",
138
+ 5: "NonEmptyLight",
139
+ }
140
+ return names.get(self.value, "Unknown")
141
+
142
+ def __str__(self) -> str:
143
+ return f"{self.name_en} ({self.value})"
144
+
145
+
146
+ class OperationResultCode(IntEnum):
147
+ """操作结果代码枚举"""
148
+
149
+ SUCCESS = 0 # 操作成功
150
+ ILLEGAL_STOCK_IN = 2 # 非法上架
151
+ ILLEGAL_STOCK_OUT = 4 # 非法下架
152
+ ILLEGAL_STOCK_IN_CLEAR_ERROR = 8 # 非法上架清错
153
+ ILLEGAL_STOCK_OUT_CLEAR_ERROR = 16 # 非法下架清错
154
+
155
+ @classmethod
156
+ def from_value(cls, value: int) -> 'OperationResultCode':
157
+ """根据值获取枚举实例"""
158
+ try:
159
+ return cls(value)
160
+ except ValueError:
161
+ raise ValueError(f"Invalid OperationResultCode value: {value}")
162
+
163
+ @property
164
+ def name_en(self) -> str:
165
+ """获取英文名称"""
166
+ names = {
167
+ 0: "Success",
168
+ 2: "IllegalStockIn",
169
+ 4: "IllegalStockOut",
170
+ 8: "IllegalStockInClearError",
171
+ 16: "IllegalStockOutClearError",
172
+ }
173
+ return names.get(self.value, "Unknown")
174
+
175
+ def __str__(self) -> str:
176
+ return f"{self.name_en} ({self.value})"
177
+
178
+
179
+ class TriggerState(IntEnum):
180
+ """触发状态枚举"""
181
+
182
+ TAKE_OUT = 0 # 取出
183
+ PUT_IN = 1 # 放入
184
+
185
+ @classmethod
186
+ def from_value(cls, value: int) -> 'TriggerState':
187
+ """根据值获取枚举实例"""
188
+ try:
189
+ return cls(value)
190
+ except ValueError:
191
+ raise ValueError(f"Invalid TriggerState value: {value}")
192
+
193
+ @property
194
+ def name_en(self) -> str:
195
+ """获取英文名称"""
196
+ names = {
197
+ 0: "TakeOut",
198
+ 1: "PutIn",
199
+ }
200
+ return names.get(self.value, "Unknown")
201
+
202
+ def __str__(self) -> str:
203
+ return f"{self.name_en} ({self.value})"