Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1366 from gerrieg/homematic
Browse files Browse the repository at this point in the history
[Homematic] Fixed CCU firmware version extraction.
  • Loading branch information
teichsta committed Aug 27, 2014
2 parents 1c91a83 + 50c6f7e commit 741f115
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2010-2014, openHAB.org and others.
*
* 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.homematic.internal.communicator.client;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.openhab.binding.homematic.internal.communicator.client.interfaces.RpcClient;
import org.openhab.binding.homematic.internal.model.HmInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract class with common methods for all RpcClients.
*
* @author Gerhard Riegler
* @since 1.6.0
*/
public abstract class BaseRpcClient implements RpcClient {
private final static Logger logger = LoggerFactory.getLogger(BaseRpcClient.class);

/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.debug("Starting {}", this.getClass().getSimpleName());
}

/**
* {@inheritDoc}
*/
@Override
public ServerId getServerId(HmInterface hmInterface) throws HomematicClientException {
ServerId serverId = null;
try {
serverId = new ServerId(getVersion(hmInterface));
} catch (Exception ex) {
// ignore, the getVersion method may not be implemented (CCU1)
}

if (serverId == null || !serverId.isHomegear()) {
Map<String, String> deviceDescription = getDeviceDescription(hmInterface, "BidCoS-RF");
String firmwareVersion = null;
if (deviceDescription != null) {
firmwareVersion = deviceDescription.get("FIRMWARE");
}
serverId = new ServerId(StringUtils.defaultIfBlank(firmwareVersion, "unknown"));
}

return serverId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.openhab.binding.homematic.internal.binrpc.BinRpcResponse;
import org.openhab.binding.homematic.internal.common.HomematicConfig;
import org.openhab.binding.homematic.internal.common.HomematicContext;
import org.openhab.binding.homematic.internal.communicator.client.interfaces.RpcClient;
import org.openhab.binding.homematic.internal.model.HmInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,20 +28,12 @@
* @author Gerhard Riegler
* @since 1.5.0
*/
public class BinRpcClient implements RpcClient {
public class BinRpcClient extends BaseRpcClient {
private final static Logger logger = LoggerFactory.getLogger(BinRpcClient.class);
private final static boolean TRACE_ENABLED = logger.isTraceEnabled();

private HomematicConfig config = HomematicContext.getInstance().getConfig();

/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.debug("Starting {}", this.getClass().getSimpleName());
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -93,11 +84,26 @@ public Object[] getAllValues(HmInterface hmInterface) throws HomematicClientExce
/**
* {@inheritDoc}
*/
@Override
public ServerId getServerId(HmInterface hmInterface) throws HomematicClientException {
public String getVersion(HmInterface hmInterface) throws HomematicClientException {
BinRpcRequest request = new BinRpcRequest("getVersion");
Object[] result = sendMessage(hmInterface, request);
return new ServerId(result[0].toString());
return result[0].toString();
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getDeviceDescription(HmInterface hmInterface, String address)
throws HomematicClientException {
BinRpcRequest request = new BinRpcRequest("getDeviceDescription");
request.addArg(address);
Object[] result = sendMessage(hmInterface, request);
if (result != null && result.length > 0 && result[0] instanceof Map) {
return (Map<String, String>) result[0];
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

import org.openhab.binding.homematic.internal.common.HomematicConfig;
import org.openhab.binding.homematic.internal.common.HomematicContext;
import org.openhab.binding.homematic.internal.communicator.client.interfaces.RpcClient;
import org.openhab.binding.homematic.internal.model.HmInterface;
import org.openhab.binding.homematic.internal.xmlrpc.XmlRpcConnection;
import org.openhab.binding.homematic.internal.xmlrpc.XmlRpcConnectionCuxd;
import org.openhab.binding.homematic.internal.xmlrpc.XmlRpcConnectionRF;
import org.openhab.binding.homematic.internal.xmlrpc.XmlRpcConnectionWired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Client implementation for sending messages via XML-RPC to the CCU. It's a
Expand All @@ -30,20 +27,11 @@
* @author Gerhard Riegler
* @since 1.5.0
*/
public class XmlRpcClient implements RpcClient {
private final static Logger logger = LoggerFactory.getLogger(XmlRpcClient.class);
public class XmlRpcClient extends BaseRpcClient {
private HomematicConfig config = HomematicContext.getInstance().getConfig();

private Map<HmInterface, XmlRpcConnection> xmlRpcConnections = new HashMap<HmInterface, XmlRpcConnection>(2);

/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.debug("Starting {}", this.getClass().getSimpleName());
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -98,14 +86,26 @@ public Object[] getAllValues(HmInterface hmInterface) throws HomematicClientExce
/**
* {@inheritDoc}
*/
@Override
public ServerId getServerId(HmInterface hmInterface) throws HomematicClientException {
public String getVersion(HmInterface hmInterface) throws HomematicClientException {
Object result = getConnection(hmInterface).getVersion();
if (result instanceof String) {
return new ServerId((String) result);
return (String) result;
}
throw new HomematicClientException("getVersion returns unknown result type: "
+ (result == null ? "null" : result.getClass()));
return null;
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getDeviceDescription(HmInterface hmInterface, String address)
throws HomematicClientException {
Object result = getConnection(hmInterface).getDeviceDescription(address);
if (result instanceof Map) {
return (Map<String, String>) result;
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ public void setDatapointValue(HmInterface hmInterface, String address, String da
* Returns the id of the Homematic server.
*/
public ServerId getServerId(HmInterface hmInterface) throws HomematicClientException;

/**
* Returns the version of the Homematic server.
*/
public String getVersion(HmInterface hmInterface) throws HomematicClientException;

/**
* Returns the description of a Homematic device.
*/
public Map<String, String> getDeviceDescription(HmInterface hmInterface, String address)
throws HomematicClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ public Object getVersion() {
return executeRPC("getVersion", null);
}

public Object getDeviceDescription(String address) {
log.debug("called getDeviceDescription");
Object[] params = { address };
return executeRPC("getDeviceDescription", params);
}

public void executeProgram(String programName) {
log.debug("called executeProgram");
Object[] params = { programName };
Expand Down

0 comments on commit 741f115

Please sign in to comment.