toggle, reset and homekite route add.

This commit is contained in:
2024-03-08 09:23:29 +03:00
parent 494675c567
commit b3b2516def
3 changed files with 28 additions and 12 deletions

View File

@@ -4,7 +4,13 @@ const Library = require("../library");
const DeviceModel = require("../models/device.model");
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) {
try {
const deviceExist = await DeviceModel.findOne({
@@ -12,23 +18,33 @@ const set = async (token, device_id, remote_name, remote_type, operating_type) =
});
if (deviceExist) {
const hostname = deviceExist.device_ip_address;
const path = "on";
const response = await fetch(
"http://" + hostname + "/" + path + "?token=" + configs.verifyToken
"http://" +
hostname +
"/" +
operating_type +
"?token=" +
configs.verifyToken
);
const isOpen = await response.text();
if (isOpen) {
Library.saveDeviceLog(device_id, remote_name, remote_type, operating_type);
return "Cihaz açıldı"
console.log(isOpen);
if (isOpen === "true") {
Library.saveDeviceLog(
device_id,
remote_name,
remote_type,
operating_type
);
return operating_type + " işlemi başarılı!";
} else {
throw new Error("Cihaz açılırken hata oluştu!");
throw new Error("Client message: " + isOpen);
}
} else {
throw new Error("Cihaz bulunamadı!");
}
} catch (error) {
throw new Error("Mongodb: " + error.message + " (set.controller)");
throw new Error(error.message);
}
} else {
throw new Error("Hatalı token (set.controller)");

View File

@@ -42,8 +42,8 @@ services:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=anTis**664+..12895
- ME_CONFIG_MONGODB_SERVER=mongo
- ME_CONFIG_MONGODB_AUTH_USERNAME=wisecolt
- ME_CONFIG_MONGODB_AUTH_PASSWORD=XQrvBF7y&Jnc&JoAPCVG6%!kM3UY*d*VweW
- ME_CONFIG_BASICAUTH_USERNAME=wisecolt
- ME_CONFIG_BASICAUTH_PASSWORD=4noQ93GMQ6hJPgFdovjW
ports:
- "8081:8081"
depends_on:

View File

@@ -10,7 +10,7 @@ const deviceLogSchema = new Schema({
type: String
},
operating_type:{
type: String // On/Off - Homekit Reset - Reset
type: String // Toggle - Homekit Reset - Reset
},
log_time: {
type: Date