Skip to content

Commit

Permalink
- Implemented: Notifications, custom notification text helpers $name …
Browse files Browse the repository at this point in the history
…and $value
  • Loading branch information
gizmocuz committed Oct 23, 2016
1 parent 23b9d25 commit 8e0dfd5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -20,6 +20,7 @@ Version 3.xxxx (October xx 2016)
- Implemented: MySensors, S_POWER, Apparent power: volt-ampere (VA)
- Implemented: MySensors, S_POWER, Ratio of real power to apparent power: floating point value in the range [-1,..,1]
- Implemented: Nefit Easy, User Mode (as switch, On=Clock, Off=Manual), Flow Temperature, Hot Water Mode
- Implemented: Notifications, custom notification text helpers $name and $value
- Implemented: OpenZWave, Aeotec ZWave+ USB Controller, Enable/Disable blinking mode (@Schmart, Thanks for the magic codes!)
- Implemented: OpenZWave, Node table, now also displays Manufacturer, Product ID and Product Type
- Implemented: OpenZWave, When including Thermostat Setpoints, the zwave Label will be used as Name by default
Expand Down
86 changes: 69 additions & 17 deletions notifications/NotificationHelper.cpp
Expand Up @@ -146,6 +146,14 @@ void CNotificationHelper::LoadConfig()
_log.Log(LOG_NORM, std::string(logline.str()).c_str());
}

std::string CNotificationHelper::ParseCustomMessage(const std::string &cMessage, const std::string &sName, const std::string &sValue)
{
std::string ret = cMessage;
stdreplace(ret, "$name", sName);
stdreplace(ret, "$value", sValue);
return ret;
}

bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
const unsigned long long Idx,
const std::string &devicename,
Expand All @@ -159,6 +167,7 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
return false;

char szTmp[600];
std::string notValue;

std::string szExtraData = "|Name=" + devicename + "|";

Expand Down Expand Up @@ -221,10 +230,15 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
msg = szTmp;
}
}
if (bSendNotification)
{
sprintf(szTmp, "%.1f", temp);
notValue = szTmp;
}
}
else if ((ntype == signhum) && (bHaveHumidity))
{
//humanity
//humidity
szExtraData += "Image=moisture48|";
if (bWhenIsGreater)
{
Expand All @@ -244,11 +258,16 @@ bool CNotificationHelper::CheckAndHandleTempHumidityNotification(
msg = szTmp;
}
}
if (bSendNotification)
{
sprintf(szTmp, "%d", humidity);
notValue = szTmp;
}
}
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand All @@ -269,6 +288,7 @@ bool CNotificationHelper::CheckAndHandleDewPointNotification(

char szTmp[600];
std::string szExtraData = "|Name=" + devicename + "|Image=temp-0-5|";
std::string notValue;

time_t atime = mytime(NULL);

Expand Down Expand Up @@ -301,12 +321,14 @@ bool CNotificationHelper::CheckAndHandleDewPointNotification(
bSendNotification = true;
sprintf(szTmp, "%s Dew Point reached (%.1f degrees)", devicename.c_str(), temp);
msg = szTmp;
sprintf(szTmp, "%.1f", temp);
notValue = szTmp;
}
}
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand Down Expand Up @@ -336,6 +358,7 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
atime -= m_NotificationSensorInterval;

std::string msg = "";
std::string notValue;

std::string signamp1 = Notification_Type_Desc(NTYPE_AMPERE1, 1);
std::string signamp2 = Notification_Type_Desc(NTYPE_AMPERE2, 2);
Expand Down Expand Up @@ -377,6 +400,11 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
msg = szTmp;
}
}
if (bSendNotification)
{
sprintf(szTmp, "%.1f", Ampere1);
notValue = szTmp;
}
}
else if (ntype == signamp2)
{
Expand All @@ -399,6 +427,11 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
msg = szTmp;
}
}
if (bSendNotification)
{
sprintf(szTmp, "%.1f", Ampere2);
notValue = szTmp;
}
}
else if (ntype == signamp3)
{
Expand All @@ -421,11 +454,16 @@ bool CNotificationHelper::CheckAndHandleAmpere123Notification(
msg = szTmp;
}
}
if (bSendNotification)
{
sprintf(szTmp, "%.1f", Ampere3);
notValue = szTmp;
}
}
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand All @@ -448,7 +486,9 @@ bool CNotificationHelper::CheckAndHandleNotification(
result = m_sql.safe_query("SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%llu)", Idx);
if (result.size() == 0)
return false;

std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|";
std::string notValue;

time_t atime = mytime(NULL);

Expand All @@ -470,7 +510,7 @@ bool CNotificationHelper::CheckAndHandleNotification(
{
std::string msg = message;
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand Down Expand Up @@ -567,7 +607,12 @@ bool CNotificationHelper::CheckAndHandleNotification(
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
{
std::string notValue;
sprintf(szTmp, "%.1f", mvalue);
notValue = szTmp;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
}
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand Down Expand Up @@ -613,6 +658,7 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
std::string atype = splitresults[0];

bool bSendNotification = false;
std::string notValue;

if (atype == ltype)
{
Expand All @@ -624,46 +670,46 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
switch (switchtype)
{
case STYPE_Doorbell:
msg += " pressed";
notValue = "pressed";
break;
case STYPE_Contact:
msg += " Open";
notValue = "Open";
szExtraData += "Image=contact48_open|";
break;
case STYPE_DoorLock:
msg += " Open";
notValue = "Open";
szExtraData += "Image=door48open|";
break;
case STYPE_Motion:
msg += " movement detected";
notValue = "movement detected";
break;
case STYPE_SMOKEDETECTOR:
msg += " ALARM/FIRE !";
notValue = "ALARM/FIRE !";
break;
default:
msg += " >> ON";
notValue = ">> ON";
break;
}

}
else {
szExtraData += "Status=Off|";
switch (switchtype)
{
case STYPE_DoorLock:
case STYPE_Contact:
msg += " Closed";
notValue = "Closed";
break;
default:
msg += " >> OFF";
notValue = ">> OFF";
break;
}
}
msg += " " + notValue;
}
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand Down Expand Up @@ -710,6 +756,7 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
std::string atype = splitresults[0];

bool bSendNotification = false;
std::string notValue;

if (atype == ltype)
{
Expand All @@ -736,22 +783,27 @@ bool CNotificationHelper::CheckAndHandleSwitchNotification(
std::vector<std::string> splitresults;
StringSplit(levelNames, "|", splitresults);
msg += " >> " + splitresults[(llevel / 10)];
notValue = ">> " + splitresults[(llevel / 10)];
}
else
{
msg += " >> LEVEL " + sLevel;
notValue = ">> LEVEL " + sLevel;
}
}
}
else
{
bSendNotification = true;
szExtraData += "Status=Off|";
msg += " >> OFF";
notValue = ">> OFF";
}
}
if (bSendNotification)
{
if (!itt->CustomMessage.empty())
msg = itt->CustomMessage;
msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue);
SendMessageEx(itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true);
TouchNotification(itt->ID);
}
Expand Down
1 change: 1 addition & 0 deletions notifications/NotificationHelper.h
Expand Up @@ -93,6 +93,7 @@ class CNotificationHelper {
void SetConfigValue(const std::string &key, const std::string &value);
private:
void AddNotifier(CNotificationBase *notifier);
std::string ParseCustomMessage(const std::string &cMessage, const std::string &sName, const std::string &sValue);
boost::mutex m_mutex;
std::map<unsigned long long, std::vector<_tNotification> > m_notifications;
int m_NotificationSensorInterval;
Expand Down

0 comments on commit 8e0dfd5

Please sign in to comment.