1
0
mirror of https://github.com/kenzok8/small-package synced 2025-09-18 18:51:16 +08:00

update-09.24

This commit is contained in:
github-actions[bot]
2021-09-24 23:37:27 +08:00
parent f9585b6e58
commit 16a922f897
1458 changed files with 321464 additions and 7622 deletions

View File

@ -0,0 +1,58 @@
module("luci.controller.homebridge",package.seeall)
function index()
if not nixio.fs.access("/etc/config/homebridge")then
return
end
entry({"admin","services","homebridge"},
alias("admin","services","homebridge","general"),
_("Homebridge"),1).dependent=true
entry({"admin", "services", "homebridge", "general"},
cbi("homebridge/general"),
_("Settings"), 1).leaf=true
entry({"admin", "services", "homebridge", "platforms"},
arcombine(cbi("homebridge/platforms"),cbi("homebridge/platform-config")),
_("Platform Settings"), 2).leaf=true
--entry({"admin", "services", "homebridge", "accessories"},
-- arcombine(cbi("homebridge/accessories"),cbi("homebridge/accessory-config")),
-- _("Accessory Settings"), 3).leaf=true
entry({"admin","services","homebridge","log"},
template("homebridge/logview"),
_("Log"), 4).leaf=true
entry({"admin","services","homebridge","status"},
call("act_status")).leaf=true
entry({"admin","services","homebridge","process_status"},
call("act_process_status")).leaf=true
entry({"admin","services","homebridge","logdata"},
call("act_log")).leaf=true
end
function act_status()
local e={}
e.running=luci.sys.call("pgrep homebridge >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function act_process_status()
local e={}
local section = luci.http.formvalue("section")
luci.sys.call("sleep 3")
e.index = luci.http.formvalue("index")
e.run = luci.sys.call("/usr/share/homebridge/process_status.sh " .. section .. " >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function act_log()
local log_data = {}
log_data = nixio.fs.readfile("/var/log/homebridge.log") or ""
luci.http.prepare_content("application/json")
luci.http.write_json(log_data)
end

View File

@ -0,0 +1,28 @@
m = Map("homebridge", "Homebridge", "Accessories")
-- [[ Devices Manage ]] --
s = m:section(TypedSection, "accessory")
s.anonymous = true
s.addremove = true
s.sorable = true
s.template = "cbi/tblsection"
s.extedit = luci.dispatcher.build_url("admin/services/homebridge/accessories/%s")
function s.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(s.extedit % sid)
return
end
end
o = s:option(DummyValue, "alias", translate("Alias"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or translate("None")
end
o = s:option(DummyValue, "ip", translate("IP"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
return m

View File

@ -0,0 +1,94 @@
local m, s, o
local sid = arg[1]
local yeelight_devices = {
"ColorLEDBulb",
"DeskLamp",
"ColorLedStrip",
"CeilingLamp",
"WhiteBulb"
}
local airpurifier_devices = {
"MiAirPurifier",
"MiAirPurifier2",
"MiAirPurifierPro",
"MiAirPurifier2S"
}
local philips_light_devices = {
"MiPhilipsSmartBulb",
"MiPhilipsTableLamp2",
"MiPhilipsCeilingLamp"
}
m = Map("homebridge", translate("Edit Server"))
m.redirect = luci.dispatcher.build_url("admin/services/homebridge/accessories")
m.sid = sid
if m.uci:get("homebridge", sid) ~= "accessory" then
luci.http.redirect(m.redirect)
return
end
-- [[ Edit Server ]]--
s = m:section(NamedSection, sid, "accessory")
s.anonymous = true
s.addremove = false
o = s:option(ListValue, "platform_type", translate("Platform Type"))
o:value("homebridge-re-yeelight", translate("Yeelight"))
o:value("homebridge-mi-airpurifier", translate("Mi Airpurifier"))
o:value("homebridge-mi-philips-light", translate("Mi Philips Light"))
o.rmempty = false
o = s:option(ListValue, "yeelight_platform", translate("Yeelight"))
for _, v in ipairs(yeelight_devices) do o:value(v) end
o:depends("platform_type", "homebridge-re-yeelight")
o = s:option(ListValue, "air_platform", translate("Airpurifier"))
for _, v in ipairs(airpurifier_devices) do o:value(v) end
o:depends("platform_type", "homebridge-mi-airpurifier")
o = s:option(ListValue, "philips_platform", translate("Philips Light"))
for _, v in ipairs(philips_light_devices) do o:value(v) end
o:depends("platform_type", "homebridge-mi-philips-light")
o = s:option(Value, "alias", translate("Alias"))
o.rmempty = false
o = s:option(Value, "ip", translate("IP"))
o.placeholder = "eg: 192.168.1.1"
o.datatype = "ipaddr"
o.rmempty = false
o = s:option(Value, "token","Token")
o.datatype = "string"
o.rmempty = false
o = s:option(Flag, "updatetimer", translate("Auto Update Device"))
o.default = '1'
o.rmempty = false
o:depends("platform_type", "homebridge-re-yeelight")
o:depends("platform_type", "homebridge-mi-philips-light")
o = s:option(Value, "interval", translate("Interval"))
o.datatype = "uinteger"
o:depends("updatetimer", "1")
o.default = "5"
o.rmempty = false
function o.write(self,section,value)
if(value~=nil)
then
AbstractValue.write(self, section, value)
else
AbstractValue.write(self, section, "5")
end
end
return m

View File

@ -0,0 +1,67 @@
local fs=require"nixio.fs"
local sys=require"luci.sys"
m=Map("homebridge", translate("HomeBridge"), translate("Configuration Homebridge"))
m:append(Template("homebridge/status"))
s=m:section(TypedSection,"homebridge", translate("Global Configuration"))
s.addremove=false
s.anonymous=true
o = s:option(Flag,"enabled",translate("Enable"))
o.rmempty = false
o.default = "1"
button = s:option(Button, "_button","安装")
button.inputtile=translate("exec")
function button.write(self, section, value)
os.execute("/usr/share/homebridge/setup.sh &")
local url = luci.dispatcher.build_url("/admin/services/homebridge/log/")
luci.http.write("<script>location.href='"..url.."';</script>")
end
o = s:option(ListValue, "model", translate("Running Model"))
o:value("main", "Only Main")
o:value("independent", "Only Independent")
o:value("combine", "Main + Independent")
o.rmempty = false
o = s:option(Value, "interface", translate("mdns interface"))
o.datatype = "ip4addr"
o.rmempty = false
o.default = "192.168.1.1"
o = s:option(Value, "name", translate("Homebridge Name"))
o.rmempty = true
o.default = "homebridge"
o:depends("model", "main")
o:depends("model", "combine")
o = s:option(Value, "username", translate("Mac Address"))
o.rmempty = true
o.datatype = "macaddr"
o.default = "CC:22:3D:E3:CE:30"
o:depends("model", "main")
o:depends("model", "combine")
o = s:option(Value, "port", translate("Port"))
o.rmempty = true
o.datatype = "port"
o.default = "51826"
o:depends("model", "main")
o:depends("model", "combine")
o = s:option(Value, "pin", "Pin")
o.rmempty = true
o.datatype = "string"
o.default = "123-45-789"
o:depends("model", "main")
o:depends("model", "combine")
--local apply=luci.http.formvalue("cbi.apply")
--if apply then
-- luci.sys.call("export HOME='/root';/etc/init.d/homebridge restart")
--end
return m

View File

@ -0,0 +1,186 @@
local m, s, o
local sid = arg[1]
local yeelight_devices = {
"ColorLEDBulb",
"DeskLamp",
"ColorLedStrip",
"CeilingLamp",
"WhiteBulb"
}
local philips_light_devices = {
"MiPhilipsSmartBulb",
"MiPhilipsTableLamp2",
"MiPhilipsCeilingLamp"
}
local mi_plug_devices = {
"MiPlugBase",
"MiPlugBaseWithUSB",
"MiIntelligencePinboard",
"MiQingPinboard",
"MiQingPinboardWithUSB"
}
local vacuum_devices = {
"MiRobotVacuum",
"MiRobotVacuum2"
}
m = Map("homebridge", translate("Edit Server"))
m.redirect = luci.dispatcher.build_url("admin/services/homebridge/platforms")
m.sid = sid
if m.uci:get("homebridge", sid) ~= "platform" then
luci.http.redirect(m.redirect)
return
end
-- [[ Edit Platform ]]--
s = m:section(NamedSection, sid, "platform")
s.anonymous = true
s.addremove = false
o = s:option(Flag, "is_independent", translate("Independent"))
o.rmempty = false
o = s:option(Value, "name", translate("Homebridge Name"))
o.default = "homebridge"
o:depends("is_independent", "1")
o = s:option(Value, "username", translate("Mac Address"))
o.datatype = "macaddr"
o.default = "CC:22:3D:E3:CE:30"
o:depends("is_independent", "1")
o = s:option(Value, "port", translate("Port"))
o.datatype = "port"
o.default = "51826"
o:depends("is_independent", "1")
o = s:option(Value, "pin", "Pin")
o.datatype = "string"
o.default = "123-45-789"
o:depends("is_independent", "1")
o = s:option(ListValue, "platform_type", translate("Platform Type"))
o:value("ReYeelightPlatform", translate("Yeelight"))
o:value("MiPhilipsLightPlatform", translate("Mi Philips Light"))
o:value("MiOutletPlatform", translate("Mi Plug"))
o:value("MiRobotVacuumPlatform", translate("Mi Vacuum"))
o.rmempty = false
o = s:option(ListValue, "platform_yeelight", translate("Yeelight"))
for _, v in ipairs(yeelight_devices) do o:value(v) end
o:depends("platform_type", "ReYeelightPlatform")
o = s:option(ListValue, "platform_philips_light", translate("Philips Light"))
for _, v in ipairs(philips_light_devices) do o:value(v) end
o:depends("platform_type", "MiPhilipsLightPlatform")
o = s:option(ListValue, "platform_mi_plug", translate("Mi Plug"))
for _, v in ipairs(mi_plug_devices) do o:value(v) end
o:depends("platform_type", "MiOutletPlatform")
o = s:option(ListValue, "platform_vacuum", translate("Vacuum"))
for _, v in ipairs(vacuum_devices) do o:value(v) end
o:depends("platform_type", "MiRobotVacuumPlatform")
o = s:option(Value, "alias", translate("Alias"))
o.rmempty = false
o = s:option(Value, "ip", translate("IP"))
o.placeholder = "eg: 192.168.1.1"
o.datatype = "ipaddr"
o.rmempty = false
o = s:option(Value, "token","Token")
o.datatype = "string"
o.rmempty = false
-- [ yeelight config ] --
o = s:option(Flag, "updatetimer", translate("Auto Update Device"))
o.default = '1'
o:depends("platform_type", "ReYeelightPlatform")
o:depends("platform_philips_light", "MiPhilipsCeilingLamp")
o.rmempty = false
o = s:option(Value, "interval", translate("Interval"))
o.datatype = "uinteger"
o:depends("updatetimer", "1")
o.default = "5"
-- [ yeelight config ] --
-- [Philips Light Config] --
o = s:option(Value, "main_light_name", translate("Main Light Name"))
o:depends("platform_philips_light", "MiPhilipsTableLamp2")
o.default = "main light"
o.datatype = "string"
o = s:option(Flag, "second_light_disable", translate("Disable Second Light"))
o.default = false
o:depends("platform_philips_light", "MiPhilipsTableLamp2")
o.rmempty = false
o = s:option(Value, "second_light_name", translate("Second Light Name"))
o:depends("platform_philips_light", "MiPhilipsTableLamp2")
o.default = "second light"
o.datatype = "string"
o = s:option(Flag, "eyecare_switch_disable", translate("Disable Eyecare Model"))
o:depends("platform_philips_light", "MiPhilipsTableLamp2")
o.default = "0"
o.rmempty = false
o = s:option(Value, "eyecare_switch_name", translate("Eyecare Model Name"))
o:depends("platform_philips_light", "MiPhilipsTableLamp2")
o.default = "eyecare model"
-- [Philips Light Config] --
-- [ Outlet Config ] --
o = s:option(Flag, "outlet_disable", translate("Disable Plug"))
o.default = "0"
o.rmempty = false
o:depends("platform_type", "MiOutletPlatform")
o = s:option(Flag, "temperature_disable", translate("Disable Temperature"))
o.default = "0"
o:depends("platform_type", "MiOutletPlatform")
o.rmempty = false
o = s:option(Value, "temperature_name", translate("Temperature Name"))
o:depends("platform_type", "MiOutletPlatform")
o.datatype = "string"
o.default = "temperature"
o = s:option(Flag, "switch_LED_disable", translate("Disable LED"))
o:depends("platform_mi_plug", "MiPlugBase")
o:depends("platform_mi_plug", "MiIntelligencePinboard")
o.default = "0"
o.rmempty = false
o = s:option(Value, "switch_LED_name", translate("LED Name"))
o:depends("platform_mi_plug", "MiPlugBase")
o:depends("platform_mi_plug", "MiIntelligencePinboard")
o.datatype = "string"
o.default = "LED"
o = s:option(Flag, "switch_USB_disable", translate("Disable USB"))
o.default = "0"
o:depends("platform_mi_plug", "MiPlugBaseWithUSB")
o.rmempty = false
o = s:option(Value, "switch_USB_name", translate("USB Name"))
o.datatype = "string"
o:depends("platform_mi_plug", "MiPlugBaseWithUSB")
o.default = "USB"
-- [ Outlet Config ] --
return m

View File

@ -0,0 +1,82 @@
local ucursor = require "luci.model.uci".cursor()
local json = require "luci.jsonc"
m=Map("homebridge", "Homebridge", "Platforms configuration")
s = m:section(TypedSection, "platform", "Platforms Configuration")
s.anonymous = true
s.addremove = true
s.sorable = true
s.template = "cbi/tblsection"
s.extedit = luci.dispatcher.build_url("admin/services/homebridge/platforms/%s")
function s.create(...)
local sid = TypedSection.create(...)
if sid then
luci.http.redirect(s.extedit % sid)
return
end
end
o = s:option(DummyValue, "alias", translate("Alias"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "is_independent", "Independent")
function o.cfgvalue(...)
local v = Value.cfgvalue(...)
local ret
if v=="1" then
ret = "Independent"
else
ret = "Main"
end
return ret
end
o = s:option(DummyValue, "username", translate("MAC Address"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "ip", translate("IP"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "port", translate("Port"))
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "pin", "pin")
function o.cfgvalue(...)
return Value.cfgvalue(...) or "?"
end
o = s:option(DummyValue, "port", translate("Process Status"))
o.template="homebridge/process_status"
o.width="10%"
m:append(Template("homebridge/platform_list"))
local ucursor = require "luci.model.uci".cursor()
local model = ucursor:get("homebridge", "@homebridge[0]","model")
--if model == "independent" or model == "combine" then
-- o = s:option(Button, "restart", translate("Restart"))
-- o.inputstyle = "exec"
-- function o.write(self, section)
-- luci.sys.exec("export HOME='/root';/etc/init.d/homebridge restart_on " .. section .. " >> /var/log/homebridge.log")
-- end
-- o = s:option(Button, "stop", translate("Stop"))
-- o.inputstyle = "exec"
-- function o.write(self, section)
-- luci.sys.exec("export HOME=/root; /etc/init.d/homebridge stop_sub_service " .. section .. " >> /var/log/homebridge.log")
-- end
--end
--local apply=luci.http.formvalue("cbi.apply")
--if apply then
-- luci.sys.exec("export HOME=/root;/etc/init.d/homebridge restart")
--end
return m

View File

@ -0,0 +1,46 @@
<% css = [[
#log_text {
padding: 10px;
text-align: left;
height: 500px;
overflow: auto;
}
#log_text pre {
word-break: break-all;
margin: 0;
}
.description {
color: #ffffff;
background-color: #0099ff;
}
]]
%>
<%+header%>
<div class="cbi-map">
<h2 name="content"><%:Homebridge%> - <%:Log Data%></h2>
<fieldset class="cbi-section">
<fieldset class="cbi-section-node">
<div id="log_text"><img src="<%=resource%>/icons/loading.gif" alt="<%:Loading...%>" style="vertical-align:middle" /><%:Collecting data...%></div>
<!-- <div style="text-align:right"><small><%:Refresh every 5 seconds.%></small></div>-->
</fieldset>
</fieldset>
</div>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
var log_id = document.getElementById('log_text');
XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "services", "homebridge", "logdata")%>', null, function(x, data) {
if ( log_id && data ) {
log_id.innerHTML = String.format(
'<pre>%s</pre>',
data || '<%:No log data.%>',
);
} else if ( log_id ) {
log_id.innerHTML = '<strong><%:Error get log data.%></strong>';
}
});
//]]></script>
<%+footer%>

View File

@ -0,0 +1,41 @@
<%#
Copyright 2018-2019 Lienol <lawlienol@gmail.com>
Licensed to the public under the Apache License 2.0.
-%>
<%
local dsp = require "luci.dispatcher"
-%>
<script type="text/javascript">
//<![CDATA[
const processes = document.getElementsByClassName("process-status")
const xhr = (index) => {
return new Promise((res) => {
const process = processes[index];
process.innerHTML = '<font color="#0072c3">connecting...</font>';
XHR.get('<%=dsp.build_url("admin/services/homebridge/process_status")%>', {
index,
section: process.getAttribute("hint")
},
(x, result) => {
let col = '#ff0000';
if (result.run) {
process.innerHTML = '<font color="#249400">ok</font>';
} else {
process.innerHTML = '<font color="#ff0000">fail</font>';
}
res();
});
})
}
let task = -1;
const thread = () => {
task = task + 1
if (processes[task]) {
xhr(task).then(thread);
}
}
for (let i = 0; i < 10; i++) {
thread()
}
</script>

View File

@ -0,0 +1,3 @@
<%+cbi/valueheader%>
<span class="process-status" hint="<%=section%>">wait</span>
<%+cbi/valuefooter%>

View File

@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[homebridge]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('homebridge_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>Homebridge <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>Homebridge <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="homebridge_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,7 @@
config homebridge
option interface '192.168.1.1'
option enabled '1'
option model 'independent'

View File

@ -0,0 +1,230 @@
#!/bin/sh /etc/rc.common
START=98
STOP=15
#USE_PROCD=1
EXTRA_COMMANDS="restart_on start_sub_service stop_sub_service status"
EXTRA_HELP=<<EOF
status Print Homebridge run information
restart_on 'section_name':restart of input section name
start_sub_service 'section_name':start of input section name
stop_sub_service 'section_name':stop of input section name
EOF
BIN="/usr/bin/homebridge"
USER="homebridge"
LOG_FILE="/var/log/homebridge.log"
CONFIG_BASE="/usr/share/homebridge/devices/"
NODE_PATH="/usr/lib/node_modules/"
enabled=0
model=nil
interface=nil
main_config() {
config_get_bool enabled $1 enabled
config_get model $1 model
config_get interface $1 interface
if [[ "$model"="Main" || "$model"="combine" ]];then
local username
local port
local name
local pin
config_get username $1 username
config_get port $1 port
config_get name $1 name
config_get pin $1 pin
mkdir -p "${CONFIG_BASE}/main/"
cat<<-EOF > "${CONFIG_BASE}/main/config.json"
{
"bridge":{
"username":"${username}",
"port":${port},
"name":"${name}",
"pin":"${pin}"
},
"mdns": {
"interface":"${interface}"
},
"accessories":[
],
"platforms":[
EOF
fi
}
restart_on() {
echo "restart on function" >> $LOG_FILE
section="$1"
if [ -n $section ];then
stop_sub_service $section
sleep 1
start_sub_service $section
fi
}
restart(){
echo "restart service now" > $LOG_FILE
stop
start
}
check_plugin(){
local plugin_name
local platform_name
config_get plugin_name $1 platform_type
if [ $plugin_name = "MiPhilipsLightPlatform" ]; then
platform_name="homebridge-mi-philips-light"
fi
if [ $plugin_name = "MiOutletPlatform" ]; then
platform_name="homebridge-mi-outlet"
fi
if [ $plugin_name = "ReYeelightPlatform" ]; then
platform_name="homebridge-re-yeelight"
fi
if [ $plugin_name = "MiRobotVacuumPlatform" ];then
platform_name="homebridge-mi-robot_vacuum"
fi
if [ -d ${NODE_PATH}$platform_name ];then
echo "$platform_name already installed" >> $LOG_FILE
else
npm install -g $platform_name >> $LOG_FILE
fi
}
start(){
echo "start function" > $LOG_FILE
if [ -d $CONFIG_BASE ];then
if ! [[ `node -v` ]];then
echo "Please Install Environment First" >> $LOG_FILE
exit 1
fi
if [ ! `node-gyp --version` ];then
echo "Please Install node-gyp Environment First">> $LOG_FILE
fi
config_load homebridge
config_foreach main_config homebridge
echo "Start Homebridge" >> $LOG_FILE
export HOME=/root
if [ $enabled = "1" ];then
# install npm platform
config_foreach check_plugin platform
# remove invalid folders
lua /usr/share/homebridge/remove_folder.lua >> $LOG_FILE
if [ "$model" = "independent" ];then
echo "Run As Independent Model" >> $LOG_FILE
config_foreach start_sub_service platform
fi
if [ "$model" = "main" ];then
echo "Run As Main Model" >> $LOG_FILE
config_foreach gen_node_config platform
cat<<-EOF >> "${CONFIG_BASE}/main/config.json"
]
}
EOF
pid=$CONFIG_BASE/main/homebridge.pid
nohup ${BIN} -U "${CONFIG_BASE}/main/" >> $LOG_FILE 2>&1 </dev/null &
echo $! > $pid
fi
if [ "$model" == "combine" ];then
echo "Run As Combine Model" >> $LOG_FILE
config_foreach start_sub_service platform
config_foreach gen_node_config platform
cat<<-EOF >> "${CONFIG_BASE}/main/config.json"
]
}
EOF
pid=$CONFIG_BASE/main/homebridge.pid
nohup ${BIN} -U "${CONFIG_BASE}/main/" >> $LOG_FILE 2>&1 </dev/null &
echo $! > $pid
fi
fi
else
echo "Can't create folder ${CONFIG_BASE}" >> $LOG_FILE
fi
}
gen_node_config() {
config_load homebridge
local is_independent
config_get_bool is_independent $1 is_independent
echo $is_independent >> $LOG_FILE
if [ $is_independent = 0 ];then
echo "Run $1 as Main" >> $LOG_FILE
lua /usr/share/homebridge/gen_config.lua $1 main >>$CONFIG_BASE/main/config.json
fi
}
start_sub_service() {
echo "start sub service function" >> $LOG_FILE
config_load homebridge
local is_independent
config_get_bool is_independent $1 is_independent
if [ $is_independent = 1 ];then
echo "Run $1 as independent" >> $LOG_FILE
mkdir -p $CONFIG_BASE/$1
pid=$CONFIG_BASE/$1/homebridge.pid
lua /usr/share/homebridge/gen_config.lua $1 independent >$CONFIG_BASE/$1/config.json
config_path="${CONFIG_BASE}$1/"
nohup ${BIN} -U "${config_path}" >> $LOG_FILE 2>&1 </dev/null &
echo $! > $pid
fi
}
stop() {
echo "stop function" >> $LOG_FILE
killall -9 homebridge >> $LOG_FILE 2>&1
# config_load homebridge
# stop_main_service
# config_foreach stop_sub_service platform
}
stop_main_service() {
echo "stop main service" >> $LOG_FILE
pid=$CONFIG_BASE/main/homebridge.pid
if [ -f $pid ];then
pid_number=$(cat $pid)
if kill -0 $pid_number >/dev/null 2>&1;then
echo "stopping homebridge main" >> $LOG_FILE
kill $pid_number
else
echo "pid not found main" >> $LOG_FILE
fi
else
echo "file not found main" >> $LOG_FILE
fi
}
stop_sub_service() {
echo "stop sub service" >> $LOG_FILE
pid=$CONFIG_BASE/$1/homebridge.pid
if [ -f $pid ];then
pid_number=$(cat $pid)
if kill -0 $pid_number > /dev/null 2>&1;then
echo "stopping homebridge" >> $LOG_FILE
kill $pid_number
else
echo "pid not found" >>$LOG_FILE
fi
else
echo "file not found" >>$LOG_FILE
fi
}
is_running(){
pgrep 'homebridge' > /dev/null 2>&1
}
status(){
echo "status function" >> $LOG_FILE
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
}

View File

@ -0,0 +1,8 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@homebridge[-1]
add ucitrack homebridge
set ucitrack.@homebridge[-1].init=homebridge
commit ucitrack
EOF
exit 0

View File

@ -0,0 +1,115 @@
local ucursor = require "luci.model.uci".cursor()
local json = require "luci.jsonc"
local h_interface = ucursor:get("homebridge", "@homebridge[0]", "interface")
local platform_section=arg[1]
local gen_type=arg[2]
local platform_info = ucursor:get_all("homebridge", platform_section)
function gen(platform_info)
local device_type
if platform_info.platform_type == "ReYeelightPlatform" then
device_type = platform_info.platform_yeelight
end
if platform_info.platform_type == "MiPhilipsLightPlatform" then
device_type = platform_info.platform_philips_light
end
if platform_info.platform_type == "MiOutletPlatform" then
device_type = platform_info.platform_mi_plug
end
if platform_info.platform_type == "MiRobotVacuumPlatform" then
device_type = platform_info.platform_vacuum
end
local platform = {
platform = platform_info.platform_type,
deviceCfgs = {{
type = device_type,
ip = platform_info.ip,
token = platform_info.token
}}
}
deviceCfg = platform.deviceCfgs[1]
if platform_info.platform_type == "ReYeelightPlatform" then
deviceCfg["Name"] = platform_info.alias
deviceCfg["updatetimer"] = (platform_info.updatetimer == "1")
deviceCfg["interval"] = tonumber(platform_info.interval)
end
if platform_info.platform_type == "MiPhilipsLightPlatform" then
if platform_info.platform_philips_light == "MiPhilipsCeilingLamp" or platform_info.platform_philips_light == "MiPhilipsSmartBulb" then
deviceCfg["lightName"] = platform_info.alias
deviceCfg["lightDisable"] = false
end
if platform_info.platform_philips_light == "MiPhilipsCeilingLamp" then
deviceCfg["updatetimer"] = (platform_info.updatetimer == "1")
deviceCfg["interval"] = tonumber(platform_info.interval)
end
if platform_info.platform_philips_light == "MiPhilipsTableLamp2" then
deviceCfg["mainLightName"] = platform_info.main_light_name
deviceCfg["secondLightName"] = platform_info.second_light_name
deviceCfg["secondLightDisable"] = platform_info.second_light_disable == "1"
deviceCfg["eyecareSwitchName"] = platform_info.eyecare_switch_name
deviceCfg["eyecareSwitchDisable"] = platform_info.eyecare_switch_disable == "1"
end
end
if platform_info.platform_type == "MiOutletPlatform" then
deviceCfg["outletName"] = platform_info.alias
deviceCfg["outletDisable"] = platform_info.outlet_disable == "1"
deviceCfg["temperatureName"] = platform_info.temperature_name
deviceCfg["temperatureDisable"] = platform_info.temperature_disable
if platform_info.platform_mi_plug == "MiPlugBase" or platform_info.platform_mi_plug == "MiIntelligencePinboard" then
deviceCfg["switchLEDName"] = platform_info.switch_LED_name
deviceCfg["switchLEDDisable"] = platform_info.switch_LED_disable == "1"
end
if platform_info.platform_mi_plug == "MiPlugBaseWithUSB" then
deviceCfg["switchUSBName"] = platform_info.switch_USB_name
deviceCfg["switchUSBDisable"] = platform_info.switch_USB_disable == "1"
end
end
if platform_info.platform_type == "MiRobotVacuumPlatform" then
deviceCfg["robotVacuumName"] = platform_info.alias
deviceCfg["robotVacuumDisable"] = false
deviceCfg["enablePauseToCharge"] = true
end
return platform
end
local platform
if gen_type == "main" then
platform = gen(platform_info)
end
if gen_type == "independent" then
platform = {
mdns = {
interface = h_interface
},
bridge = {
name=platform_info.name,
username=platform_info.username,
port=tonumber(platform_info.port),
pin=platform_info.pin
},
accessories = {
},
platforms = {{}}
}
platform.platforms[1]=gen(platform_info)
end
print(json.stringify(platform, 1))

View File

@ -0,0 +1,22 @@
#!/bin/sh
CONFIG_BASE="/usr/share/homebridge/devices/"
if [ -z $1 ]
then
echo "Need a section argument"
exit 1
fi
pid_path=$CONFIG_BASE/$1/homebridge.pid
echo $pid_path
if [ -f $pid_path ];then
pid_number=$(cat $pid_path)
if [ -d /proc/$pid_number ];then
exit 0
else
exit 1
fi
else
exit 1
fi

View File

@ -0,0 +1,52 @@
local ucursor = require "luci.model.uci".cursor()
local json = require "luci.jsonc"
local path = "/usr/share/homebridge/devices/"
local configs = ucursor:get_all("homebridge")
function addToSet(set, key)
set[key] = true
end
function removeFromSet(set, key)
set[key] = nil
end
function setContains(set, key)
return set[key] ~= nil
end
local config_array={}
addToSet(config_array, "main")
for key, value in pairs(configs) do
addToSet(config_array, key)
end
--print(json.stringify(config_array, 1))
files = io.popen("ls " .. path):lines()
for file in files do
if not setContains(config_array, file) then
print("remove directory or file:" .. file)
os.execute("rm -rf " .. path ..file)
end
end

View File

@ -0,0 +1,115 @@
#!/bin/sh
LOG_FILE=/var/log/homebridge.log
function check_node_environment(){
echo "Begin Checking Node environment-----------------------">>$LOG_FILE
if node -v > /dev/null 2>&1
then
echo "node already installed" >> $LOG_FILE
else
echo "try install node" >> $LOG_FILE
if opkg install node >> $LOG_FILE 2>&1
then
echo "node environment install success" >> $LOG_FILE
else
echo "node install failed" >> $LOG_FILE
return 1
fi
fi
if npm --version > /dev/null 2>&1
then
echo "node-npm environment install success" >> $LOG_FILE
else
echo "try install node-npm" >> $LOG_FILE
if opkg install node-npm >> $LOG_FILE 2>&1
then
echo "node-npm environment install success"
else
echo "node-npm install failed" >> $LOG_FILE
return 1
fi
fi
if node-gyp --version > /dev/null 2>&1
then
echo "node-gyp already installed" >> $LOG_FILE
return 0
else
echo "try install node-gyp" >> $LOG_FILE
if npm install -g node-gyp >> $LOG_FILE 2>&1
then
echo "install node-gyp success" >> $LOG_FILE
return 0
else
echo "install node-gyp failed" >> $LOG_FILE
return 1
fi
fi
}
function check_miio(){
echo "Begin Checking Miio-----------------------">>$LOG_FILE
if [ -d "/usr/lib/node_modules/miio" ]; then
echo "miio already installed" >> $LOG_FILE
return 0
else
echo "try install miio" >> $LOG_FILE
if npm install -g miio@0.14.1 2 >> $LOG_FILE 2>&1
then
echo "miio install complete" >> $LOG_FILE
return 0
else
echo "miio install failed" >> $LOG_FILE
return 1
fi
fi
return 1
}
function check_homebridge(){
echo "Homebridge check ----------------------------">>$LOG_FILE
if [ -d "/usr/lib/node_modules/homebridge" ]; then
echo "homebridge already installed" >> $LOG_FILE
return 0
else
echo "try install homebridge" >> $LOG_FILE
if npm install -g homebridge >> $LOG_FILE 2>&1
then
echo "homebridge install success">>$LOG_FILE
return 0
else
echo "homebridge install failed">>$LOG_FILE
return 1
fi
fi
return 1
}
function update_opkg(){
echo "OPKG update -------------------------" >> $LOG_FILE
if opkg update >> $LOG_FILE 2>&1
then
echo "OPKG update success" >> $LOG_FILE
else
echo "OPKG update failed" >> $LOG_FILE
fi
echo "OPKG update finished ----------------" >> $LOG_FILE
}
function main(){
echo "Begin Checking Environment--------------" > $LOG_FILE
update_opkg
if check_node_environment
then
if check_miio
then
if check_homebridge
then
echo "End Checking Environment ---------------------------">>$LOG_FILE
fi
fi
fi
}
main