solax-py-library 1.0.0.2514__py3-none-any.whl → 1.0.0.2515__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.
@@ -1,9 +1,10 @@
1
- # class BaseAction(object):
2
- # def __init__(self, smart_scene_service):
3
- # self.smart_scene_service = smart_scene_service
4
- # self.device_service = DeviceService()
5
- # self.ems_tcp_service = EMSTcpService()
6
- #
7
- #
8
- #
9
- #
1
+ class BaseAction(object):
2
+ def __init__(self, smart_scene_service, do_funcs, **kwargs):
3
+ self.smart_scene_service = smart_scene_service
4
+ self.do_func_map = do_funcs
5
+
6
+ def do_func(self, scene_id, data):
7
+ child_data = data.childData
8
+ child_type = data.childType
9
+ do_func = self.do_func_map.get(child_type)
10
+ return do_func(child_data, scene_id)
@@ -1,19 +1,6 @@
1
- #
2
- # class EMS1000Action(BaseAction):
3
- # def __init__(self, smart_scene_service):
4
- # super().__init__(smart_scene_service)
5
- # self.do_func = self.do_ems1000_action
6
- # self.cabinet_type = None
7
- #
8
- # def do_ems1000_action(self, scene_id, data: EmsActionItemData):
9
- # if data.childType == "DoControl":
10
- # ret = self.do_control(data.childData.data)
11
- # else:
12
- # ret = False
13
- # return ret
14
- #
15
- # def do_control(self, data):
16
- # app_log.info("执行: DO控制")
17
- # self.smart_scene_service.ems_do_control(data)
18
- # return True
19
- #
1
+ from solax_py_library.smart_scene.core.action.base import BaseAction
2
+ from solax_py_library.smart_scene.types.action import ActionType
3
+
4
+
5
+ class EMS1000Action(BaseAction):
6
+ action_type = ActionType.EMS1000
@@ -1,241 +1,6 @@
1
- # from solax_py_library.smart_scene.core.action.base import BaseAction
2
- # from solax_py_library.smart_scene.types.action import SystemActionType
3
- # from solax_py_library.smart_scene.types.condition import SystemConditionItemData
4
- #
5
- #
6
- # class SystemAction(BaseAction):
7
- # def __init__(self, smart_scene_service, app_log):
8
- # super().__init__(smart_scene_service)
9
- # self.log = app_log
10
- # self.do_func = self.do_system_action
11
- # self.cabinet_type = None
12
- #
13
- # def do_system_action(self, scene_id, data: SystemConditionItemData):
14
- # child_data = data.childData
15
- # child_type = data.childType
16
- # data = child_data.data
17
- # if self.cabinet_type is None:
18
- # self.cabinet_type = self.smart_scene_service.get_cabinet_type()
19
- # if child_type == SystemActionType.systemSwitch:
20
- # return self.system_switch(data[0], scene_id)
21
- # elif child_type == SystemActionType.exportControl:
22
- # return self.export_control(data, scene_id)
23
- # elif child_type == SystemActionType.importControl:
24
- # return self.import_control(data, scene_id)
25
- # elif child_type == SystemActionType.workMode:
26
- # return self.work_mode(data, scene_id)
27
- # return False
28
- #
29
- #
30
- # class SystemSwitchAction(SystemAction):
31
- # def system_switch(self, value, scene_id) -> bool:
32
- # """系统开关机"""
33
- # if value not in [0, 1]:
34
- # value = 1
35
- # if self.cabinet_type in ["TRENE"]:
36
- # self.ems_tcp_service.set_trene_switch(value)
37
- # return True
38
- # else:
39
- # master_sn = self.device_service.get_master_inv_by_device()
40
- # # 如果为AELIO,则只需要操控主机
41
- # if master_sn:
42
- # data = {"sn": master_sn, "switch": value}
43
- # self.log.info(f"执行: 系统开关机, data: {data}")
44
- # t = threading.Thread(
45
- # target=self.smart_scene_service.request_local_server,
46
- # args=("setSystemSwitch", data, scene_id),
47
- # daemon=True,
48
- # )
49
- # t.start()
50
- # return True
51
- #
52
- #
53
- # class ExportControlAction(SystemAction):
54
- # def export_control(self, value, scene_id) -> bool:
55
- # """零输出控制"""
56
- # if len(value) != 4:
57
- # value.extend([1, 0, 1])
58
- # data = {
59
- # "isEnable": value[0],
60
- # "controlMode": value[1],
61
- # "exportValue": value[2],
62
- # "unitType": value[3],
63
- # }
64
- # self.log.info(f"执行: 馈网控制, data: {data}")
65
- # ret = self.smart_scene_service.request_local_server(
66
- # "editOutputControl", data, scene_id
67
- # )
68
- # if not ret or ret["success"] is False:
69
- # return False
70
- # return True
71
- #
72
- #
73
- # class ImportControlAction(SystemAction):
74
- # def import_control(self, value, scene_id) -> bool:
75
- # """需量控制"""
76
- # if self.cabinet_type in ["TRENE"]:
77
- # if len(value) != 3:
78
- # value.extend([1, 0])
79
- # data = {
80
- # "isAllowDischarge": value[1],
81
- # "demandLimitValue": value[2],
82
- # "isEnable": value[0],
83
- # }
84
- # else:
85
- # if len(value) != 2:
86
- # value.append(0)
87
- # data = {
88
- # "isAllowDischarge": 1,
89
- # "demandLimitValue": value[1],
90
- # "isEnable": value[0],
91
- # }
92
- # self.log.info(f"执行: 需量控制, data: {data}")
93
- # ret = self.smart_scene_service.request_local_server(
94
- # "editDemandControl", data, scene_id
95
- # )
96
- # if not ret or ret["success"] is False:
97
- # return False
98
- # return True
99
- #
100
- #
101
- # class WorkModeAction(SystemAction):
102
- # def work_mode(self, value, scene_id) -> bool:
103
- # # 0: self use; 1: 并网优先; 2: 备用模式; 3: 手动; 4: 削峰填谷 5: TOU(暂不用); 16: VPP
104
- # if value[0] not in [0, 1, 2, 3, 4, 16]:
105
- # return False
106
- # data = None
107
- # if self.cabinet_type in ["AELIO"]:
108
- # if value[0] in [0, 1, 2, 3, 4]:
109
- # data = {"useMode": value[0]}
110
- # elif self.cabinet_type in ["TRENE"]:
111
- # if value[0] in [0, 1, 3, 4]:
112
- # data = {"useMode": value[0]}
113
- # else:
114
- # return False
115
- # if data is not None: # 普通模式
116
- # self.log.info(f"普通模式控制 data: {data}")
117
- # # 手动模式
118
- # if data["useMode"] == 3:
119
- # if value[1] == 5:
120
- # value.extend([0, 10])
121
- # self.smart_scene_service.set_manual_mode(
122
- # value[1], value[2], value[3], self.cabinet_type
123
- # )
124
- # else:
125
- # self.smart_scene_service.request_local_server(
126
- # "setAelioUseMode", data, scene_id
127
- # )
128
- # else: # VPP模式
129
- # if self.cabinet_type in ["AELIO"]:
130
- # if value[1] == 1:
131
- # reg_value_list = [1]
132
- # # 有功功率
133
- # reg_value_list.extend(
134
- # self.smart_scene_service.struct_transform(
135
- # value[2] * 1000, "int32", "little"
136
- # )
137
- # )
138
- # # 无功功率
139
- # reg_value_list.extend(
140
- # self.smart_scene_service.struct_transform(
141
- # value[3] * 1000, "int32", "little"
142
- # )
143
- # )
144
- # # 持续时间35秒, 控制超时 35s,控制类型为set
145
- # reg_value_list.extend([35, 35, 1])
146
- # elif value[1] == 2:
147
- # reg_value_list = [2, 1]
148
- # # 能量目标
149
- # reg_value_list.extend(
150
- # self.smart_scene_service.struct_transform(
151
- # value[2] * 1000, "uint32", "little"
152
- # )
153
- # )
154
- # # 功率目标
155
- # reg_value_list.extend(
156
- # self.smart_scene_service.struct_transform(
157
- # value[3] * 1000, "int32", "little"
158
- # )
159
- # )
160
- # # 控制超时 35s
161
- # reg_value_list.extend([35])
162
- # elif value[1] == 3:
163
- # # 控制类型为set,SOC:value[2]
164
- # reg_value_list = [3, 1, value[2]]
165
- # # 充放电功率目标
166
- # reg_value_list.extend(
167
- # self.smart_scene_service.struct_transform(
168
- # value[3] * 1000, "int32", "little"
169
- # )
170
- # )
171
- # # 控制超时 35s
172
- # reg_value_list.extend([35])
173
- # elif value[1] == 4:
174
- # reg_value_list = [4]
175
- # # 电池功率目标
176
- # reg_value_list.extend(
177
- # self.smart_scene_service.struct_transform(
178
- # value[2] * 1000, "int32", "little"
179
- # )
180
- # )
181
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
182
- # reg_value_list.extend([35, 0xA0])
183
- # elif value[1] == 5:
184
- # reg_value_list = [5]
185
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
186
- # reg_value_list.extend([35, 0xA0])
187
- # elif value[1] == 6:
188
- # reg_value_list = [6]
189
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
190
- # reg_value_list.extend([35, 0xA0])
191
- # elif value[1] == 7:
192
- # reg_value_list = [7]
193
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
194
- # reg_value_list.extend([35, 0xA0])
195
- # elif value[1] == 8:
196
- # # 控制类型为set,
197
- # reg_value_list = [8, 1]
198
- # # PV功率限制
199
- # reg_value_list.extend(
200
- # self.smart_scene_service.struct_transform(
201
- # value[2] * 1000, "uint32", "little"
202
- # )
203
- # )
204
- # # 电池功率限制
205
- # reg_value_list.extend(
206
- # self.smart_scene_service.struct_transform(
207
- # value[3] * 1000, "int32", "little"
208
- # )
209
- # )
210
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
211
- # reg_value_list.extend([35, 0xA0])
212
- # elif value[1] == 9:
213
- # # 控制类型为set,
214
- # reg_value_list = [9, 1]
215
- # # PV功率限制
216
- # reg_value_list.extend(
217
- # self.smart_scene_service.struct_transform(
218
- # value[2] * 1000, "uint32", "little"
219
- # )
220
- # )
221
- # # 电池功率限制
222
- # reg_value_list.extend(
223
- # self.smart_scene_service.struct_transform(
224
- # value[3] * 1000, "int32", "little"
225
- # )
226
- # )
227
- # # 控制超时 35s, # 远程控制超时后需设备执行的模式 0xA0 关闭VPP,0xA1 默认的VPP模式
228
- # reg_value_list.extend([value[4], 35, 0xA0])
229
- # else:
230
- # reg_value_list = []
231
- # func_name = PCSOperateFunctionName.SET_AELIO_VPP_MODE
232
- # channel = options.REDIS_WRITE_SERIAL_DEVICE
233
- # future_data = {}
234
- # future_data["func_name"] = func_name
235
- # future_data["operationMode"] = Enumeration.SINGLE_DEVICE_MODE
236
- # future_data["data"] = {"value_list": reg_value_list}
237
- # app_log.info(f"VPP模式控制 data: {future_data}")
238
- # self.smart_scene_service.request_local_redis(
239
- # channel, json.dumps(future_data)
240
- # )
241
- # return True
1
+ from solax_py_library.smart_scene.core.action.base import BaseAction
2
+ from solax_py_library.smart_scene.types.action import ActionType
3
+
4
+
5
+ class SystemAction(BaseAction):
6
+ action_type = ActionType.system
@@ -2,6 +2,18 @@ import copy
2
2
  import struct
3
3
  from typing import List
4
4
 
5
+ format_map = {
6
+ "int8": "bb",
7
+ "uint8": "BB",
8
+ "int16": "h",
9
+ "uint16": "H",
10
+ "int32": "i",
11
+ "uint32": "I",
12
+ "int64": "q",
13
+ "uint64": "Q",
14
+ "float": "f",
15
+ }
16
+
5
17
 
6
18
  def unpack(data: List, data_format, reversed=False):
7
19
  """
@@ -11,20 +23,29 @@ def unpack(data: List, data_format, reversed=False):
11
23
  """
12
24
  cur_data = copy.deepcopy(data)
13
25
  data_format = data_format.lower()
14
- format_map = {
15
- "int8": "bb",
16
- "uint8": "BB",
17
- "int16": "h",
18
- "uint16": "H",
19
- "int32": "i",
20
- "uint32": "I",
21
- "int64": "q",
22
- "uint64": "Q",
23
- "float": "f",
24
- }
25
26
  if data_format not in format_map:
26
27
  raise Exception("暂不支持")
27
28
  pack_str = ("<" if reversed else ">") + "H" * len(cur_data)
28
29
  to_pack_data = struct.pack(pack_str, *cur_data)
29
30
  struct_format = ("<" if reversed else ">") + format_map[data_format]
30
31
  return struct.unpack(struct_format, to_pack_data)
32
+
33
+
34
+ def struct_transform(value, fmt, order="big"):
35
+ """将10进制的原始值转换为modbus协议需要的精度与类型的值"""
36
+ opt = "<" if order == "little" else ">"
37
+ try:
38
+ value = int(value)
39
+ if fmt in format_map:
40
+ ret = struct.pack(f"{opt}{format_map[fmt]}", value)
41
+ ret_list = struct.unpack(f"{opt}H", ret)
42
+ else:
43
+ ret_list = [0]
44
+ except Exception:
45
+ if "16" in fmt:
46
+ ret_list = [0]
47
+ elif "32" in fmt:
48
+ ret_list = [0, 0]
49
+ else:
50
+ ret_list = [0, 0, 0, 0]
51
+ return list(ret_list)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: solax-py-library
3
- Version: 1.0.0.2514
3
+ Version: 1.0.0.2515
4
4
  Summary: some common tool
5
5
  Author: shenlvyu
6
6
  Author-email: 13296718439@163.com
@@ -16,9 +16,9 @@ solax_py_library/smart_scene/constant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCe
16
16
  solax_py_library/smart_scene/constant/message_entry.py,sha256=Ah2yDNpsf1W4HKD-tCzK6xtew0H5TLN7ko7kSsXgcng,8973
17
17
  solax_py_library/smart_scene/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  solax_py_library/smart_scene/core/action/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- solax_py_library/smart_scene/core/action/base.py,sha256=vSC3rL9qfPy41Nlds_0QcTLMbf4n-P18XUBJ3oYiNGk,237
20
- solax_py_library/smart_scene/core/action/ems_action.py,sha256=tasL7pUJbnmrEEokAa9Mug5eUFvHuFKGYZKNvNMdrBs,610
21
- solax_py_library/smart_scene/core/action/system_action.py,sha256=mVLTg9pZ7tDayLbr3I92a33snA2AGT3meUdm_XYDQEc,10839
19
+ solax_py_library/smart_scene/core/action/base.py,sha256=bH1FZX3lVtbG4tQPIaOrwv8-htMu2CwryOPMZ8fV3Qg,390
20
+ solax_py_library/smart_scene/core/action/ems_action.py,sha256=sML6qasFoqOktTvEcHm0vKPYCj60VcKjAFz8RAaQc2U,206
21
+ solax_py_library/smart_scene/core/action/system_action.py,sha256=oGXq3yXS9nKcGjJActjk0R2Wr3AoO9uoyRPyuiM053g,204
22
22
  solax_py_library/smart_scene/core/condition/__init__.py,sha256=1nN-N52Oq7LKdn6ApKGtSZq5fB1qJzJq8BOKOumfQvY,475
23
23
  solax_py_library/smart_scene/core/condition/base.py,sha256=saj7dc0Su2Wi_Lx04cesHFgIPDyQUwvHuDElcaDOIHU,596
24
24
  solax_py_library/smart_scene/core/condition/cabinet_condition.py,sha256=HEVifO3rHk2ElfSCEB0MzVdfrFWlkwqjt6tFhtJ8CLY,1581
@@ -73,8 +73,8 @@ solax_py_library/upload/types/ftp.py,sha256=9kCeLB0g5Je19v4ifz8YYEsGOhJL1lKBO2C6
73
73
  solax_py_library/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  solax_py_library/utils/cloud_client.py,sha256=5dZrc5fzrNFSXqTPZd7oHt-Y9Jj6RCigB7aXJQMJ8sQ,9610
75
75
  solax_py_library/utils/common.py,sha256=bfnZcX9uM-PjJrYAFv1UMmZgt6bGR7MaOd7jRPNHGxw,1238
76
- solax_py_library/utils/struct_util.py,sha256=4SKx5IyAke88PGHPHDK3OEDtyGHdapGoQ1BnGR0F2ts,913
76
+ solax_py_library/utils/struct_util.py,sha256=nlMaopAWy5bN_NGiNph0Kou5wuuYprq5lTm7h1rXJCA,1477
77
77
  solax_py_library/utils/time_util.py,sha256=bY5kj9dmyOuLEQ6uYGQK7jU7y1RMiHZgevEKnkcQcSU,1461
78
- solax_py_library-1.0.0.2514.dist-info/METADATA,sha256=2aiCh__xWlAwyUZxGCK5qlIlz3kRyGTEO8CHz__cLG8,1827
79
- solax_py_library-1.0.0.2514.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
80
- solax_py_library-1.0.0.2514.dist-info/RECORD,,
78
+ solax_py_library-1.0.0.2515.dist-info/METADATA,sha256=wXQlZNxou41J6NRtFQCV2qK8v1rzEKBUmF0J29qArW0,1827
79
+ solax_py_library-1.0.0.2515.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
80
+ solax_py_library-1.0.0.2515.dist-info/RECORD,,