Installation
yarn add @tuya/tuya-panel-api
import { lampApi } from '@tuya/tuya-panel-api';
Scene API
const { getSceneVersionInfo, getSceneData, updateVersion } = lampApi;
Scene methods
| Method name |
Purpose |
Parameter |
| getSceneVersionInfo |
Returns the current version and all versions of the scene library. |
(sceneId : number ) |
| getSceneData |
Returns scene resources. |
(libVersion: string) |
| updateVersion |
Edits an image of a smart scene. |
(libVersion: string) |
Example
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);
})
Device property API
const { getAllCloudConfig, saveCloudConfig, deleteCloudConfig, syncCloudConfig, fetchLocalConfig, fetchCloudConfig } = lampApi;
Device property methods
| Method name |
Purpose |
Parameter |
| getAllCloudConfig |
Returns all device properties. |
None |
| saveCloudConfig |
Saves device custom properties. |
(code: string, data: any) |
| deleteCloudConfig |
Deletes device custom properties. |
(code: string) |
| syncCloudConfig |
Syncs device properties. |
None |
| fetchLocalConfig |
Returns device properties cached locally. |
None |
| fetchCloudConfig |
Returns device properties saved in the cloud. Device properties cached locally are used in priority over those in the cloud. |
None |
Example
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);
});
Biorhythm API
const { isSupportRhythm, getCurrentLocation, getCityInfoByLocation, saveRhythmInfo, getRhythmTimeByLocation, getCloudCustomRhythm, getCloudCityInfo, triggerRhythmStatus } = lampApi;
Biorhythm methods
| Method name |
Description |
Parameter |
Remarks |
| isSupportRhythm |
Specifies whether to support biorhythm. |
None |
Return value: Promise<boolean>. |
| getCurrentLocation |
Returns the longitude and latitude of the current location. The location permission must be turned on for the app. |
None |
Return value: Promise<{ longitude: number; latitude: number }>. |
| saveRhythmInfo |
Saves the biorhythm information. This feature can be enabled or disabled. |
(propertyList: []) |
For more information about the request parameters, see Example. |
| triggerRhythmStatus |
Updates the biorhythm information. |
( cronExp: string; ) |
The cron expression. If it is not set, the biorhythm information is updated once per month. |
| getRhythmTimeByLocation |
Returns the sunrise and sunset time at the specified location. The time is converted to the time zone where the device is located before the result is returned. |
(lon: string, lat: string) |
lon: the longitude of the specified location.lat: the latitude of the specified location.
|
| getCityInfoByLocation |
Returns the city information at the specified location. |
(lon: string, lat: string) |
lon: the longitude of the specified location.lat: the latitude of the specified location.
|
| getCloudCustomRhythm |
Returns the custom biorhythm data that is saved by saveRhythmInfo. |
None |
For more information, see Example |
| getCloudCityInfo |
Returns the city information that is saved in the cloud by saveRhythmInfo. |
None |
For more information, see Example. |
Example
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": 39.90960456049752
"longitude":116.3972282409668,
"name":"Beijing, China",
"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; // The sunrise time that is displayed in the format of HH:MM.
sunset: string; // The sunset time that is displayed in the format of HH:MM.
transitAtNoon: string; // The noon time that is displayed in the format of HH:MM.
dawn: string; // The dawn time that is displayed in the format of HH:MM.
dusk: string; // The dusk time that is displayed in the format of HH:MM.
date: string; // The date.
}[]) => {
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);
})