use of org.openhab.binding.lgtv.internal.LgtvStatusUpdateEvent in project openhab1-addons by openhab.
the class LgTvMessageReader method doPost.
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
BufferedReader rd = null;
StringBuilder sb = null;
res.setContentType("text/plain");
res.setStatus(200);
OutputStream responseBody = res.getOutputStream();
LgtvStatusUpdateEvent event = new LgtvStatusUpdateEvent(this);
rd = new BufferedReader(new InputStreamReader(req.getInputStream()));
sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line + '\n');
}
String remoteaddr = req.getRemoteAddr();
int start = remoteaddr.indexOf(":");
String t;
if (start > -1) {
t = remoteaddr.substring(0, start);
} else {
t = remoteaddr;
}
remoteaddr = t;
start = remoteaddr.indexOf("/");
if (start > -1) {
t = remoteaddr.substring(start + 1, remoteaddr.length());
} else {
t = remoteaddr;
}
remoteaddr = t;
logger.debug("httphandler called from remoteaddr=" + remoteaddr + " result=" + sb.toString());
LgTvEventChannelChanged myevent = new LgTvEventChannelChanged();
String result = "";
try {
result = myevent.readevent(sb.toString());
} catch (JAXBException e) {
logger.error("error in httphandler", e);
}
logger.debug("eventresult=" + result);
LgTvEventChannelChanged.envelope envel = myevent.getenvel();
String eventname = envel.getchannel().geteventname();
if (eventname.equals("ChannelChanged")) {
String name = "CHANNEL_CURRENTNAME=" + envel.getchannel().getchname();
String number = "CHANNEL_CURRENTNUMBER=" + envel.getchannel().getmajor();
String set = "CHANNEL_SET=" + envel.getchannel().getmajor();
sendtohandlers(event, remoteaddr, name);
sendtohandlers(event, remoteaddr, number);
sendtohandlers(event, remoteaddr, set);
} else if (eventname.equals("byebye")) {
sendtohandlers(event, remoteaddr, "BYEBYE_SEEN=1");
} else {
logger.debug("warning - unhandled event");
}
responseBody.close();
}
use of org.openhab.binding.lgtv.internal.LgtvStatusUpdateEvent in project openhab1-addons by openhab.
the class LgTvInteractor method handlevolchangeeasy.
public String handlevolchangeeasy(String sval) {
String res = "#notpaired";
int val;
int pos = sval.indexOf(".");
if (pos > 0) {
String ns = sval.substring(0, pos);
val = Integer.parseInt(ns);
} else {
val = Integer.parseInt(sval);
}
if (ispaired()) {
res = getvolumeinfo(0);
String currentvol = quickfind(res, "level");
int cvol = Integer.parseInt(currentvol);
int todo = val - cvol;
logger.debug("currentvolume=" + cvol + " newvolume=" + val + " todo=" + todo);
LgTvCommand volup = LgTvCommand.valueOf("VOLUME_UP");
LgTvCommand voldown = LgTvCommand.valueOf("VOLUME_DOWN");
String usecommand = todo > 0 ? volup.getLgSendCommand() : voldown.getLgSendCommand();
if (todo < 0) {
todo = todo * -1;
}
for (int i = 0; i < todo; i++) {
handlekeyinput(usecommand);
}
logger.debug("currentvolume=" + cvol + " newvolume=" + val + " todo=" + todo + " usecommand=" + usecommand);
if (todo != 0) {
res = getvolumeinfo(0);
currentvol = quickfind(res, "level");
if (associatedreader != null) {
String volume = "VOLUME_CURRENT=" + val;
LgtvStatusUpdateEvent event = new LgtvStatusUpdateEvent(this);
associatedreader.sendtohandlers(event, lgip, volume);
}
}
}
return new String(res);
}
use of org.openhab.binding.lgtv.internal.LgtvStatusUpdateEvent in project openhab1-addons by openhab.
the class LgTvInteractor method setconnectionstatus.
public void setconnectionstatus(lgtvconnectionstatus s) {
if (s != connectionstatus) {
logger.info("lgtv connectionstatus of ip=" + lgip + " changed from " + connectionstatus + " to " + s);
connectionstatus = s;
if (associatedreader != null) {
String status = "CONNECTION_STATUS=" + ((s == lgtvconnectionstatus.CS_PAIRED) ? "1" : "0");
LgtvStatusUpdateEvent event = new LgtvStatusUpdateEvent(this);
associatedreader.sendtohandlers(event, lgip, status);
if (s == lgtvconnectionstatus.CS_NOTCONNECTED) {
associatedreader.sendtohandlers(event, lgip, status);
String name = "CHANNEL_CURRENTNAME=0";
String number = "CHANNEL_CURRENTNUMBER=0";
String vol = "VOLUME_CURRENT=0";
associatedreader.sendtohandlers(event, lgip, name);
associatedreader.sendtohandlers(event, lgip, number);
associatedreader.sendtohandlers(event, lgip, vol);
}
}
}
}
Aggregations