Add senec inverter option
parent
c09add5c09
commit
3254a8992d
|
|
@ -129,9 +129,9 @@ void IntegrationPluginSenec::startPairing(ThingPairingInfo *info)
|
|||
return;
|
||||
}
|
||||
|
||||
// qCDebug(dcSenec()) << "Senec server is reachable. Starting the OpenID auth process" << connection->authEndpoint().toString(QUrl::FullyEncod7edy);
|
||||
// info->setOAuthUrl(connection->authEndpoint());
|
||||
// info->finish(Thing::ThingErrorNoError);
|
||||
qCDebug(dcSenec()) << "Senec server is reachable. Starting the OpenID auth process" << connection->authEndpoint().toString(QUrl::FullyEncoded);
|
||||
info->setOAuthUrl(connection->authEndpoint());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
|
||||
connection->initialize();
|
||||
|
|
@ -238,18 +238,20 @@ void IntegrationPluginSenec::setupThing(ThingSetupInfo *info)
|
|||
}
|
||||
});
|
||||
|
||||
connect(storage, &SenecStorageLan::availableChanged, thing, [thing](bool available){
|
||||
connect(storage, &SenecStorageLan::availableChanged, thing, [thing, this](bool available){
|
||||
thing->setStateValue(senecStorageLanConnectedStateTypeId, available);
|
||||
|
||||
// TODO: Update also child things
|
||||
|
||||
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
||||
child->setStateValue("connected", available);
|
||||
}
|
||||
});
|
||||
|
||||
connect(storage, &SenecStorageLan::updatedFinished, thing, [storage, thing, this](bool success){
|
||||
|
||||
thing->setStateValue(senecStorageLanConnectedStateTypeId, storage->available());
|
||||
|
||||
// TODO: Update also child things
|
||||
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
||||
child->setStateValue("connected", storage->available());
|
||||
}
|
||||
|
||||
if (!success)
|
||||
return;
|
||||
|
|
@ -278,8 +280,20 @@ void IntegrationPluginSenec::setupThing(ThingSetupInfo *info)
|
|||
meterThing->setStateValue(senecMeterCurrentPowerStateTypeId, storage->gridPower());
|
||||
meterThing->setStateValue(senecMeterConnectedStateTypeId, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Check if we have an inverter
|
||||
Thing *inverterThing = nullptr;
|
||||
Things inverterThings = myThings().filterByThingClassId(senecInverterThingClassId).filterByParentId(thing->id());
|
||||
if (!inverterThings.isEmpty()) {
|
||||
inverterThing = inverterThings.first();
|
||||
}
|
||||
|
||||
// If so, update
|
||||
if (inverterThing) {
|
||||
inverterThing->setStateValue(senecInverterCurrentPowerStateTypeId, storage->inverterPower());
|
||||
inverterThing->setStateValue(senecInverterConnectedStateTypeId, true);
|
||||
}
|
||||
});
|
||||
|
||||
connect(thing, &Thing::settingChanged, this, [this, thing](const ParamTypeId ¶mTypeId, const QVariant &value){
|
||||
if (paramTypeId == senecStorageLanSettingsAddMeterParamTypeId) {
|
||||
|
|
@ -298,6 +312,22 @@ void IntegrationPluginSenec::setupThing(ThingSetupInfo *info)
|
|||
emit autoThingDisappeared(existingMeters.takeFirst()->id());
|
||||
}
|
||||
}
|
||||
} else if (paramTypeId == senecStorageLanSettingsAddMeterParamTypeId) {
|
||||
|
||||
if (value.toBool()) {
|
||||
// Check if we have to add the meter
|
||||
if (myThings().filterByThingClassId(senecInverterThingClassId).filterByParentId(thing->id()).isEmpty()) {
|
||||
qCDebug(dcSenec()) << "Add inverter for" << thing->name();
|
||||
emit autoThingsAppeared(ThingDescriptors() << ThingDescriptor(senecInverterThingClassId, "SENEC Inverter", QString(), thing->id()));
|
||||
}
|
||||
} else {
|
||||
// Check if we have to remove the meter
|
||||
Things existingInverters = myThings().filterByThingClassId(senecInverterThingClassId).filterByParentId(thing->id());
|
||||
if (!existingInverters.isEmpty()) {
|
||||
qCDebug(dcSenec()) << "Remove inverter thing for" << thing->name();
|
||||
emit autoThingDisappeared(existingInverters.takeFirst()->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -326,6 +356,22 @@ void IntegrationPluginSenec::setupThing(ThingSetupInfo *info)
|
|||
emit autoThingDisappeared(existingMeters.takeFirst()->id());
|
||||
}
|
||||
}
|
||||
} else if (paramTypeId == senecStorageSettingsAddInverterParamTypeId) {
|
||||
|
||||
if (value.toBool()) {
|
||||
// Check if we have to add the meter
|
||||
if (myThings().filterByThingClassId(senecInverterThingClassId).filterByParentId(thing->id()).isEmpty()) {
|
||||
qCDebug(dcSenec()) << "Add inverter for" << thing->name();
|
||||
emit autoThingsAppeared(ThingDescriptors() << ThingDescriptor(senecInverterThingClassId, "SENEC Inverter", QString(), thing->id()));
|
||||
}
|
||||
} else {
|
||||
// Check if we have to remove the meter
|
||||
Things existingInverters = myThings().filterByThingClassId(senecInverterThingClassId).filterByParentId(thing->id());
|
||||
if (!existingInverters.isEmpty()) {
|
||||
qCDebug(dcSenec()) << "Remove inverter thing for" << thing->name();
|
||||
emit autoThingDisappeared(existingInverters.takeFirst()->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -333,6 +379,8 @@ void IntegrationPluginSenec::setupThing(ThingSetupInfo *info)
|
|||
|
||||
} else if (thing->thingClassId() == senecMeterThingClassId) {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else if (thing->thingClassId() == senecInverterThingClassId) {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ private:
|
|||
PluginTimer *m_refreshTimer = nullptr;
|
||||
|
||||
QHash<Thing *, SenecAccount *> m_accounts;
|
||||
|
||||
QHash<Thing *, NetworkDeviceMonitor *> m_monitors;
|
||||
QHash<Thing *, SenecStorageLan *> m_storages;
|
||||
|
||||
|
|
|
|||
|
|
@ -195,6 +195,13 @@
|
|||
"displayName": "Add meter",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"id": "67e91768-86c4-4021-a93b-4c240adce687",
|
||||
"name": "addInverter",
|
||||
"displayName": "Add inverter",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
}
|
||||
],
|
||||
"paramTypes": [
|
||||
|
|
@ -382,6 +389,40 @@
|
|||
"cached": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "senecInverter",
|
||||
"displayName": "SENEC Inverter",
|
||||
"id": "5682ab06-9e0e-40ce-97c0-53dd411a012f",
|
||||
"createMethods": [ "auto" ],
|
||||
"interfaces": ["solarinverter", "connectable"],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "4a9e27cb-0e4f-4189-8a26-ddd7a604fb90",
|
||||
"name": "connected",
|
||||
"displayName": "Connected",
|
||||
"type": "bool",
|
||||
"defaultValue": false,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "990a62ba-3582-4e1e-8449-dfdece3c519c",
|
||||
"name": "currentPower",
|
||||
"displayName": "Current power usage",
|
||||
"type": "double",
|
||||
"unit": "Watt",
|
||||
"defaultValue": 0,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "f052af7c-2408-4f1e-af35-c874461acb9d",
|
||||
"name": "totalEnergyProduced",
|
||||
"displayName": "Energy returned",
|
||||
"type": "double",
|
||||
"unit": "KiloWattHour",
|
||||
"defaultValue": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,13 +134,6 @@ QString SenecStorageLan::parseString(const QString &value)
|
|||
return value.right(value.length() - 3);
|
||||
}
|
||||
|
||||
// quint8 SenecStorageLan::parseUInt8(const QString &value)
|
||||
// {
|
||||
// Q_ASSERT_X(value.left(3) == "u8_", "SenecStorageLan", "The given value does not seem to be a uint8, it is not starting with u8_");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
void SenecStorageLan::initialize()
|
||||
{
|
||||
// if (m_url.isValid()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue