QString HttpDaemon::generateWebPage() { DeviceClass deviceClass = m_plugin->supportedDevices().first(); QString body = QString( "<html>" "<body>" "<h1>Mock device Controller</h1>\n" "<hr>" "<h2>Device Information</h2>" "Name: %1<br>" "ID: %2<br>" "DeviceClass ID: %3<br>").arg(m_device->paramValue("name").toString()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); body.append("<hr>"); body.append("<h2>States</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.stateTypes().count(); ++i) { body.append("<tr>"); body.append("<form action=\"/setstate\" method=\"get\">"); const StateType &stateType = deviceClass.stateTypes().at(i); body.append("<td>" + stateType.name() + "</td>"); body.append(QString("<td><input type='input'' name='%1' value='%2'></td>").arg(stateType.id().toString()).arg(m_device->states().at(i).value().toString())); body.append("<td><input type=submit value='Set State'/></td>"); body.append("</form>"); body.append("</tr>"); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Events</h2>"); body.append("<table>"); for (int i = 0; i < deviceClass.eventTypes().count(); ++i) { const EventType &eventType = deviceClass.eventTypes().at(i); body.append(QString( "<tr>" "<form action=\"/generateevent\" method=\"get\">" "<td>%1<input type='hidden' name='eventtypeid' value='%2'/></td>" "<td>").arg(eventType.name()).arg(eventType.id().toString())); if (!eventType.name().endsWith(" changed")) { body.append("<input type='submit' value='Generate'/>"); } body.append("</td>" "</form>" "</tr>" ); } body.append("</table>"); body.append("<hr>"); body.append("<h2>Actions</h2>"); body.append("<table border=2px>"); body.append("<tr><td>Name</td><td>Type ID</td><td>Timestamp</td></tr>"); for (int i = 0; i < m_actionList.count(); ++i) { ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first); QDateTime timestamp = m_actionList.at(i).second; QString actionName; foreach (const ActionType &at, deviceClass.actionTypes()) { if (at.id() == actionTypeId) { actionName = at.name(); break; } } body.append(QString( "<tr>" "<td>%1</td>" "<td>%2</td>" "<td>%3</td>" "</tr>" ).arg(actionName).arg(actionTypeId.toString()).arg(timestamp.toString())); } body.append("</table>"); body.append("</body></html>\n"); return generateHeader() + body; }
StateTypeId ecoTempStateTypeId = StateTypeId("24dfd20d-bc8d-48e4-8162-b20ae0465c41"); StateTypeId maxSetpointTempStateTypeId = StateTypeId("a8536ddf-a6e4-41c2-89c1-e7102608f5f6"); StateTypeId minSetpointTempStateTypeId = StateTypeId("ceb0ad05-37ad-4b79-a4d9-540c34a7e3e4"); StateTypeId errorOccuredStateTypeId = StateTypeId("9880247b-cf9a-453c-b0c3-d910eba8a253"); StateTypeId initializedStateTypeId = StateTypeId("a9e29f03-063e-4686-8aac-2f6d8f8a4937"); StateTypeId batteryLowStateTypeId = StateTypeId("53b89f32-8894-4290-92a0-6a470c6b69ab"); StateTypeId linkStatusOKStateTypeId = StateTypeId("aff38be8-7ea6-4fd8-b0fa-e987ab05c719"); StateTypeId panelLockedStateTypeId = StateTypeId("979df197-09a1-46f9-9217-9d323b1062bd"); StateTypeId gatewayKnownStateTypeId = StateTypeId("1d6bd962-5c31-47ad-80a4-dda87bff98f5"); StateTypeId dtsActiveStateTypeId = StateTypeId("1b402ba6-a8ae-45b1-8acf-2b0a89f71889"); StateTypeId deviceModeStateTypeId = StateTypeId("639360f0-bb65-43e6-b227-50ae0ac39d6c"); StateTypeId deviceModeStringStateTypeId = StateTypeId("ff5194e3-5641-4ac2-92c7-48c431b4a2eb"); StateTypeId setpointTempStateTypeId = StateTypeId("579aa8c6-8814-491b-9e7c-b98108c323d1"); StateTypeId currentTemperatureStateTypeId = StateTypeId("852e7708-db1d-42d1-96e4-19c13598262c"); ActionTypeId setSetpointTemperatureActionTypeId = ActionTypeId("9c1968ba-39f9-493d-9fe2-848fa86bd2f0"); ActionTypeId setAutoModeActionTypeId = ActionTypeId("162b4b3d-9923-4f2c-a755-b50c8a06a6f0"); ActionTypeId setManuelModeActionTypeId = ActionTypeId("8e604437-9f5b-4c17-b5b0-e2db6007af5b"); ActionTypeId setEcoModeActionTypeId = ActionTypeId("27a981e8-ec23-4ba8-921e-33b911a7dd89"); ActionTypeId displayCurrentTempActionTypeId = ActionTypeId("184fb112-7a03-4560-8634-0257c969c26e"); DeviceClassId radiatorThermostateDeviceClassId = DeviceClassId("f80d9481-4827-45ee-a013-b97b22412d92"); StateTypeId offsetTempStateTypeId = StateTypeId("576da571-9a65-478f-96bf-19256c8b9ece"); StateTypeId windowOpenDurationStateTypeId = StateTypeId("81c6c74a-b0cd-4daa-9eb9-f1cd68f328af"); StateTypeId boostValueValueStateTypeId = StateTypeId("7c41fa64-b1a1-48d2-9d03-67aa16cd83ad"); StateTypeId boostDurationStateTypeId = StateTypeId("e75c1398-9ad7-466c-b3b9-b03bbb686a30"); StateTypeId discalcWeekDayStateTypeId = StateTypeId("bd6f5947-d4b4-444b-81c8-77eec46957e4"); StateTypeId discalcTimeStateTypeId = StateTypeId("e78235ee-affc-41e3-a463-9f0512b4a6c3"); StateTypeId valveMaximumSettingsStateTypeId = StateTypeId("e367fa3a-b30f-49bd-af3f-cff92360ad32"); StateTypeId valveOffsetStateTypeId = StateTypeId("ffaff87b-b741-4db8-9875-3380af4f1885");
#include "devicepluginmailnotification.h" #include "plugin/device.h" #include "devicemanager.h" #include <QDebug> #include <QJsonDocument> #include <QVariantMap> #include <QDateTime> DeviceClassId googleMailDeviceClassId = DeviceClassId("3869884a-1592-4b8f-84a7-994be18ff555"); DeviceClassId yahooMailDeviceClassId = DeviceClassId("59409e8f-0c83-414f-abd5-bbbf2758acba"); DeviceClassId customMailDeviceClassId = DeviceClassId("f4844c97-7ca6-4349-904e-ff9749a9fe74"); ActionTypeId sendMailActionTypeId = ActionTypeId("054613b0-3666-4dad-9252-e0ebca187edc"); DevicePluginMailNotification::DevicePluginMailNotification() { } DevicePluginMailNotification::~DevicePluginMailNotification() { } DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Device *device) { // Google mail if(device->deviceClassId() == googleMailDeviceClassId) { device->setName("Google Mail (" + device->paramValue("user").toString() + ")"); SmtpClient *smtpClient = new SmtpClient(this);
/*! Return a list of \l{DeviceClass}{DeviceClasses} describing all the devices supported by this plugin. If a DeviceClass has an invalid parameter it will be ignored. */ QList<DeviceClass> DevicePlugin::supportedDevices() const { QList<DeviceClass> deviceClasses; foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) { bool broken = false; VendorId vendorId = vendorJson.toObject().value("id").toString(); foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) { QJsonObject jo = deviceClassJson.toObject(); DeviceClass deviceClass(pluginId(), vendorId, jo.value("deviceClassId").toString()); deviceClass.setName(jo.value("name").toString()); DeviceClass::CreateMethods createMethods; foreach (const QJsonValue &createMethodValue, jo.value("createMethods").toArray()) { if (createMethodValue.toString() == "discovery") { createMethods |= DeviceClass::CreateMethodDiscovery; } else if (createMethodValue.toString() == "auto") { createMethods |= DeviceClass::CreateMethodAuto; } else if (createMethodValue.toString() == "user") { createMethods |= DeviceClass::CreateMethodUser; } else { qCWarning(dcDeviceManager) << "Unknown createMehtod" << createMethodValue.toString() << "in deviceClass " << deviceClass.name() << ". Falling back to CreateMethodUser."; createMethods |= DeviceClass::CreateMethodUser; } } deviceClass.setCreateMethods(createMethods); deviceClass.setDeviceIcon(loadAndVerifyDeviceIcon(jo.value("deviceIcon").toString())); deviceClass.setDiscoveryParamTypes(parseParamTypes(jo.value("discoveryParamTypes").toArray())); QString setupMethod = jo.value("setupMethod").toString(); if (setupMethod == "pushButton") { deviceClass.setSetupMethod(DeviceClass::SetupMethodPushButton); } else if (setupMethod == "displayPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodDisplayPin); } else if (setupMethod == "enterPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodEnterPin); } else if (setupMethod == "justAdd") { qCWarning(dcDeviceManager) << "Unknown setupMehtod" << setupMethod << "in deviceClass " << deviceClass.name() << ". Falling back to SetupMethodJustAdd."; deviceClass.setSetupMethod(DeviceClass::SetupMethodJustAdd); } deviceClass.setPairingInfo(jo.value("pairingInfo").toString()); deviceClass.setParamTypes(parseParamTypes(jo.value("paramTypes").toArray())); QList<DeviceClass::BasicTag> basicTags; foreach (const QJsonValue &basicTagJson, jo.value("basicTags").toArray()) { basicTags.append(loadAndVerifyBasicTag(basicTagJson.toString())); } deviceClass.setBasicTags(basicTags); QList<ActionType> actionTypes; QList<StateType> stateTypes; foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) { QJsonObject st = stateTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name", st); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes"; broken = true; break; } QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data()); StateType stateType(st.value("id").toString()); stateType.setName(st.value("name").toString()); stateType.setType(t); stateType.setUnit(loadAndVerifyUnit(st.value("unit").toString())); stateType.setDefaultValue(st.value("defaultValue").toVariant()); if (st.contains("minValue")) stateType.setMinValue(st.value("minValue").toVariant()); if (st.contains("maxValue")) stateType.setMaxValue(st.value("maxValue").toVariant()); if (st.contains("possibleValues")) { QVariantList possibleValues; foreach (const QJsonValue &possibleValueJson, st.value("possibleValues").toArray()) { possibleValues.append(possibleValueJson.toVariant()); } stateType.setPossibleValues(possibleValues); // inform the plugin developer about the error in the plugin json file Q_ASSERT_X(stateType.possibleValues().contains(stateType.defaultValue()), QString("\"%1\" plugin").arg(pluginName()).toLatin1().data(), QString("The given default value \"%1\" is not in the possible values of the stateType \"%2\".") .arg(stateType.defaultValue().toString()).arg(stateType.name()).toLatin1().data()); } stateTypes.append(stateType); // create ActionType if this StateType is writable if (st.contains("writable") && st.value("writable").toBool()) { // Note: fields already checked in StateType ActionType actionType(ActionTypeId(stateType.id().toString())); actionType.setName("set " + stateType.name()); ParamType paramType(stateType.name(), t, stateType.defaultValue()); paramType.setAllowedValues(stateType.possibleValues()); paramType.setUnit(stateType.unit()); paramType.setLimits(stateType.minValue(), stateType.maxValue()); actionType.setParamTypes(QList<ParamType>() << paramType); actionTypes.append(actionType); } } deviceClass.setStateTypes(stateTypes); foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) { QJsonObject at = actionTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", at); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes"; broken = true; break; } ActionType actionType(at.value("id").toString()); actionType.setName(at.value("name").toString()); actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray())); actionTypes.append(actionType); } deviceClass.setActionTypes(actionTypes); QList<EventType> eventTypes; foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) { QJsonObject et = eventTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", et); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes"; broken = true; break; } EventType eventType(et.value("id").toString()); eventType.setName(et.value("name").toString()); eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray())); eventTypes.append(eventType); } deviceClass.setEventTypes(eventTypes); if (!broken) deviceClasses.append(deviceClass); } }