Commit bcf063e258d11727f0bc00ecc26e56b9254d49f8

  • avatar
  • Sergey 'Jin' Bostandzhyan <jin @deve…per.digitalstrom.org>
  • Sun Aug 08 16:24:09 CEST 2010
Made sure JSON API returns local time values
core/web/handler/jsonhelper.cpp
(11 / 2)
  
2626
2727#include "core/web/json.h"
2828
29#include "core/datetools.h"
30
2931#include "core/model/devicereference.h"
3032#include "core/model/device.h"
3133#include "core/model/set.h"
3838namespace dss {
3939
4040 boost::shared_ptr<JSONObject> toJSON(const DeviceReference& _device) {
41 DateTime tmp_date;
42
4143 boost::shared_ptr<JSONObject> result(new JSONObject());
4244 result->addProperty("id", _device.getDSID().toString());
4345 result->addProperty("isSwitch", _device.hasSwitch());
5050 result->addProperty("circuitID", _device.getDevice().getDSMeterID());
5151 result->addProperty("busID", _device.getDevice().getShortAddress());
5252 result->addProperty("isPresent", _device.getDevice().isPresent());
53 result->addProperty("lastDiscovered", _device.getDevice().getLastDiscovered());
54 result->addProperty("firstSeen", _device.getDevice().getFirstSeen());
53
54 tmp_date = _device.getDevice().getLastDiscovered();
55 result->addProperty("lastDiscovered", tmp_date.fromUTC());
56
57 tmp_date = _device.getDevice().getFirstSeen();
58 result->addProperty("firstSeen", tmp_date.fromUTC());
59
5560 result->addProperty("on", _device.getDevice().isOn());
5661 result->addProperty("locked", _device.getDevice().getIsLockedInDSM());
5762 return result;
core/web/handler/meteringrequesthandler.cpp
(4 / 2)
  
155155 {
156156 boost::shared_ptr<JSONArrayBase> valuePair(new JSONArrayBase());
157157 valuesArray->addElement("", valuePair);
158 boost::shared_ptr<JSONValue<int> > timeVal(new JSONValue<int>(iValue->getTimeStamp().secondsSinceEpoch()));
158 DateTime tmp_date = iValue->getTimeStamp();
159 boost::shared_ptr<JSONValue<int> > timeVal(new JSONValue<int>(tmp_date.fromUTC().secondsSinceEpoch()));
159160 boost::shared_ptr<JSONValue<double> > valueVal(new JSONValue<double>(iValue->getValue()));
160161 valuePair->addElement("", timeVal);
161162 valuePair->addElement("", valueVal);
239239 modulator->addProperty("dsid", dsMeter->getDSID().toString());
240240 modulator->addProperty("value", isEnergy ? dsMeter->getCachedEnergyMeterValue() : dsMeter->getCachedPowerConsumption());
241241
242 modulator->addProperty("date", isEnergy ? dsMeter->getCachedEnergyMeterTimeStamp().toString() : dsMeter->getCachedPowerConsumptionTimeStamp().toString());
242 DateTime temp_date = isEnergy ? dsMeter->getCachedEnergyMeterTimeStamp() : dsMeter->getCachedPowerConsumptionTimeStamp();
243 modulator->addProperty("date", temp_date.fromUTC().toString());
243244
244245 modulators->addElement("", modulator);
245246 } catch (std::runtime_error&) {
core/web/handler/systemrequesthandler.cpp
(1 / 1)
  
3737 return success(DSS::getInstance()->versionString());
3838 } else if (_request.getMethod() == "time") {
3939 std::stringstream s;
40 s << DateTime().secondsSinceEpoch();
40 s << DateTime().fromUTC().secondsSinceEpoch();
4141 return success(s.str());
4242 }
4343 throw std::runtime_error("Unhandled function");