toggle, reset and homekite route add.
This commit is contained in:
@@ -4,7 +4,13 @@ const Library = require("../library");
|
|||||||
const DeviceModel = require("../models/device.model");
|
const DeviceModel = require("../models/device.model");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
|
||||||
const set = async (token, device_id, remote_name, remote_type, operating_type) => {
|
const set = async (
|
||||||
|
token,
|
||||||
|
device_id,
|
||||||
|
remote_name,
|
||||||
|
remote_type,
|
||||||
|
operating_type
|
||||||
|
) => {
|
||||||
if (token === configs.verifyToken) {
|
if (token === configs.verifyToken) {
|
||||||
try {
|
try {
|
||||||
const deviceExist = await DeviceModel.findOne({
|
const deviceExist = await DeviceModel.findOne({
|
||||||
@@ -12,23 +18,33 @@ const set = async (token, device_id, remote_name, remote_type, operating_type) =
|
|||||||
});
|
});
|
||||||
if (deviceExist) {
|
if (deviceExist) {
|
||||||
const hostname = deviceExist.device_ip_address;
|
const hostname = deviceExist.device_ip_address;
|
||||||
const path = "on";
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://" + hostname + "/" + path + "?token=" + configs.verifyToken
|
"http://" +
|
||||||
|
hostname +
|
||||||
|
"/" +
|
||||||
|
operating_type +
|
||||||
|
"?token=" +
|
||||||
|
configs.verifyToken
|
||||||
);
|
);
|
||||||
|
|
||||||
const isOpen = await response.text();
|
const isOpen = await response.text();
|
||||||
if (isOpen) {
|
console.log(isOpen);
|
||||||
Library.saveDeviceLog(device_id, remote_name, remote_type, operating_type);
|
if (isOpen === "true") {
|
||||||
return "Cihaz açıldı"
|
Library.saveDeviceLog(
|
||||||
|
device_id,
|
||||||
|
remote_name,
|
||||||
|
remote_type,
|
||||||
|
operating_type
|
||||||
|
);
|
||||||
|
return operating_type + " işlemi başarılı!";
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Cihaz açılırken hata oluştu!");
|
throw new Error("Client message: " + isOpen);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Cihaz bulunamadı!");
|
throw new Error("Cihaz bulunamadı!");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error("Mongodb: " + error.message + " (set.controller)");
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Hatalı token (set.controller)");
|
throw new Error("Hatalı token (set.controller)");
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ services:
|
|||||||
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
|
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
|
||||||
- ME_CONFIG_MONGODB_ADMINPASSWORD=anTis**664+..12895
|
- ME_CONFIG_MONGODB_ADMINPASSWORD=anTis**664+..12895
|
||||||
- ME_CONFIG_MONGODB_SERVER=mongo
|
- ME_CONFIG_MONGODB_SERVER=mongo
|
||||||
- ME_CONFIG_MONGODB_AUTH_USERNAME=wisecolt
|
- ME_CONFIG_BASICAUTH_USERNAME=wisecolt
|
||||||
- ME_CONFIG_MONGODB_AUTH_PASSWORD=XQrvBF7y&Jnc&JoAPCVG6%!kM3UY*d*VweW
|
- ME_CONFIG_BASICAUTH_PASSWORD=4noQ93GMQ6hJPgFdovjW
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- "8081:8081"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const deviceLogSchema = new Schema({
|
|||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
operating_type:{
|
operating_type:{
|
||||||
type: String // On/Off - Homekit Reset - Reset
|
type: String // Toggle - Homekit Reset - Reset
|
||||||
},
|
},
|
||||||
log_time: {
|
log_time: {
|
||||||
type: Date
|
type: Date
|
||||||
|
|||||||
Reference in New Issue
Block a user