various small changes

master
loosrob 2022-02-08 21:41:59 +01:00 committed by GitHub
parent 57ca8c4ad0
commit 2ea3bfb695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 49 deletions

View File

@ -1145,11 +1145,11 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
QString stateName = topic.split('/').at(4);
QVariant value = payload;
QHash<QString, StateTypeId> stateTypeIdMap;
stateTypeIdMap["power"] = shellyEmChannelCurrentPowerPhaseAStateTypeId;
stateTypeIdMap["power"] = shellyEmChannelCurrentPowerStateTypeId;
stateTypeIdMap["reactive_power"] = shellyEmChannelReactivePowerPhaseAStateTypeId;
stateTypeIdMap["voltage"] = shellyEmChannelVoltagePhaseAStateTypeId;
stateTypeIdMap["total"] = shellyEmChannelEnergyConsumedPhaseAStateTypeId;
stateTypeIdMap["total_returned"] = shellyEmChannelEnergyProducedPhaseAStateTypeId;
stateTypeIdMap["total"] = shellyEmChannelTotalEnergyConsumedStateTypeId;
stateTypeIdMap["total_returned"] = shellyEmChannelTotalEnergyProducedStateTypeId;
StateTypeId stateTypeId = stateTypeIdMap.value(stateName);
if (stateTypeId.isNull()) {
qCWarning(dcShelly()) << "Unhandled emeter value for channel" << channel << stateName;
@ -1163,7 +1163,6 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
foreach (Thing *child, myThings().filterByParentId(thing->id()).filterByInterface("energymeter")) {
ParamTypeId channelParamTypeId = channelParamTypeMap.value(child->thingClassId());
if (child->paramValue(channelParamTypeId).toInt() == channel + 1) {
//child->setStateValue(currentPowerStateTypeMap.value(child->thingClassId()), power);
child->setStateValue(stateTypeId, value.toDouble() * factor);
}
}
@ -1175,14 +1174,14 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
foreach (Thing *child, myThings().filterByParentId(thing->id()).filterByInterface("energymeter")) {
ParamTypeId channelParamTypeId = channelParamTypeMap.value(child->thingClassId());
if (child->paramValue(channelParamTypeId).toInt() == channel + 1) {
double power = child->stateValue(shellyEmChannelCurrentPowerStateTypeId).toDouble();
double voltage = child->stateValue(shellyEmChannelVoltagePhaseAStateTypeId).toDouble();
if (qFuzzyCompare(voltage, 0) == false) {
double calcCurrent = child->stateValue(shellyEmChannelCurrentPowerPhaseAStateTypeId).toDouble()/voltage;
double calcCurrent = power/voltage;
child->setStateValue(shellyEmChannelCurrentPhaseAStateTypeId, calcCurrent);
} else {
child->setStateValue(shellyEmChannelCurrentPhaseAStateTypeId, 0);
}
double power = child->stateValue(shellyEmChannelCurrentPowerPhaseAStateTypeId).toDouble();
double reactivePower = child->stateValue(shellyEmChannelReactivePowerPhaseAStateTypeId).toDouble();
double root = qSqrt(power*power + reactivePower*reactivePower);
if (qFuzzyCompare(root, 0) == false) {
@ -1191,12 +1190,6 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
} else {
child->setStateValue(shellyEmChannelPowerFactorPhaseAStateTypeId, 0);
}
double grandTotal = child->stateValue(shellyEmChannelEnergyConsumedPhaseAStateTypeId).toDouble();
child->setStateValue(shellyEmChannelTotalEnergyConsumedStateTypeId, grandTotal);
double grandTotalReturned = child->stateValue(shellyEmChannelEnergyProducedPhaseAStateTypeId).toDouble();
child->setStateValue(shellyEmChannelTotalEnergyProducedStateTypeId, grandTotalReturned);
double totalPower = child->stateValue(shellyEmChannelCurrentPowerPhaseAStateTypeId).toDouble();
child->setStateValue(shellyEmChannelCurrentPowerStateTypeId, totalPower);
}
}
@ -1404,7 +1397,7 @@ void IntegrationPluginShelly::setupShellyGateway(ThingSetupInfo *info)
autoChilds.append(switch2Child);
}
// Create 2 measurement channels for shelly em --> create separate switch child as well?
// Create 2 measurement channels for shelly em
if (info->thing()->thingClassId() == shellyEmThingClassId) {
ThingDescriptor channelChild(shellyEmChannelThingClassId, info->thing()->name() + " channel 1", QString(), info->thing()->id());
channelChild.setParams(ParamList() << Param(shellyEmChannelThingChannelParamTypeId, 1));

View File

@ -1785,7 +1785,8 @@
"name": "shellyEm",
"displayName": "Shelly EM",
"createMethods": ["discovery"],
"interfaces": ["gateway", "wirelessconnectable", "update"],
"interfaces": ["gateway", "wirelessconnectable", "power", "update"],
"providedInterfaces": ["energymeter"],
"paramTypes": [
{
"id": "e44d6880-4e54-44b0-85f5-4e035179402e",
@ -1888,7 +1889,7 @@
"name": "shellyEmChannel",
"displayName": "Shelly EM Channel",
"createMethods": ["auto"],
"interfaces": ["energymeter"],
"interfaces": ["wirelessconnectable", "energymeter"],
"paramTypes": [
{
"id": "b9b85416-0d48-4e71-9471-03385f8fc619",
@ -1935,7 +1936,7 @@
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 0,
"cached": false
"cached": true
},
{
"id": "7fe88e8f-a1c4-4e8d-a1de-9135b80bc7e3",
@ -1945,7 +1946,7 @@
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 0,
"cached": false
"cached": true
},
{
"id": "a85041e8-a19e-4695-8404-3e3a06b1e92a",
@ -1955,18 +1956,6 @@
"type": "double",
"unit": "Watt",
"defaultValue": 0,
"filter": "adaptive",
"cached": false
},
{
"id": "18b17662-43bc-45d4-9e33-35912b57bfb1",
"name": "currentPowerPhaseA",
"displayName": "Current power",
"displayNameEvent": "Current power changed",
"type": "double",
"unit": "Watt",
"defaultValue": 0,
"filter": "adaptive",
"cached": false
},
{
@ -2009,26 +1998,6 @@
"defaultValue": 0,
"filter": "adaptive",
"cached": false
},
{
"id": "cb28c99c-2f64-4b8b-83ca-e9809ecd992a",
"name": "energyConsumedPhaseA",
"displayName": "Total consumed energy",
"displayNameEvent": "Total consumed energy changed",
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 0,
"cached": false
},
{
"id": "3c254d08-ca5a-4caa-a6fb-7f9d0e3ac6d6",
"name": "energyProducedPhaseA",
"displayName": "Total returned energy",
"displayNameEvent": "Total returned energy changed",
"type": "double",
"unit": "KiloWattHour",
"defaultValue": 0,
"cached": false
}
],
"actionTypes": [