Skip to content

Commit

Permalink
Merge pull request #6120 from manup/master
Browse files Browse the repository at this point in the history
Fix PUT sensor/state/localtime
  • Loading branch information
manup committed Jun 7, 2022
2 parents 18110e2 + beda9a6 commit e115f68
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rest_sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,20 @@ int DeRestPluginPrivate::changeSensorState(const ApiRequest &req, ApiResponse &r
}
}
}

if (rid.suffix == RStateLocaltime)
{
// convert to QDateTime here, otherwise the time string would be interpretet
// as UTC in item->setValue()
const auto str = val.toString();
auto fmt = str.contains('.') ? QLatin1String("yyyy-MM-ddTHH:mm:ss.zzz")
: QLatin1String("yyyy-MM-ddTHH:mm:ss");
auto dt = QDateTime::fromString(str, fmt);

if (dt.isValid()) { val = dt; }
else { val = ""; } // mark invalid but keep processing to return proper error
}

if (item->setValue(val))
{
rspItemState[QString("/sensors/%1/state/%2").arg(id).arg(pi.key())] = val;
Expand Down

0 comments on commit e115f68

Please sign in to comment.