Commit b414f6ec authored by luz's avatar luz

hue: added --hueapiurl command line parameter to specifiy a fixed hue API URL...

hue: added --hueapiurl command line parameter to specifiy a fixed hue API URL (such as deCONZ) instead of discovering bridge via UPnP/SSDP
parent a8823a80
......@@ -154,6 +154,8 @@ void HueApiOperation::abortOperation(ErrorPtr aError)
#pragma mark - BridgeFinder
// string used in place of UUID when using fixed hue API URL
#define PSEUDO_UUID_FOR_FIXED_API "fixed_api_base_URL"
class p44::BridgeFinder : public P44Obj
{
......@@ -203,8 +205,20 @@ public:
userName = nonNullCStr(aUserName);
deviceType = nonNullCStr(aDeviceType);
authTimeWindow = aAuthTimeWindow;
keepAlive = BridgeFinderPtr(this);
bridgeDetector->startSearch(boost::bind(&BridgeFinder::bridgeDiscoveryHandler, this, _1, _2), NULL);
if (hueComm.fixedBaseURL.empty()) {
// actually search for a bridge
keepAlive = BridgeFinderPtr(this);
bridgeDetector->startSearch(boost::bind(&BridgeFinder::bridgeDiscoveryHandler, this, _1, _2), NULL);
}
else {
// we have a pre-known base URL for the hue API, use this without any find operation
keepAlive = BridgeFinderPtr(this);
// - just put it in as the only auth candidate
authCandidates.clear();
authCandidates[PSEUDO_UUID_FOR_FIXED_API] = hueComm.fixedBaseURL;
startedAuth = MainLoop::now();
attemptPairingWithCandidates();
}
};
......@@ -214,8 +228,18 @@ public:
callback = aFindHandler;
uuid = hueComm.uuid;;
userName = hueComm.userName;
keepAlive = BridgeFinderPtr(this);
bridgeDetector->startSearch(boost::bind(&BridgeFinder::bridgeRefindHandler, this, _1, _2), uuid.c_str());
if (hueComm.fixedBaseURL.empty() && uuid!=PSEUDO_UUID_FOR_FIXED_API) {
// actually search for bridge
keepAlive = BridgeFinderPtr(this);
bridgeDetector->startSearch(boost::bind(&BridgeFinder::bridgeRefindHandler, this, _1, _2), uuid.c_str());
}
else {
// we have a pre-known base URL for the hue API, use this without any find operation
hueComm.baseURL = hueComm.fixedBaseURL; // use it
hueComm.apiReady = true; // can use API now
DBGLOG(LOG_DEBUG, "Using fixed API URL to access hue Bridge %s: %s\n", hueComm.uuid.c_str(), hueComm.baseURL.c_str());
callback(ErrorPtr()); // success
}
};
......
......@@ -133,6 +133,7 @@ namespace p44 {
/// @name settings
/// @{
string fixedBaseURL; ///< fixed hue API base URL, bypasses any SSDP searches
string uuid; ///< the UUID for searching the hue bridge via SSDP
string userName; ///< the user name
......
......@@ -49,6 +49,13 @@ bool HueDeviceContainer::getDeviceIcon(string &aIcon, bool aWithData, const char
}
string HueDeviceContainer::getExtraInfo()
{
return string_format("hue api: %s", hueComm.baseURL.c_str());
}
#pragma mark - DB and initialisation
// Version history
......
......@@ -54,7 +54,6 @@ namespace p44 {
typedef DeviceClassContainer inherited;
friend class HueDevice;
HueComm hueComm;
HuePersistence db;
CompletedCB collectedHandler;
......@@ -68,8 +67,11 @@ namespace p44 {
/// @}
public:
HueDeviceContainer(int aInstanceNumber, DeviceContainer *aDeviceContainerP, int aTag);
HueComm hueComm;
void initialize(CompletedCB aCompletedCB, bool aFactoryReset);
virtual const char *deviceClassIdentifier() const;
......@@ -103,6 +105,10 @@ namespace p44 {
/// @return true if there is an icon, false if not
virtual bool getDeviceIcon(string &aIcon, bool aWithData, const char *aResolutionPrefix);
/// Get extra info (plan44 specific) to describe the addressable in more detail
/// @return string, single line extra info describing aspects of the device not visible elsewhere
virtual string getExtraInfo();
private:
void refindResultHandler(ErrorPtr aError);
......
......@@ -248,6 +248,7 @@ public:
{ 'b', "enocean", true, "bridge;EnOcean modem serial port device or proxy host[:port]" },
{ 0, "enoceanreset", true, "pinspec;set I/O pin connected to EnOcean module reset" },
{ 0, "huelights", false, "enable support for hue LED lamps (via hue bridge)" },
{ 0, "hueapiurl", true, "hue API url; use hue bridge API at specific location (disables UPnP/SSDP search)" },
#if !DISABLE_OLA
{ 0, "ola", false, "enable support for OLA (Open Lighting Architecture) server" },
#endif
......@@ -454,6 +455,10 @@ public:
// - Add hue support
if (getOption("huelights")) {
HueDeviceContainerPtr hueDeviceContainer = HueDeviceContainerPtr(new HueDeviceContainer(1, p44VdcHost.get(), 3)); // Tag 3 = hue
string apiurl;
if (getStringOption("hueapiurl", apiurl)) {
hueDeviceContainer->hueComm.fixedBaseURL = apiurl;
}
hueDeviceContainer->addClassToDeviceContainer();
}
#if !DISABLE_OLA
......
......@@ -48,7 +48,8 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ED6D7BDA1716B63A005DED18"
......@@ -104,7 +105,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--dali 192.168.59.221 --daliportidle 10 --dalitxadj 16"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--dali localhost:2101 --dalitxadj 16"
......@@ -124,6 +125,10 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--huelights"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--hueapiurl http://192.168.1.148:80/api"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
......@@ -190,7 +195,8 @@
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ED6D7BDA1716B63A005DED18"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment