mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Add hyperion-remote instance cmd (#596)
* Add hyperion-remote instance cmd - Adds a new command to hyperion-remote that allows the selection of a instance by name - Fixed broken umlauts - Fixed wrong text placement inside icon tags * Add warning if selected instance is not found
This commit is contained in:
parent
034f821d46
commit
d190e6f294
@ -65,13 +65,13 @@ $(document).ready( function() {
|
||||
var startBtnColor = inst[key].running ? "success" : "danger";
|
||||
var startBtnIcon = inst[key].running ? "stop" : "play";
|
||||
var startBtnText = inst[key].running ? $.i18n('general_btn_stop') : $.i18n('general_btn_start');
|
||||
var renameBtn = '<button id="instren_'+inst[key].instance+'" type="button" class="btn btn-primary"><i class="fa fa-pencil"> '+$.i18n('general_btn_rename')+'</i></button>';
|
||||
var renameBtn = '<button id="instren_'+inst[key].instance+'" type="button" class="btn btn-primary"><i class="fa fa-fw fa-pencil"></i>'+$.i18n('general_btn_rename')+'</button>';
|
||||
var startBtn = ""
|
||||
var delBtn = "";
|
||||
if(inst[key].instance > 0)
|
||||
{
|
||||
delBtn = '<button id="instdel_'+inst[key].instance+'" type="button" class="btn btn-warning"><i class="fa fa-remove"> '+$.i18n('general_btn_delete')+'</i></button>';
|
||||
startBtn = '<button id="inst_'+inst[key].instance+'" type="button" class="btn btn-'+startBtnColor+'"><i class="fa fa-'+startBtnIcon+'"> '+startBtnText+'</i></button>';
|
||||
delBtn = '<button id="instdel_'+inst[key].instance+'" type="button" class="btn btn-warning"><i class="fa fa-fw fa-remove"></i>'+$.i18n('general_btn_delete')+'</button>';
|
||||
startBtn = '<button id="inst_'+inst[key].instance+'" type="button" class="btn btn-'+startBtnColor+'"><i class="fa fa-fw fa-'+startBtnIcon+'"></i>'+startBtnText+'</button>';
|
||||
}
|
||||
$('.itbody').append(createTableRow([inst[key].friendly_name, renameBtn, startBtn, delBtn], false, true));
|
||||
$('#instren_'+inst[key].instance).off().on('click', handleInstanceRename);
|
||||
|
@ -159,7 +159,7 @@ function sendToHyperion(command, subcommand, msg)
|
||||
else
|
||||
msg = "";
|
||||
|
||||
window.websocket.send(encode_utf8('{"command":"'+command+'", "tan":'+window.wsTan+subcommand+msg+'}'));
|
||||
window.websocket.send('{"command":"'+command+'", "tan":'+window.wsTan+subcommand+msg+'}');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
@ -199,7 +199,14 @@ void JsonConnection::deleteEffect(const QString &effectName)
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
QString JsonConnection::getServerInfo()
|
||||
QString JsonConnection::getServerInfoString()
|
||||
{
|
||||
QJsonDocument doc(getServerInfo());
|
||||
QString info(doc.toJson(QJsonDocument::Indented));
|
||||
return info;
|
||||
}
|
||||
|
||||
QJsonObject JsonConnection::getServerInfo()
|
||||
{
|
||||
qDebug() << "Get server info";
|
||||
|
||||
@ -218,12 +225,10 @@ QString JsonConnection::getServerInfo()
|
||||
throw std::runtime_error("No info available in result");
|
||||
}
|
||||
|
||||
QJsonDocument doc(reply["info"].toObject());
|
||||
QString info(doc.toJson(QJsonDocument::Indented));
|
||||
return info;
|
||||
return reply["info"].toObject();
|
||||
}
|
||||
|
||||
return QString();
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
QString JsonConnection::getSysInfo()
|
||||
@ -562,6 +567,21 @@ void JsonConnection::setToken(const QString &token)
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
void JsonConnection::setInstance(const int &instance)
|
||||
{
|
||||
// create command
|
||||
QJsonObject command;
|
||||
command["command"] = QString("instance");
|
||||
command["subcommand"] = QString("switchTo");
|
||||
command["instance"] = instance;
|
||||
|
||||
// send command message
|
||||
QJsonObject reply = sendMessage(command);
|
||||
|
||||
// parse reply message
|
||||
parseReply(reply);
|
||||
}
|
||||
|
||||
QJsonObject JsonConnection::sendMessage(const QJsonObject & message)
|
||||
{
|
||||
// serialize message
|
||||
|
@ -73,11 +73,18 @@ public:
|
||||
void deleteEffect(const QString &effectName);
|
||||
|
||||
///
|
||||
/// Retrieve a list of all occupied priority channels
|
||||
/// Retrieve entire serverinfo as String
|
||||
///
|
||||
/// @return String with the server info
|
||||
///
|
||||
QString getServerInfo();
|
||||
QString getServerInfoString();
|
||||
|
||||
///
|
||||
/// Get the entire serverinfo
|
||||
///
|
||||
/// @return QJsonObject with the server info
|
||||
///
|
||||
QJsonObject getServerInfo();
|
||||
|
||||
///
|
||||
/// Retrieve system info
|
||||
@ -174,6 +181,12 @@ public:
|
||||
// set the specified authorization token
|
||||
void setToken(const QString &token);
|
||||
|
||||
///
|
||||
/// Send a json message with a specific instance id
|
||||
/// @param instance The instance id
|
||||
///
|
||||
void setInstance(const int &instance);
|
||||
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -39,6 +39,20 @@ void showHelp(Option & option){
|
||||
qWarning() << qPrintable(QString("\t%1\t%2\t%3").arg(shortOption, longOption, option.description()));
|
||||
}
|
||||
|
||||
int getInstaneIdbyName(const QJsonObject & reply, const QString name){
|
||||
if(reply.contains("instance")){
|
||||
QJsonArray list = reply.value("instance").toArray();
|
||||
|
||||
for (const auto & entry : list) {
|
||||
const QJsonObject obj = entry.toObject();
|
||||
if(obj["friendly_name"] == name && obj["running"].toBool())
|
||||
return obj["instance"].toInt();
|
||||
}
|
||||
}
|
||||
std::cout << "Can't find a running instance with name '" << name.toStdString()<< "' at this Hyperion server, will use first instance" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
setenv("AVAHI_COMPAT_NOWARN", "1", 1);
|
||||
@ -64,6 +78,7 @@ int main(int argc, char * argv[])
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Option & argAddress = parser.add<Option> ('a', "address" , "Set the address of the hyperion server [default: %1]", "localhost:19444");
|
||||
Option & argToken = parser.add<Option> ('t', "token " , "If authorization tokens are required, this token is used");
|
||||
Option & argInstance = parser.add<Option> ('I', "instance" , "Select a specific target instance by name for your command. By befault it uses always the first instance");
|
||||
IntOption & argPriority = parser.add<IntOption> ('p', "priority" , "Used to the provided priority channel (suggested 2-99) [default: %1]", "50");
|
||||
IntOption & argDuration = parser.add<IntOption> ('d', "duration" , "Specify how long the leds should be switched on in milliseconds [default: infinity]");
|
||||
ColorsOption & argColor = parser.add<ColorsOption> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex getColors or a color name. The color may be repeated multiple time like: RRGGBBRRGGBB)");
|
||||
@ -165,6 +180,14 @@ int main(int argc, char * argv[])
|
||||
if (parser.isSet(argToken))
|
||||
connection.setToken(argToken.value(parser));
|
||||
|
||||
// If a specific Hyperion instance is given, set it
|
||||
if (parser.isSet(argInstance))
|
||||
{
|
||||
QJsonObject reply = connection.getServerInfo();
|
||||
int val = getInstaneIdbyName(reply, argInstance.value(parser));
|
||||
connection.setInstance(val);
|
||||
}
|
||||
|
||||
// now execute the given command
|
||||
if (parser.isSet(argColor))
|
||||
{
|
||||
@ -189,7 +212,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
else if (parser.isSet(argServerInfo))
|
||||
{
|
||||
std::cout << "Server info:\n" << connection.getServerInfo().toStdString() << std::endl;
|
||||
std::cout << "Server info:\n" << connection.getServerInfoString().toStdString() << std::endl;
|
||||
}
|
||||
else if (parser.isSet(argSysInfo))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user