@ledvance/ui-biz-bundle 1.1.150 → 1.1.151

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.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.150",
7
+ "version": "1.1.151",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -10,10 +10,11 @@ import {
10
10
  getSpecifiedTimeDpReportLogs
11
11
  } from '@ledvance/base/src/models/TuyaApi'
12
12
  import { exportCsvFile, localeNumber, loopsText, monthFormat, monthFormatShort } from '@ledvance/base/src/utils/common'
13
- import { overDays } from '@ledvance/base/src/utils'
13
+ import { overDays, xLog } from '@ledvance/base/src/utils'
14
14
  import dayjs from 'dayjs'
15
15
  import CustomParseFormat from 'dayjs/plugin/customParseFormat'
16
16
  import { isEmpty } from 'lodash'
17
+ import { TYSdk } from 'tuya-panel-kit'
17
18
  import { DateType } from './co2Data'
18
19
  import { EnergyData } from './component/EnergyModal'
19
20
  import { OverviewItem } from './EnergyConsumptionPage'
@@ -39,6 +40,11 @@ export async function updatePrice(devId: string, energyData: EnergyData) {
39
40
  return await NativeApi.putJson(devId, 'energiepreise', JSON.stringify(energyData))
40
41
  }
41
42
 
43
+ export async function resetElectricity(devId) {
44
+ const res = await TYSdk.apiRequest('tuya.m.dp.statistics.reset', {devId}, '1.0')
45
+ xLog('resetElectricity res', res)
46
+ }
47
+
42
48
  export async function getElectricity(devId: string, addEleDpCode: string, date: string, dateType: DateType): Promise<OverviewItem[]> {
43
49
  let res: OverviewItem[] = []
44
50
  switch (dateType) {
@@ -175,83 +181,37 @@ function createZeroPaddingPoint(timePoint: dayjs.Dayjs): PowerDataItem {
175
181
  }
176
182
 
177
183
  /**
178
- * 获取设备功率数据(智能填充,高性能,避免在小间隔内插入0值)
184
+ * 获取设备功率数据
179
185
  * @param devId 设备ID
180
186
  * @param powerDpCode 功率数据点编码
181
187
  * @param interval 时间区间(分钟)
182
188
  * @returns 按时间排序的完整数据
183
189
  */
184
- export async function getPowerData(
185
- devId: string,
186
- powerDpCode: string,
187
- interval: number
188
- ): Promise<PowerDataItem[]> {
189
- try {
190
- const now = dayjs();
191
- const endTime = now;
192
- const startTime = now.add(-interval, TIME_UNIT);
193
- const endTimeMs = endTime.valueOf();
194
- const startTimeMs = startTime.valueOf();
195
- const paddingIntervalMs = DATA_POINT_INTERVAL_SEC * 1000;
196
- // 1. 请求已排序的实际数据
197
- const dpResult = await getSpecifiedTimeDpReportLogs(
198
- devId,
199
- [powerDpCode],
200
- 'ASC',
201
- startTimeMs.toString(),
202
- endTimeMs.toString(),
203
- RETRY_CONFIG
204
- );
205
- const validDpResult = Array.isArray(dpResult) ? (dpResult as DpReportSataData[]) : [];
206
- const actualData: PowerDataItem[] = validDpResult
207
- .map((dp) => {
208
- const timeMs = dp.timeStamp * 1000;
209
- if (timeMs < startTimeMs || timeMs > endTimeMs) return null;
210
- return {
211
- key: dayjs.unix(dp.timeStamp).format('HH:mm:ss'),
212
- chartTitle: dayjs.unix(dp.timeStamp).format('MM/DD/YYYY HH:mm:ss'),
213
- time: timeMs,
214
- value: parseFloat(dp.value) / 10,
215
- };
216
- })
217
- .filter((item): item is PowerDataItem => item !== null);
218
- // 如果没有任何真实数据,则生成完整的预设0值数据作为兜底
219
- if (actualData.length === 0) {
220
- const finalData: PowerDataItem[] = [];
221
- let currentTime = startTime;
222
- while (currentTime.valueOf() < endTimeMs) {
223
- finalData.push(createZeroPaddingPoint(currentTime));
224
- currentTime = currentTime.add(DATA_POINT_INTERVAL_SEC, 'second');
225
- }
226
- return finalData;
190
+ export async function getPowerData(devId: string, powerDpCode: string, interval: number): Promise<PowerDataItem[]> {
191
+ const now = dayjs()
192
+ const startTime = now.add(-1 * interval, 'minute').valueOf().toString()
193
+ const endTime = now.valueOf().toString()
194
+ const dpResult = await getSpecifiedTimeDpReportLogs(
195
+ devId,
196
+ [powerDpCode],
197
+ 'ASC',
198
+ startTime,
199
+ endTime,
200
+ {
201
+ maxRetries: 5,
202
+ initialDelay: 1000,
203
+ maxDelay: 30000,
204
+ backoffFactor: 2
227
205
  }
228
- // 2. 高性能线性填充
229
- const finalData: PowerDataItem[] = [];
230
- let lastTimeMs = startTimeMs; // 游标从查询区间的开始时间算起
231
- // 遍历所有真实数据点
232
- actualData.forEach((currentPoint) => {
233
- // 从上一个点的时间开始,用 while 循环填充,直到下一个真实数据点之前
234
- let paddingTimeMs = lastTimeMs + paddingIntervalMs;
235
- while (paddingTimeMs < currentPoint.time) {
236
- finalData.push(createZeroPaddingPoint(dayjs(paddingTimeMs)));
237
- paddingTimeMs += paddingIntervalMs;
238
- }
239
-
240
- // 添加当前的真实数据点
241
- finalData.push(currentPoint);
242
- lastTimeMs = currentPoint.time; // 更新游标
243
- });
244
- // 3. 填充查询末尾的空白区域(从最后一个真实数据点到查询结束时间)
245
- let paddingTimeMs = lastTimeMs + paddingIntervalMs;
246
- while (paddingTimeMs < endTimeMs) {
247
- finalData.push(createZeroPaddingPoint(dayjs(paddingTimeMs)));
248
- paddingTimeMs += paddingIntervalMs;
206
+ ) as DpReportSataData[]
207
+ return dpResult.map(dp => {
208
+ return {
209
+ key: dp.timeStr,
210
+ chartTitle: dayjs.unix(dp.timeStamp).format('MM/DD/YYYY HH:mm:ss'),
211
+ time: dp.timeStamp * 1000,
212
+ value: parseFloat(dp.value) / 10
249
213
  }
250
- return finalData;
251
- } catch (error) {
252
- console.error(`[getPowerData] 失败:devId=${devId}, powerDpCode=${powerDpCode}`, error);
253
- return [];
254
- }
214
+ })
255
215
  }
256
216
 
257
217
  export const exportEnergyCsv = (values: any[][], unit: string) => {