Sorry it took so long to post back.
I’ve called the binding esmadja
If you aren’t familiar with the development environment this isn’t going to be too useful.
Unfortunately I won’t be able to help too much.
You should look at the following tutorial. You should be able to figure out where each file belongs.
This is the EsmadjaBindingContstants.java file
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.esmadja;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
/**
* The {@link EsmadjaBinding} class defines common constants, which are
* used across the whole binding.
*
* @author Eric Smadja - Initial contribution
*/
public class EsmadjaBindingConstants {
public static final String BINDING_ID = "esmadja";
// List of all Thing Type UIDs
public final static ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "sample");
// List of all Channel ids
public final static String ZONE_1_POWER = "zone1#power";
public final static String ZONE_1_VOLUME = "zone1#volume";
public final static String ZONE_1_MUTE = "zone1#mute";
public final static String ZONE_1_INPUT = "zone1#input";
public final static String ZONE_2_POWER = "zone2#power";
public final static String ZONE_2_VOLUME = "zone2#volume";
public final static String ZONE_2_MUTE = "zone2#mute";
public final static String ZONE_2_INPUT = "zone2#input";
// List of input ID
public final static int INPUT_SAT = 1;
public final static int INPUT_GAME = 2;
public final static int INPUT_AUX = 3;
public final static int INPUT_DVD = 15;
public final static int INPUT_BLURAY = 16;
public final static int INPUT_TV_AUDIO = 34;
public final static int INPUT_CD = 35;
public final static int INPUT_FMTUNER = 36;
public final static int INPUT_MEDIA_PLAYER = 39;
public final static int INPUT_IRADIO = 40;
public final static int INPUT_USB_IPOD = 41;
public final static int INPUT_NETWORK = 43;
}
This is the EsmadjaHandler.java file
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.esmadja.handler;
import static org.openhab.binding.esmadja.EsmadjaBindingConstants.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.lang.StringUtils;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link EsmadjaHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Eric Smadja - Initial contribution
*/
public class EsmadjaHandler extends BaseThingHandler {
private Logger logger = LoggerFactory.getLogger(EsmadjaHandler.class);
public static final String HOST = "ipAddress";
public EsmadjaHandler(Thing thing) {
super(thing);
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (String.valueOf(command) != "REFRESH") {
HttpURLConnectionExample http = new HttpURLConnectionExample();
int retry = 3;
String status = "";
switch (channelUID.getId()) {
case ZONE_1_POWER:
logger.debug("Sending Denon Zone 1 Power command.");
try {
while ((retry > 0) & !status.equals(String.valueOf(command))) {
;
retry--;
String httpAddress = (String) getConfig().get(HOST);
String setState = "PutZone_OnOff%2F" + command;
http.sendGet("http://" + httpAddress + "/MainZone/index.put.asp?cmd0=" + setState);
String response = http
.sendGet("http://" + httpAddress + "/goform/formMainZone_MainZoneXml.xml");
status = StringUtils.substringBetween(response.toString(), "<ZonePower><value>",
"</value></ZonePower>");
logger.debug("Input status: " + status);
}
logger.debug("Try count was " + String.valueOf(3 - retry));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case ZONE_1_VOLUME:
logger.debug("Sending Denon Zone 1 Volume command.");
try {
String httpAddress = (String) getConfig().get(HOST);
String volume = command + "";
Integer ivolume = Integer.valueOf(volume);
if (ivolume.equals(0)) {
volume = "--";
} else {
volume = String.valueOf(ivolume - 18);
}
String setState = "PutMasterVolumeSet%2F" + volume;
http.sendGet("http://" + httpAddress + "/MainZone/index.put.asp?cmd0=" + setState);
String response = http
.sendGet("http://" + httpAddress + "/goform/formMainZone_MainZoneXml.xml");
String stringParser = StringUtils.substringBetween(response.toString(), "<MasterVolume><value>",
"</value></MasterVolume>");
logger.debug("Input status: " + stringParser);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case ZONE_1_MUTE:
logger.debug("Sending Denon Zone 1 mute command.");
try {
while ((retry > 0) & status.equals(command)) {
;
}
{
retry++;
}
String httpAddress = (String) getConfig().get(HOST);
String setState = "PutVolumeMute%2F" + command;
http.sendGet("http://" + httpAddress + "/MainZone/index.put.asp?cmd0=" + setState);
String response = http
.sendGet("http://" + httpAddress + "/goform/formMainZone_MainZoneXml.xml");
String stringParser = StringUtils.substringBetween(response.toString(), "<Mute><value>",
"</value></Mute>");
logger.debug("Input status: " + stringParser);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case ZONE_1_INPUT:
logger.debug("Sending Denon Zone 1 Input command.");
try {
while ((retry > 0) & status.equals(command)) {
;
}
{
retry++;
}
String httpAddress = (String) getConfig().get(HOST);
String inputValue = "";
String execcommand = command + "";
Integer excom = Integer.valueOf(command + "");
if (execcommand != "REFRESH") {
switch (excom) {
case INPUT_SAT:
inputValue = "SAT%2FCBL";
break;
case INPUT_GAME:
inputValue = "GAME";
break;
case INPUT_AUX:
inputValue = "AUX";
break;
case INPUT_DVD:
inputValue = "DVD";
break;
case INPUT_BLURAY:
inputValue = "BD";
break;
case INPUT_TV_AUDIO:
inputValue = "TV";
break;
case INPUT_CD:
inputValue = "CD";
break;
case INPUT_FMTUNER:
inputValue = "TUNER";
break;
case INPUT_MEDIA_PLAYER:
inputValue = "MPLAY";
break;
case INPUT_IRADIO:
inputValue = "IRADIO";
break;
case INPUT_USB_IPOD:
inputValue = "USB%2FIPOD";
break;
case INPUT_NETWORK:
inputValue = "NETHOME";
break;
}
}
String setState = "PutZone_InputFunction%2F" + inputValue;
http.sendGet("http://" + httpAddress + "/MainZone/index.put.asp?cmd0=" + setState);
String response = http
.sendGet("http://" + httpAddress + "/goform/formMainZone_MainZoneXml.xml");
String stringParser = StringUtils.substringBetween(response.toString(),
"<InputFuncSelect><value>", "</value></InputFuncSelect>");
logger.debug("Input status: " + stringParser);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case ZONE_2_POWER:
// TODO: handle command
logger.debug("Denon Zone 2 command.");
// Note: if communication with thing fails for some reason,
// indicate that by setting the status with detail information
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
// "Could not control device at IP address x.x.x.x");
break;
}
}
}
@Override
public void initialize() {
// TODO: Initialize the thing. If done set status to ONLINE to indicate proper working.
// Long running initialization should be done asynchronously in background.
HttpURLConnectionExample http = new HttpURLConnectionExample();
if (getConfig().get(HOST) != null) {
try {
String httpAddress = (String) getConfig().get(HOST);
String response = http.sendGet("http://" + httpAddress + "/goform/Deviceinfo.xml");
String stringParser = StringUtils.substringBetween(response.toString(), "<FriendlyName><value>",
"</value></FriendlyName>");
updateStatus(ThingStatus.ONLINE);
logger.debug("Denon ipAddress is configured at " + httpAddress);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
updateStatus(ThingStatus.OFFLINE);
logger.debug("Denon ipAddress is incorrect or could not connect.");
}
} else {
updateStatus(ThingStatus.OFFLINE);
logger.debug("Denon ipAddress not configured.");
}
// Note: When initialization can NOT be done set the status with more details for further
// analysis. See also class ThingStatusDetail for all available status details.
// Add a description to give user information to understand why thing does not work
// as expected. E.g.
// updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
// "Can not access device as username and/or password are invalid");
}
public class HttpURLConnectionExample {
private final String USER_AGENT = "Mozilla/5.0";
// HTTP GET request
private String sendGet(String url) throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
// add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
logger.debug("Sending 'GET' request to URL : " + url);
logger.debug("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
logger.debug(response.toString());
return response.toString();
}
}
}
This is the EsmadjaHandlerFactory.java file
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.esmadja.internal;
import static org.openhab.binding.esmadja.EsmadjaBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import org.openhab.binding.esmadja.handler.EsmadjaHandler;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
/**
* The {@link EsmadjaHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Eric Smadja - Initial contribution
*/
public class EsmadjaHandlerFactory extends BaseThingHandlerFactory {
private final static Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_SAMPLE);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}
@Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_SAMPLE)) {
return new EsmadjaHandler(thing);
}
return null;
}
}
This is the binding.xml file
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="esmadja"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="http://eclipse.org/smarthome/schemas/binding/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/binding/v1.0.0 http://eclipse.org/smarthome/schemas/binding-1.0.0.xsd">
<name>Denon Binding</name>
<description>Netowrk Denon binding</description>
<author>Eric Smadja</author>
</binding:binding>
This is the thing-types.xml file
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="esmadja"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd">
<!-- Sample Thing Type -->
<thing-type id="sample">
<label>Denon AVR</label>
<description>Network enabled Denon AV Receivers</description>
<channel-groups>
<channel-group typeId="zone1Controls" id="zone1" />
<channel-group typeId="zone2Controls" id="zone2" />
</channel-groups>
<config-description>
<parameter name="ipAddress" type="text" required="true">
<label>Network Address</label>
<description>The IP or host name of the Denon Receiver</description>
<context>network-address</context>
</parameter>
</config-description>
</thing-type>
<channel-group-type id="zone1Controls">
<label>Zone 1</label>
<channels>
<channel id="power" typeId="power" />
<channel id="input" typeId="input" />
<channel id="volume" typeId="volume" />
<channel id="mute" typeId="mute" />
</channels>
</channel-group-type>
<channel-group-type id="zone2Controls">
<label>Zone 2</label>
<channels>
<channel id="power" typeId="power" />
<channel id="input" typeId="input" />
<channel id="volume" typeId="volume" />
<channel id="mute" typeId="mute" />
</channels>
</channel-group-type>
<!-- Commands -->
<channel-type id="power">
<item-type>Switch</item-type>
<label>Power</label>
<description>Power on/off your device</description>
</channel-type>
<channel-type id="input">
<item-type>Number</item-type>
<label>Input Source</label>
<description>Select the input source of the AVR</description>
<state>
<options>
<option value="00">DVR/VCR</option>
<option value="01">SATELLITE/CABLE</option>
<option value="02">GAME</option>
<option value="03">AUX</option>
<option value="04">GAME</option>
<option value="15">DVD</option>
<option value="16">BLURAY</option>
<option value="34">TV AUDIO</option>
<option value="35">CD</option>
<option value="36">TUNER FM</option>
<option value="39">MEDIA PLAYER</option>
<option value="40">INTERET RADIO</option>
<option value="41">USB</option>
<option value="43">NETWORK</option>
</options>
</state>
</channel-type>
<channel-type id="mute">
<item-type>Switch</item-type>
<label>Mute</label>
<description>Mute/unmute your device</description>
</channel-type>
<channel-type id="volume">
<item-type>Dimmer</item-type>
<label>Volume</label>
<description>Volume of your device</description>
<state min="0" max="100" step="1" pattern="%d %%">
</state>
</channel-type>
</thing:thing-descriptions>