Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shelly][WIP] Add energy channels for Shelly Pro EM 50 #17836

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2CoverStatus;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusEm;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusEm1Data;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusEmData;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusHumidity;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusIlluminance;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusPower;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusSmoke;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2DeviceStatusTempId;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBWStatus;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2StatusEm1;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2InputStatus;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RelayStatus;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage;
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2StatusEm1;
import org.openhab.binding.shelly.internal.config.ShellyThingConfiguration;
import org.openhab.binding.shelly.internal.handler.ShellyBaseHandler;
import org.openhab.binding.shelly.internal.handler.ShellyComponents;
Expand Down Expand Up @@ -194,8 +195,8 @@ protected boolean fillDeviceStatus(ShellySettingsStatus status, Shelly2DeviceSta
updated |= updateRelayStatus(status, result.switch100, channelUpdate);
updated |= updateRelayStatus(status, result.pm10, channelUpdate);
updated |= updateEmStatus(status, result.em0, result.emdata0, channelUpdate);
updated |= updateEmStatus(status, result.em10, channelUpdate);
updated |= updateEmStatus(status, result.em11, channelUpdate);
updated |= updateEmStatus(status, result.em10, result.em1data0, channelUpdate);
updated |= updateEmStatus(status, result.em11, result.em1data1, channelUpdate);
updated |= updateRollerStatus(status, result.cover0, channelUpdate);
updated |= updateDimmerStatus(status, result.light0, channelUpdate);
updated |= updateRGBWStatus(status, result.rgbw0, channelUpdate);
Expand Down Expand Up @@ -327,9 +328,9 @@ private void updateMeter(ShellySettingsStatus status, int id, ShellySettingsMete
relayStatus.meters.set(id, sm);
}

private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2StatusEm1 em, boolean channelUpdate)
throws ShellyApiException {
if (em == null) {
private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2StatusEm1 em,
@Nullable Shelly2DeviceStatusEm1Data em1Data, boolean channelUpdate) throws ShellyApiException {
if (em == null || em1Data == null) {
return false;
}

Expand All @@ -338,9 +339,6 @@ private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2Sta
if (em.actPower != null) {
sm.power = emeter.power = em.actPower;
}
if (em.aptrPower != null) {
emeter.totalReturned = em.aptrPower;
}
if (em.voltage != null) {
emeter.voltage = em.voltage;
}
Expand Down Expand Up @@ -369,9 +367,6 @@ private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2Dev
if (em.totalActPower != null) {
status.totalPower = em.totalActPower;
}
if (em.totalAprtPower != null) {
status.totalReturned = em.totalAprtPower;
}

if (emData.totalKWH != null) {
status.totalKWH = emData.totalKWH;
Expand All @@ -385,9 +380,6 @@ private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2Dev
if (emData.aTotal != null) {
emeter.total = emData.aTotal;
}
if (em.aAprtPower != null) {
emeter.totalReturned = em.aAprtPower;
}
if (em.aVoltage != null) {
emeter.voltage = em.aVoltage;
}
Expand All @@ -410,9 +402,6 @@ private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2Dev
if (emData.bTotal != null) {
emeter.total = emData.bTotal;
}
if (em.bAprtPower != null) {
emeter.totalReturned = em.bAprtPower;
}
if (em.bVoltage != null) {
emeter.voltage = em.bVoltage;
}
Expand All @@ -436,9 +425,6 @@ private boolean updateEmStatus(ShellySettingsStatus status, @Nullable Shelly2Dev
if (emData.cTotal != null) {
emeter.total = emData.cTotal;
}
if (em.cAprtPower != null) {
emeter.totalReturned = em.cAprtPower;
}
if (em.cVoltage != null) {
emeter.voltage = em.cVoltage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,30 @@ public static class Shelly2DeviceStatusEmData {
public String[] errors;
}

public static class Shelly2StatusEm1 {
public Integer id;
public Double current;
public Double voltage;
@SerializedName("act_power")
public Double actPower;
@SerializedName("aprt_power")
public Double aptrPower;
public Double pf;
public String calibration;
public ArrayList<String> errors;
}

public static class Shelly2DeviceStatusEm1Data {
public Integer id;

@SerializedName("total_act_energy")
public Double totalKWH;
@SerializedName("total_act_ret_energy")
public Double totalReturned;

public String[] errors;
}

public class Shelly2DeviceStatusSmoke {
public Integer id;
public Boolean alarm;
Expand Down Expand Up @@ -780,12 +804,15 @@ public static class Shelly2RGBWStatus {
public Shelly2DeviceStatusEm em0;
@SerializedName("emdata:0")
public Shelly2DeviceStatusEmData emdata0;

@SerializedName("em1:0")
public Shelly2StatusEm1 em10;
@SerializedName("em1:1")
public Shelly2StatusEm1 em11;
@SerializedName("em1data:0")
public Shelly2DeviceStatusEmData em1data0;
public Shelly2DeviceStatusEm1Data em1data0;
@SerializedName("em1data:1")
public Shelly2DeviceStatusEm1Data em1data1;

@SerializedName("cover:0")
public Shelly2CoverStatus cover0;
Expand Down Expand Up @@ -914,19 +941,6 @@ public static class Shelly2Pm1Status {
public String[] errors;
}

public static class Shelly2StatusEm1 {
public Integer id;
public Double current;
public Double voltage;
@SerializedName("act_power")
public Double actPower;
@SerializedName("aprt_power")
public Double aptrPower;
public Double pf;
public String calibration;
public ArrayList<String> errors;
}

public static class Shelly2DeviceStatusTemp {
public Double tC;
public Double tF;
Expand Down
Loading