Skip to content

Commit

Permalink
Cascade On/Off for IKEA Trådfri remote
Browse files Browse the repository at this point in the history
Send set remote group `action.on` to true (false) when local group
`state.all_on` is false (true).
  • Loading branch information
ebaauw authored and manup committed Jan 4, 2018
1 parent 13ad9dc commit 6a32394
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 21 additions & 6 deletions gateway.cpp
Expand Up @@ -5,6 +5,7 @@
#include <QTime>
#include <deconz.h>
#include "gateway.h"
#include "group.h"
#include "json.h"


Expand Down Expand Up @@ -62,6 +63,7 @@ class GatewayPrivate
void checkConfigResponse(const QByteArray &data);
void checkGroupsResponse(const QByteArray &data);

DeRestPluginPrivate *parent;
Gateway::State state;
bool pairingEnabled;
bool needSaveDatabase;
Expand All @@ -81,11 +83,12 @@ class GatewayPrivate
std::vector<Command> commands;
};

Gateway::Gateway(QObject *parent) :
Gateway::Gateway(DeRestPluginPrivate *parent) :
QObject(parent),
d_ptr(new GatewayPrivate)
{
Q_D(Gateway);
d->parent = parent;
d->pings = 0;
d->state = Gateway::StateOffline;
d->pairingEnabled = false;
Expand Down Expand Up @@ -298,7 +301,7 @@ void Gateway::handleGroupCommand(const deCONZ::ApsDataIndication &ind, deCONZ::Z
break;
case SCENE_COMMAND_IKEA_MOVE_CT:
cmd.mode = zclFrame.payload().at(0);
cmd.transitionTime = 2540.0 / 83; // observed value for DimUp/Down
cmd.transitionTime = 2540.0 / 83; // value for DimUp/Down
break;
case SCENE_COMMAND_IKEA_STEP_CT:
// payload U8 mode
Expand All @@ -325,8 +328,20 @@ void Gateway::handleGroupCommand(const deCONZ::ApsDataIndication &ind, deCONZ::Z
break;
case ONOFF_COMMAND_TOGGLE:
// IKEA Trådfri Remote On/Off
// cmd.param.level = getGroupForId(cg.local).isOn() ? 0x00 : 0x01;
break;
{
::Group *group;
QVariantMap map;
QVariantMap state;

group = d->parent->getGroupForId(cg.local);
if (group && d->parent->groupToMap(group , map))
{
state = map["state"].toMap();
cmd.param.level = state["all_on"].toBool() ? 0x00 : 0x01;
break;
}
}
continue;
case ONOFF_COMMAND_OFF_WITH_EFFECT:
// Hue dimmer switch Off
cmd.transitionTime = 4;
Expand Down Expand Up @@ -686,8 +701,8 @@ void GatewayPrivate::handleEventStateConnected(GW_Event event)
map[QLatin1String("on")] = true;
break;
case ONOFF_COMMAND_TOGGLE:
// ok = true;
// map[QLatin1String("on")] = cmd.param.level == 0x00;
ok = true;
map[QLatin1String("on")] = cmd.param.level == 0x01;
break;
default:
break;
Expand Down
4 changes: 3 additions & 1 deletion gateway.h
Expand Up @@ -4,6 +4,8 @@
#include <QObject>
#include <QHostAddress>
#include <QNetworkReply>
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"

namespace deCONZ {
class ApsDataIndication;
Expand Down Expand Up @@ -37,7 +39,7 @@ class Gateway : public QObject
StateConnected
};

explicit Gateway(QObject *parent = 0);
explicit Gateway(DeRestPluginPrivate *parent = 0);
~Gateway();

const QString &name() const;
Expand Down

0 comments on commit 6a32394

Please sign in to comment.