Skip to content

Instantly share code, notes, and snippets.

@jannis6023
Created July 8, 2021 15:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jannis6023/3b7bc97d5693119f1506701c6df0791d to your computer and use it in GitHub Desktop.
Save jannis6023/3b7bc97d5693119f1506701c6df0791d to your computer and use it in GitHub Desktop.
var request = require('request');
var parser = require('fast-xml-parser');
let ip = "10.1.1.119";
// Dieser Demo-Aufruf schaltet das Display an / schaltet den Fernseher an und blendet eine OSD-Nachricht ein.
auth(ip, function (clientID){
injectRCKey(ip, clientID, "12")
executeSoapAction(ip, clientID, "SetActionField", "<?xml version=\"1.0\"?>\n" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"urn:loewe.de:RemoteTV:Tablet\">\n" +
" <env:Body >\n" +
" <m:SetActionField>\n" +
" <m:fcid>81</m:fcid>\n" +
" <m:ClientId>" + clientID + "</m:ClientId>\n" +
" <m:InputText>Test OSD-Message nachdem der TV eingeschaltet wurde.</m:InputText>\n" +
" <m:IsTimeout>0</m:IsTimeout>\n" +
" <m:Selectors>\n" +
" <m:Selector>OK</m:Selector>\n" +
" </m:Selectors>\n" +
" </m:SetActionField>\n" +
" </env:Body>\n" +
"</env:Envelope>", function (){
console.log("Message sent.")
})
})
function auth(ip, executeCallback){
var options = {
'method': 'POST',
'url': 'http://' + ip + ':905/loewe_tablet_0001',
'headers': {
'SOAPACTION': 'RequestAccess',
'Content-Type': 'application/xml'
},
body: '<?xml version="1.0"?>\n<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ltv="urn:loewe.de:RemoteTV:Tablet">\n <env:Body >\n <ltv:RequestAccess>\n <fcid>81</fcid>\n <ClientId>?</ClientId>\n <DeviceType>HomebridgeServer</DeviceType>\n <DeviceName>loewetv-plugin</DeviceName>\n <DeviceUUID>50:ertertrertre:retertrte:10:0B:B7</DeviceUUID>\n <RequesterName>HomeBridgePlugin</RequesterName>\n </ltv:RequestAccess>\n </env:Body>\n</env:Envelope>'
};
request(options, function (error, response) {
if (error) throw new Error(error);
var jsonObj = parser.parse(response.body);
let accessStatus = jsonObj["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["m:RequestAccessResponse"]["m:AccessStatus"];
let clientID = jsonObj["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["m:RequestAccessResponse"]["m:ClientId"];
if(accessStatus === "Pending"){
var options = {
'method': 'POST',
'url': 'http://' + ip + ':905/loewe_tablet_0001',
'headers': {
'SOAPACTION': 'RequestAccess',
'Content-Type': 'application/xml'
},
body: '<?xml version="1.0"?>\n<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ltv="urn:loewe.de:RemoteTV:Tablet">\n <env:Body >\n <ltv:RequestAccess>\n <fcid>81</fcid>\n <ClientId>?</ClientId>\n <DeviceType>Homebridge</DeviceType>\n <DeviceName>loewetv-plugin</DeviceName>\n <DeviceUUID>50:ertertrertre:94:10:0B:B7</DeviceUUID>\n <RequesterName>HomeBridgePlugin</RequesterName>\n </ltv:RequestAccess>\n </env:Body>\n</env:Envelope>'
};
request(options, function (error, response) {
if (error) throw new Error(error);
var jsonObj = parser.parse(response.body);
let accessStatus = jsonObj["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["m:RequestAccessResponse"]["m:AccessStatus"];
let clientID = jsonObj["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["m:RequestAccessResponse"]["m:ClientId"];
if(accessStatus === "Accepted"){
executeCallback(clientID);
}
});
}else{
executeCallback(clientID)
}
});
}
function executeSoapAction(ip, clientID, soapAction, body, callBack){
var request = require('request');
var options = {
'method': 'POST',
'url': 'http://' + ip + ':905/loewe_tablet_0001',
'headers': {
'SOAPACTION': soapAction,
'Content-Type': 'application/xml'
},
body: body
};
request(options, function (error, response) {
if (error) throw new Error(error);
callBack(response.body)
});
}
function injectRCKey(ip, clientID, rcKey){
executeSoapAction(ip, clientID, "InjectRCKey", "<?xml version=\"1.0\"?>\n" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:m=\"urn:loewe.de:RemoteTV:Tablet\">\n" +
" <env:Body >\n" +
" <m:InjectRCKey>\n" +
" <m:fcid>81</m:fcid>\n" +
" <m:ClientId>LRemoteClient-0-1625754531</m:ClientId>\n" +
" <m:InputEventSequence>\n" +
" <m:RCKeyEvent alphabet=\"l2700\" mode=\"press\" value=\"" + rcKey + "\"/>\n" +
" <m:RCKeyEvent alphabet=\"l2700\" mode=\"release\" value=\"" + rcKey + "\"/>\n" +
" </m:InputEventSequence>\n" +
" </m:InjectRCKey>\n" +
" </env:Body>\n" +
"</env:Envelope>", function (){
console.log("Successfully sent.")
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment