IDE 0.10.9
Smartlife 7.11.0(int)
@ray-js/cli": "1.7.55"
@ray-js/panel-sdk": "1.14.1"
Realme 8 pro, Andr. 13
Product ID: idqdrp5x
Can't read log for dp101 (1w error code), dp102 (CRC error rate)
I need the log itself, not just a display of the current value.
import React, { useEffect, useState } from 'react';
import { Text, View } from '@ray-js/ray';
import { Layout } from '@/components/layout';
import { useDevice } from '@ray-js/panel-sdk';
import { errorTranslations } from '@/utils/errorCodes';
declare const ty: any;
export function ErrLog() {
const devId: string = useDevice((d: any) => d.devInfo.devId) || '';
const [logs, setLogs] = useState<any[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [debugInfo, setDebugInfo] = useState<string>('Initializing...');
useEffect(() => {
const fetchLogs = async () => {
try {
setLoading(true);
setDebugInfo('Searching for log API...');
Code: Select all
let logFunc: any = null;
let foundName = '';
if (typeof ty !== 'undefined' && ty.device) {
if (typeof ty.device.getDpReportRecord === 'function') { logFunc = ty.device.getDpReportRecord; foundName = 'getDpReportRecord'; }
else if (typeof ty.device.getDeviceLog === 'function') { logFunc = ty.device.getDeviceLog; foundName = 'getDeviceLog'; }
else if (typeof ty.device.getDpLogList === 'function') { logFunc = ty.device.getDpLogList; foundName = 'getDpLogList'; }
}
if (!logFunc) {
throw new Error("Log API methods not found in SDK");
}
setDebugInfo(`Found ${foundName}! Fetching...`);
const endTime: number = Date.now();
const startTime: number = endTime - 30 * 24 * 60 * 60 * 1000; // 30 дней назад
const res: any = await new Promise((resolve, reject) => {
logFunc({
devId,
dpIds: '1,101,104',
startTime: String(startTime),
endTime: String(endTime),
size: 50,
success: (data: any) => resolve(data),
fail: (err: any) => reject(err)
});
});
console.log('=== RAW LOGS RESPONSE ===', res);
setDebugInfo(`Response received. Parsing...`);
if (res && (res.dps || res.list || res.data || res.logs || res.result?.logs)) {
const rawLogs = res.dps || res.list || res.data || res.logs || res.result.logs;
const formattedLogs = rawLogs.map((log: any) => ({
time: log.timeStamp ? log.timeStamp * 1000 : (log.gmtCreate || log.time),
value: log.value !== undefined ? log.value : log.dpValue,
dpId: log.dpId || 'N/A'
}));
formattedLogs.sort((a: any, b: any) => b.time - a.time);
setLogs(formattedLogs);
setDebugInfo(`Loaded ${formattedLogs.length} logs`);
} else {
setLogs([]);
setDebugInfo('Logs array is empty in response');
}
} catch (err: any) {
console.log('Error fetching logs:', err);
const msg = err?.message || err?.errorMsg || JSON.stringify(err);
setLogs([]);
setDebugInfo(`Error: ${msg}`);
} finally {
setLoading(false);
}
};
if (devId) {
fetchLogs();
} else {
setLoading(false);
setDebugInfo('DevId is missing');
}}, [devId]);
const formatTime = (timestamp: number): string => {
const date = new Date(timestamp);
return date.toLocaleString('en-GB', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' });
};
return (
<Layout title="Err log" showBack={true}>
<View style={{ flex: 1, backgroundColor: '#f2f4f6', boxSizing: 'border-box' }}>
Code: Select all
<View style={{ margin: '20rpx', padding: '15rpx', backgroundColor: '#333', borderRadius: '10rpx' }}>
<Text style={{ color: '#0f0', fontSize: '20rpx' }}>Status: {debugInfo}</Text>
</View>
<View style={{ padding: '32rpx' }}>
{loading && (
<View style={{ marginTop: '100rpx', textAlign: 'center' }}>
<Text style={{ color: '#999' }}>Loading logs...</Text>
</View>
)}
{!loading && logs.length === 0 && (
<View style={{ marginTop: '100rpx', textAlign: 'center' }}>
<Text style={{ color: '#999' }}>No logs available</Text>
</View>
)}
{!loading && logs.length > 0 && (
<View>
{logs.map((item: any, index: number) => {
const isError: boolean = item.value !== 'no_errors';
return (
<View
key={index}
style={{
backgroundColor: '#ffffff',
padding: '32rpx',
marginBottom: '24rpx',
borderRadius: '16rpx',
display: 'flex',
flexDirection: 'row',
alignItems: 'center'
}}
>
<View style={{
width: '16rpx',
height: '16rpx',
borderRadius: '50%',
backgroundColor: isError ? '#ff4d4f' : '#52c41a',
marginRight: '24rpx'
}} />
<View style={{ flex: 1 }}>
<Text style={{ fontSize: '28rpx', fontWeight: 'bold', color: '#333', display: 'block' }}>
DP{item.dpId}: {errorTranslations[item.value] || item.value}
</Text>
<Text style={{ fontSize: '24rpx', color: '#999', marginTop: '8rpx', display: 'block' }}>
{formatTime(item.time)}
</Text>
</View>
</View>
);
})}
</View>
)}
</View>
</View>
</Layout>);
}
export default ErrLog;
Shows "Log API methods not found in SDK"