Skip to content

Commit

Permalink
Cascade Level commands.
Browse files Browse the repository at this point in the history
Simple _Move to level_ for setting `action.bri` and _Step_ and _Stop_
as issued by Hue dimmer switch.
  • Loading branch information
ebaauw committed Dec 21, 2017
1 parent 0739f26 commit fd2b5d5
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#define ONOFF_COMMAND_TOGGLE 0x02
#define ONOFF_COMMAND_OFF_WITH_EFFECT 0x040
#define ONOFF_COMMAND_ON_WITH_TIMED_OFF 0x42
#define LEVEL_COMMAND_MOVE_TO_LEVEL 0x00
#define LEVEL_COMMAND_STEP 0x02
#define LEVEL_COMMAND_STOP 0x03


#define PHILIPS_MAC_PREFIX QLatin1String("001788")

Expand All @@ -35,6 +39,7 @@ class Command
quint8 sceneId;
quint8 level;
} param;
quint8 mode;
quint16 transitionTime;
};

Expand Down Expand Up @@ -280,9 +285,22 @@ void Gateway::handleGroupCommand(const deCONZ::ApsDataIndication &ind, deCONZ::Z
else if (ind.clusterId() == 0x0006) // onoff
{
}
// else if (ind.clusterId() == 0x0008) // level
// {
// }
else if (ind.clusterId() == 0x0008) // level
{
if (zclFrame.commandId() == LEVEL_COMMAND_MOVE_TO_LEVEL)
{
// payload U8 level, U16 transition time
cmd.param.level = zclFrame.payload().at(0);
// cmd.transitionTime = zclFrame.payload().at(1);
}
else if (zclFrame.commandId() == LEVEL_COMMAND_STEP)
{
// payload U8 mode, U8 step size, U16 transitionTime
cmd.mode = zclFrame.payload().at(0);
cmd.param.level = zclFrame.payload().at(1);
// cmd.transitionTime = zclFrame.payload().at(2);
}
}
else
{
continue;
Expand Down Expand Up @@ -564,6 +582,32 @@ void GatewayPrivate::handleEventStateConnected(GW_Event event)
map[QLatin1String("on")] = false;
}
}
else if (cmd.clusterId == 0x0008)
{
if (cmd.commandId == LEVEL_COMMAND_MOVE_TO_LEVEL)
{
url.sprintf("http://%s:%u/api/%s/groups/%u/action",
qPrintable(address.toString()), port, qPrintable(apikey), cmd.groupId);
double level = cmd.param.level;
map[QLatin1String("bri")] = level;
// map[QLatin1String("transitiontime")] = cmd.transitionTime;
}
else if (cmd.commandId == LEVEL_COMMAND_STEP)
{
url.sprintf("http://%s:%u/api/%s/groups/%u/action",
qPrintable(address.toString()), port, qPrintable(apikey), cmd.groupId);
double level = cmd.param.level * (cmd.mode ? -1 : 1);
map[QLatin1String("bri_inc")] = level;
// map[QLatin1String("transitiontime")] = cmd.transitionTime;
}
else if (cmd.commandId == LEVEL_COMMAND_STOP)
{
url.sprintf("http://%s:%u/api/%s/groups/%u/action",
qPrintable(address.toString()), port, qPrintable(apikey), cmd.groupId);
map[QLatin1String("bri_inc")] = 0.0;
// map[QLatin1String("transitiontime")] = cmd.transitionTime;
}
}

commands.pop_back();

Expand Down

0 comments on commit fd2b5d5

Please sign in to comment.