安装
yarn add @tuya/tuya-panel-api
import { lampApi } from '@tuya/tuya-panel-api';
场景 API
const { getSceneVersionInfo, getSceneData, updateVersion } = lampApi;
场景方法
| 方法名称 |
用途 |
参数 |
| getSceneVersionInfo |
获取当前情景库版本及版本集合 |
(sceneId : number ) |
| getSceneData |
获取情景资源 |
(libVersion: string) |
| updateVersion |
编辑具体场景图片 |
(libVersion: string) |
使用示例
const { getSceneVersionInfo, getSceneData, updateVersion } = lampApi;
getSceneVersionInfo().then((response: any) => {
console.log(response);
})
getSceneData(version).then((response: ISceneData[]) => {
console.log(response);
})
updateVersion(version).then((flag: boolean) => {
console.log(flag);
})
设备属性 API
const { getAllCloudConfig, saveCloudConfig, deleteCloudConfig, syncCloudConfig, fetchLocalConfig, fetchCloudConfig } = lampApi;
设备属性方法
| 方法名称 |
用途 |
参数 |
| getAllCloudConfig |
获取设备全部属性数据 |
- |
| saveCloudConfig |
保存设备自定义属性数据 |
(code: string, data: any) |
| deleteCloudConfig |
删除设备自定义属性数据 |
(code: string) |
| syncCloudConfig |
同步设备属性数据 |
- |
| fetchLocalConfig |
获取设备属性本地缓存数据 |
- |
| fetchCloudConfig |
获取设备属性云端数据,且优先取缓存数据 |
- |
使用示例
const { getAllCloudConfig, saveCloudConfig, deleteCloudConfig, syncCloudConfig, fetchLocalConfig, fetchCloudConfig } = lampApi;
getAllCloudConfig().then((data: Record<string, string>) => {
console.log(data);
});
saveCloudConfig(code: string, data: any).then((data:Promise<any>) => {
console.log(data);
});
deleteCloudConfig(code: string).then((data:Promise<any>) => {
console.log(data);
});
syncCloudConfig().then((data:Promise<any>) => {
console.log(data);
});
fetchLocalConfig().then((data:Promise<any>) => {
console.log(data);
});
fetchCloudConfig().then((data:Promise<any>) => {
console.log(data);
});
生物节律 API
const { isSupportRhythm, getCurrentLocation, getCityInfoByLocation, saveRhythmInfo, getRhythmTimeByLocation, getCloudCustomRhythm, getCloudCityInfo, triggerRhythmStatus } = lampApi;
生物节律方法
| 方法名称 |
说明 |
参数 |
备注 |
| isSupportRhythm |
是否支持生物节律高级功能 |
无 |
返回值 Promise<boolean> |
| getCurrentLocation |
获取当前位置的经纬度,必须开启 App 定位权限 |
无 |
返回值 Promise<{ longitude: number; latitude: number }> |
| saveRhythmInfo |
保存生物节律信息,支持开启与关闭 |
(propertyList: []) |
入参 详情见下方示例 |
| triggerRhythmStatus |
触发定时生物节律开启关闭 |
( cronExp: string; ) |
cron 表达式,如果不传入 cron 表达式,默认频率为一个月下发一次 |
| getRhythmTimeByLocation |
获取指定地理位置的日出日落时间,并转换成设备所在时区给出 |
(lon: string, lat: string) |
- lon:用户选择的地理位置的经度
- lat:用户选择的地理位置的纬度
|
| getCityInfoByLocation |
获取指定地理位置所在的城市信息 |
(lon: string, lat: string) |
- lon:用户选择的地理位置的经度
- lat:用户选择的地理位置的纬度
|
| getCloudCustomRhythm |
获取自定义生物节律数据,数据通过 saveRhythmInfo 接口保存 |
- |
详情见下方示例 |
| getCloudCityInfo |
获取云端存储的城市信息,数据通过 saveRhythmInfo 接口保存 |
- |
详情见下方示例 |
使用示例
const { isSupportRhythm, getCurrentLocation, getCityInfoByLocation, saveRhythmInfo, getRhythmTimeByLocation, getCloudCustomRhythm, getCloudCityInfo, triggerRhythmStatus } = lampApi;
isSupportRhythm().then((isSupport: boolean) => {
console.log(isSupport);
})
getCurrentLocation().then( { longitude: number; latitude: number } ) => {
console.log(longitude, latitude);
})
const lon = '';
const lat = '';
getCityInfoByLocation(lon, lat).then(cityInfo: {
country: string;
province: string;
city: string;
}) => {
console.log(cityInfo);
})
const params = {
propertyList: [{
"value":{
"power":0,
"latitude":61.40579401252338,
"longitude":113.86011110349514,
"name":"连斯基区,俄罗斯",
"mode":0
},
"code":"leona_rhythm_info"
}, {
"value":{
"weeks":127,
"power":1,
"number":5,
"rhythm":{
"minute":29,
"hour":18,
"brightness":0,
"power":1,
"temperature":100,
"saturation":0,
"lightness":0,
"hue":0
},
"mode":0,
"version":0
},
"code":"leona_rhythm_dp_dawn"
},
]
}
saveRhythmInfo(propertyList).then((success: boolean) => {
console.log(success);
})
const cronExp = '';
triggerRhythmStatus(cronExp).then(success: boolean) => {
console.log(success);
})
const lon = '';
const lat = '';
getRhythmTimeByLocation(lon, lat).then((rhythmTimeInfo: {
sunrise: string; // 日出(时分)
sunset: string; // 日落(时分)
transitAtNoon: string; // 正午(时分)
dawn: string; // 日出前(时分)
dusk: string; // 日落后(时分)
date: string; // 日期
}[]) => {
console.log(rhythmTimeInfo);
})
type CustomRhythm = {
value: {
weeks: number;
power: EPower;
number: number;
rhythm: {
minute: number;
hour: number;
brightness: number;
power: number;
temperature: number;
saturation: number;
lightness: number;
hue: number;
};
mode: EMode;
version: number;
};
code:
| 'leona_rhythm_dp_dawn'
| 'leona_rhythm_dp_dusk'
| 'leona_rhythm_dp_noon'
| 'leona_rhythm_dp_sunrise'
| 'leona_rhythm_dp_sunset';
};
getCloudCustomRhythm().then(customRhythmList: CustomRhythm[]) => {
console.log(customRhythmList);
})
type CityLocationInfo = {
name: string;
latitude: string;
longitude: string;
};
getCloudCityInfo().then(cityInfo: CityLocationInfo) => {
console.log(cityInfo);
})