|
|
@@ -590,6 +590,7 @@ Page({
|
|
|
isClickedOnHumidifierDown: false,
|
|
|
isClickedOnClimateAuto: false,
|
|
|
isClickedOnClimateUp: false,
|
|
|
+ isClickedToggleAromlight: false,//香薰机灯光
|
|
|
intervalId1: null,
|
|
|
intervalId2: null,
|
|
|
|
|
|
@@ -892,6 +893,53 @@ onSelect_All(e) {
|
|
|
});
|
|
|
|
|
|
},
|
|
|
+//香薰机灯光控制
|
|
|
+onSelect_All_aromlight(e) {
|
|
|
+ var that = this;
|
|
|
+ this.setData({
|
|
|
+ isClickedToggleAromlight: true
|
|
|
+ });
|
|
|
+ // 获取绑定的参数
|
|
|
+ var param0 = e.currentTarget.dataset.param0;
|
|
|
+ var param1 = e.currentTarget.dataset.param1;
|
|
|
+ var param2 = e.currentTarget.dataset.param2;
|
|
|
+ // var param3 = e.currentTarget.dataset.param3;
|
|
|
+ // var param4 = e.currentTarget.dataset.param4;
|
|
|
+ var param5 = e.currentTarget.dataset.param5;
|
|
|
+ console.log('param1='+param1);
|
|
|
+ console.log('param2='+param2);
|
|
|
+ // console.log('param3='+param3);
|
|
|
+ // console.log('param4='+param4);
|
|
|
+ console.log('param5='+param5);
|
|
|
+ // this.setData({
|
|
|
+ // status_beep: Number(param4)
|
|
|
+ // })
|
|
|
+ // if(param3 == "/turn_on"){
|
|
|
+ // that.data.listSwitch[param0].state = "off";
|
|
|
+ // that.data.listSwitch[param0].service = "turn_off";
|
|
|
+ // }else if(param3 == "/turn_off"){
|
|
|
+ // that.data.listSwitch[param0].state = "on";
|
|
|
+ // that.data.listSwitch[param0].service = "turn_on";
|
|
|
+ // }
|
|
|
+ console.log('switch 发生 change 事件,携带值为', e.detail.value)
|
|
|
+ wx.request({
|
|
|
+ url: `${homeApi_https}`+param1+param2+'/turn_on',
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ "entity_id":param5
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json', // 默认值
|
|
|
+ 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
|
|
|
+ },
|
|
|
+ success(res) {
|
|
|
+ // if(res.data){
|
|
|
+ // that.getSwitch(res.data,that)
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
onSelect_Cover(e) {
|
|
|
var that = this;
|
|
|
// 获取绑定的参数
|
|
|
@@ -1407,7 +1455,7 @@ onSelect_beep1(e) {
|
|
|
}
|
|
|
obj.state = (resData[i].state=='unknown'?"未知":resData[i].state);
|
|
|
if(resData[i].attributes && resData[i].attributes.friendly_name){
|
|
|
- obj.friendly_name = resData[i].attributes.friendly_name; //设备名称
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name); //设备名称
|
|
|
}
|
|
|
if(resData[i].attributes && resData[i].attributes.home_room){
|
|
|
obj.home_room = resData[i].attributes.home_room.split(' ')[1]; //房间号
|
|
|
@@ -1421,6 +1469,8 @@ onSelect_beep1(e) {
|
|
|
}else if(resData[i].state=='off'){
|
|
|
obj.service = 'turn_off';
|
|
|
}
|
|
|
+ //是否 是香薰机灯光
|
|
|
+ obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
|
|
|
if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
listSwitchTemp.push(obj)
|
|
|
}
|
|
|
@@ -1489,7 +1539,27 @@ onSelect_beep1(e) {
|
|
|
}
|
|
|
this.getService("/services","/"+domain,"/set_value","POST",data);
|
|
|
},
|
|
|
-
|
|
|
+ changeHumidity(e){
|
|
|
+ let list = this.data.listHumidifier;//这里是将需要循环的数组赋值给list
|
|
|
+ let indexS = Number(e.currentTarget.dataset.index);
|
|
|
+ let domain = e.currentTarget.dataset.domain;
|
|
|
+ let entity_id = e.currentTarget.dataset.id;
|
|
|
+ // 将本地缓存数据渲染到对应修改的案例
|
|
|
+ list.forEach(function (value,index, array){
|
|
|
+
|
|
|
+ if (index == indexS) {
|
|
|
+ array[index].humidity = e.detail.value;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ listHumidifier: list
|
|
|
+ })
|
|
|
+ let data = {
|
|
|
+ "entity_id":entity_id,
|
|
|
+ "humidity":e.detail.value
|
|
|
+ }
|
|
|
+ this.getService("/services","/"+domain,"/set_humidity","POST",data);
|
|
|
+ },
|
|
|
onHumidifierDown(e) {
|
|
|
var that = this;
|
|
|
this.setData({
|
|
|
@@ -1585,7 +1655,68 @@ onSelect_beep1(e) {
|
|
|
this.getService("/services","/"+domain,"/turn_off","POST",data);
|
|
|
},
|
|
|
|
|
|
-
|
|
|
+ changeClimate(e) {
|
|
|
+ var that = this;
|
|
|
+ this.setData({
|
|
|
+ isClickedOnClimateUp: true
|
|
|
+ });
|
|
|
+ console.log('that.data.climateMode=='+that.data.climateMode);
|
|
|
+ if(!that.data.climateMode){
|
|
|
+ wx.showToast({
|
|
|
+ title: '请先选择模式',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let currentValue = e.currentTarget.dataset.temperature;
|
|
|
+ let fanMode = e.currentTarget.dataset.fanMode;
|
|
|
+
|
|
|
+ let min = e.currentTarget.dataset.min;
|
|
|
+ let max = e.currentTarget.dataset.max;
|
|
|
+ let domain = e.currentTarget.dataset.domain;
|
|
|
+ let entity_id = e.currentTarget.dataset.id;
|
|
|
+ let data = {};
|
|
|
+ if(that.data.climateMode=='heat' ||that.data.climateMode=='cool'){
|
|
|
+ let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
|
|
|
+ if(newValue>max) newValue = max;
|
|
|
+ let list = this.data.listClimate;//这里是将需要循环的数组赋值给list
|
|
|
+ let indexS = Number(e.currentTarget.dataset.index);
|
|
|
+ // 将本地缓存数据渲染到对应修改的案例
|
|
|
+ list.forEach(function (value,index, array){
|
|
|
+ if (index == indexS) {
|
|
|
+ array[index].temperature = e.detail.value;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ listClimate: list
|
|
|
+ })
|
|
|
+ data = {
|
|
|
+ "entity_id":entity_id,
|
|
|
+ "temperature":e.detail.value,
|
|
|
+ "hvac_mode":that.data.climateMode
|
|
|
+ }
|
|
|
+ this.getService("/services","/"+domain,"/set_temperature","POST",data);
|
|
|
+ }else if(that.data.climateMode=='dry'){
|
|
|
+ let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
|
|
|
+ if(newValue>max) newValue = max;
|
|
|
+ data = {
|
|
|
+ "entity_id":entity_id,
|
|
|
+ "temperature":e.detail.value,
|
|
|
+ "hvac_mode":that.data.climateMode
|
|
|
+ }
|
|
|
+ this.getService("/services","/"+domain,"/set_temperature","POST",data);
|
|
|
+ }else if(that.data.climateMode=='fan_only'){
|
|
|
+ let newValue = parseInt(currentValue) + 1; // 假设文本框中的是数字
|
|
|
+ if(newValue>max) newValue = max;
|
|
|
+ data = {
|
|
|
+ "entity_id":entity_id,
|
|
|
+ // "fan_mode":(fanMode=='Fan Speed Up')?'Fan Speed Down':'Fan Speed Up',
|
|
|
+ "temperature":e.detail.value,
|
|
|
+ "hvac_mode":that.data.climateMode
|
|
|
+ }
|
|
|
+ this.getService("/services","/"+domain,"/set_temperature","POST",data);
|
|
|
+ }
|
|
|
+ },
|
|
|
onClimateDown(e) {
|
|
|
var that = this;
|
|
|
if(!that.data.climateMode){
|
|
|
@@ -2382,7 +2513,9 @@ onSelect_beep1(e) {
|
|
|
obj.service = 'turn_off';
|
|
|
}
|
|
|
//截取字符串,防止开关设备名称过长
|
|
|
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
+ //是否 是香薰机灯光
|
|
|
+ obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
|
|
|
if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
listSwitchTemp.push(obj)
|
|
|
}
|
|
|
@@ -2392,7 +2525,7 @@ onSelect_beep1(e) {
|
|
|
){
|
|
|
obj.current_position = resData[i].attributes.current_position;
|
|
|
obj.target_position = resData[i].attributes.target_position;
|
|
|
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
listCoverTemp.push(obj)
|
|
|
}
|
|
|
@@ -2405,7 +2538,7 @@ onSelect_beep1(e) {
|
|
|
// obj.min = resData[i].attributes.min;
|
|
|
// obj.max = resData[i].attributes.max;
|
|
|
// obj.step = resData[i].attributes.step;
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// if(resData[i].state!='unknown'){
|
|
|
// obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
|
|
|
// }
|
|
|
@@ -2426,7 +2559,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='button' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
// listButtonTemp.push(obj);
|
|
|
// }
|
|
|
@@ -2435,7 +2568,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='select' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.options = resData[i].attributes.options;
|
|
|
// obj.selectedIndex = 0;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
@@ -2516,7 +2649,7 @@ onSelect_beep1(e) {
|
|
|
if((resData[i].state && obj.domain && obj.domain=='media_player') && that.checkFuzzyMatch(resData[i])
|
|
|
){
|
|
|
|
|
|
- obj.friendly_name = resData[i].attributes.friendly_name;
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
if(obj.entity_id.includes('teevee') || (obj.entity_id.includes('media_player') && obj.entity_id.includes('tv_dlna_') && obj.friendly_name && obj.friendly_name.includes('电视'))){
|
|
|
obj.volume_level = resData[i].attributes.volume_level;
|
|
|
obj.is_volume_muted = resData[i].attributes.is_volume_muted;
|
|
|
@@ -2558,7 +2691,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='sensor' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
// listSensorTemp.push(obj);
|
|
|
@@ -2569,7 +2702,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='text' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.min = resData[i].attributes.min;
|
|
|
// obj.max = resData[i].attributes.max;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
@@ -2634,6 +2767,9 @@ onSelect_beep1(e) {
|
|
|
listCover:listCoverTemp,
|
|
|
})
|
|
|
// console.log('listMiotMediaPlayerTemp='+JSON.stringify(listMiotMediaPlayerTemp));
|
|
|
+ // console.log('listHumidityTemp='+JSON.stringify(listHumidityTemp));
|
|
|
+ // console.log('listClimateTemp='+JSON.stringify(listClimateTemp));
|
|
|
+ console.log('listSwitchTemp='+JSON.stringify(listSwitchTemp));
|
|
|
},
|
|
|
});
|
|
|
|
|
|
@@ -2806,7 +2942,7 @@ onSelect_beep1(e) {
|
|
|
}
|
|
|
obj.state = (resData[i].state=='unknown'?"未知":resData[i].state);
|
|
|
if(resData[i].attributes && resData[i].attributes.friendly_name){
|
|
|
- obj.friendly_name = resData[i].attributes.friendly_name; //设备名称
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode); //设备名称
|
|
|
|
|
|
if(obj.friendly_name.includes("灯")){
|
|
|
obj.imgSrc = '/static/images/led.png';
|
|
|
@@ -2833,7 +2969,9 @@ onSelect_beep1(e) {
|
|
|
obj.service = 'turn_off';
|
|
|
}
|
|
|
//截取字符串,防止开关设备名称过长
|
|
|
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
+ //是否 是香薰机灯光
|
|
|
+ obj.isAromlight = obj.friendly_name.includes('香薰机灯光')
|
|
|
if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
listSwitchTemp.push(obj)
|
|
|
}
|
|
|
@@ -2843,7 +2981,7 @@ onSelect_beep1(e) {
|
|
|
){
|
|
|
obj.current_position = resData[i].attributes.current_position;
|
|
|
obj.target_position = resData[i].attributes.target_position;
|
|
|
- obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
listCoverTemp.push(obj)
|
|
|
}
|
|
|
@@ -2856,7 +2994,7 @@ onSelect_beep1(e) {
|
|
|
// obj.min = resData[i].attributes.min;
|
|
|
// obj.max = resData[i].attributes.max;
|
|
|
// obj.step = resData[i].attributes.step;
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// if(resData[i].state!='unknown'){
|
|
|
// obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
|
|
|
// }
|
|
|
@@ -2877,7 +3015,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='button' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
// listButtonTemp.push(obj);
|
|
|
// }
|
|
|
@@ -2886,7 +3024,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='select' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.options = resData[i].attributes.options;
|
|
|
// obj.selectedIndex = 0;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
@@ -2966,7 +3104,7 @@ onSelect_beep1(e) {
|
|
|
|
|
|
if((resData[i].state && obj.domain && obj.domain=='media_player') && that.checkFuzzyMatch(resData[i])
|
|
|
){
|
|
|
- obj.friendly_name = resData[i].attributes.friendly_name;
|
|
|
+ obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
if(obj.entity_id.includes('teevee') || (obj.friendly_name && obj.friendly_name.includes('电视'))){
|
|
|
obj.volume_level = resData[i].attributes.volume_level;
|
|
|
obj.is_volume_muted = resData[i].attributes.is_volume_muted;
|
|
|
@@ -3008,7 +3146,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='sensor' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.unit_of_measurement = resData[i].attributes.unit_of_measurement;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
// listSensorTemp.push(obj);
|
|
|
@@ -3019,7 +3157,7 @@ onSelect_beep1(e) {
|
|
|
// (resData[i].state && obj.domain && obj.domain=='text' && resData[i].attributes && resData[i].attributes.parent_entity_id && entityIdList && entityIdList.includes(resData[i].attributes.parent_entity_id)
|
|
|
// )
|
|
|
// ){
|
|
|
- // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name);
|
|
|
+ // obj.friendly_name = that.truncateString(resData[i].attributes.friendly_name,roomcode);
|
|
|
// obj.min = resData[i].attributes.min;
|
|
|
// obj.max = resData[i].attributes.max;
|
|
|
// if(obj.entity_id && obj.state && obj.friendly_name && obj.domain){
|
|
|
@@ -3163,6 +3301,7 @@ onSelect_beep1(e) {
|
|
|
isClickedOnHumidifierDown: false,
|
|
|
isClickedOnClimateAuto: false,
|
|
|
isClickedOnClimateUp: false,
|
|
|
+ isClickedToggleAromlight: false,//香薰机灯光
|
|
|
});
|
|
|
}, 300);
|
|
|
},
|
|
|
@@ -3186,14 +3325,15 @@ onSelect_beep1(e) {
|
|
|
stopTouchMove: function(e) {
|
|
|
return false;
|
|
|
},
|
|
|
- truncateString: function(str) {
|
|
|
- if(!str) return ';'
|
|
|
- if (str.length <= 6) {
|
|
|
+ truncateString: function(str,roomcode) {
|
|
|
+ if(!str) return ''
|
|
|
+ let strR = str.replace(roomcode, '')
|
|
|
+ if (strR.length <= 6) {
|
|
|
// 如果字符串长度小于等于5,直接返回原字符串
|
|
|
- return str;
|
|
|
+ return strR;
|
|
|
} else{
|
|
|
- // 如果字符串长度在6到9之间,返回后五个字符(此时没有前部分可拼接)
|
|
|
- return '..'+str.slice(-6);
|
|
|
+ // 如果字符串长度在6到9之间,返回后6个字符(此时没有前部分可拼接)
|
|
|
+ return strR.slice(-6);
|
|
|
}
|
|
|
},
|
|
|
onLoad(option){
|