Skip to content

Commit

Permalink
[ferroamp] Binding for ferroamp 20241024
Browse files Browse the repository at this point in the history
Changes done, Please see Reply...regarded to each conversion

Signed-off-by: Örjan Backsell <orjan.backsell@gmail.com>
  • Loading branch information
basse04 committed Oct 25, 2024
1 parent ae90e1d commit f31221c
Show file tree
Hide file tree
Showing 8 changed files with 768 additions and 745 deletions.
10 changes: 10 additions & 0 deletions bundles/org.openhab.binding.ferroamp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ The following channels are available for `Ferroamp` EnergyHub configuration. Ple
Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=false ]
```

```java
Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=false, ssoS0=true ]
```

```java
Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=true, ssoS0=true, eso=true ]
```



## `demo.items` Example

```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}

@SuppressWarnings("null")
@Override
public void initialize() {
// Set channel configuration parameters
Expand Down Expand Up @@ -114,17 +115,26 @@ public void initialize() {
}
} else {
updateStatus(ThingStatus.OFFLINE);
thingReachable = false;
}
});

// Start channel-update as configured
scheduler.scheduleWithFixedDelay(() -> {
try {
channelUpdate();
} catch (RuntimeException scheduleWithFixedDelayException) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
scheduleWithFixedDelayException.getClass().getName() + ":"
+ scheduleWithFixedDelayException.getMessage());
System.out.println("ffff = " + getFerroampConnection().connectionState());
if (getFerroampConnection().connectionState().toString().equals("DISCONNECTED")) {
System.out.println("aaaaa = " + getFerroampConnection().connectionState());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
logger.debug("Problem connection to MqttBroker");
} else {
try {
channelUpdate();
updateStatus(ThingStatus.ONLINE);
} catch (RuntimeException scheduleWithFixedDelayException) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
scheduleWithFixedDelayException.getClass().getName() + ":"
+ scheduleWithFixedDelayException.getMessage());
}
}
}, 60, refreshInterval, TimeUnit.SECONDS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public void processMessage(String topic, byte[] payload) {
if ("extapi/data/sso".equals(topic)) {
processIncomingJsonMessageSso(topic, new String(payload, StandardCharsets.UTF_8));
}
if ("extapi/data/eso".equals(topic)) {
processIncomingJsonMessageEso(topic, new String(payload, StandardCharsets.UTF_8));
}
if ("extapi/data/esm".equals(topic)) {
processIncomingJsonMessageEsm(topic, new String(payload, StandardCharsets.UTF_8));
}
}

@SuppressWarnings("null")
Expand Down Expand Up @@ -634,111 +640,116 @@ void processIncomingJsonMessageSso(String topic, String messageJsonSso) {

ssoS3ChannelsUpdateValues = ssoS3ChannelPostsValue;
}
}

if ("extapi/data/eso".equals(topic)) {
String[] esoChannelPostsValue = new String[10]; // Array for ESO, Energy Storage Optimizer ) Posts
JsonObject jsonElementsObject = new Gson().fromJson(new Gson().fromJson(messageJsonSso, JsonObject.class),
JsonObject.class);

String jsonElementsStringTemp = "";

// faultcode
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(0)).toString();
GetGeneralValues faultcode = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[0] = faultcode.getVal();

// id
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(1)).toString();
GetGeneralValues id = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[1] = id.getVal();

// ibat
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(2)).toString();
GetGeneralValues ibat = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[2] = ibat.getVal();

// ubat
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(3)).toString();
GetGeneralValues ubat = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[3] = ubat.getVal();

// relaystatus
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(4)).toString();
GetGeneralValues relaystatus = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[4] = relaystatus.getVal();

// soc
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(5)).toString();
GetGeneralValues soc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[5] = soc.getVal();

// temp
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(6)).toString();
GetGeneralValues temp = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[6] = temp.getVal();

// wbatprod
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(7)).toString();
GetGeneralValues wbatprod = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[7] = mJTokWh(jsonStripOneLiners(wbatprod.getVal()));
@SuppressWarnings("null")
// Prepare actual Json-topic Eso-message and update values for channels
void processIncomingJsonMessageEso(String topic, String messageJsonEso) {
String[] esoChannelPostsValue = new String[10]; // Array for ESO, Energy Storage Optimizer ) Posts
JsonObject jsonElementsObject = new Gson().fromJson(new Gson().fromJson(messageJsonEso, JsonObject.class),
JsonObject.class);
String jsonElementsStringTemp = "";
Gson gson = new Gson();

// udc
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(8)).toString();
GetGeneralValues udc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[8] = udc.getVal();
// faultcode
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(0)).toString();
GetGeneralValues faultcode = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[0] = faultcode.getVal();

// id
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(1)).toString();
GetGeneralValues id = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[1] = id.getVal();

// ibat
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(2)).toString();
GetGeneralValues ibat = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[2] = ibat.getVal();

// ubat
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(3)).toString();
GetGeneralValues ubat = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[3] = ubat.getVal();

// relaystatus
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(4)).toString();
GetGeneralValues relaystatus = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[4] = relaystatus.getVal();

// soc
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(5)).toString();
GetGeneralValues soc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[5] = soc.getVal();

// temp
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(6)).toString();
GetGeneralValues temp = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[6] = temp.getVal();

// wbatprod
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(7)).toString();
GetGeneralValues wbatprod = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[7] = mJTokWh(jsonStripOneLiners(wbatprod.getVal()));

// udc
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(8)).toString();
GetGeneralValues udc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[8] = udc.getVal();

// ts
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(9)).toString();
GetGeneralValues ts = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[9] = ts.getVal();
// ts
jsonElementsStringTemp = jsonElementsObject.get(EsoJsonElements.getJsonElementsEso().get(9)).toString();
GetGeneralValues ts = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esoChannelPostsValue[9] = ts.getVal();

esoChannelsUpdateValues = esoChannelPostsValue;
}
esoChannelsUpdateValues = esoChannelPostsValue;
}

if ("extapi/data/esm".equals(topic)) {
String[] esmChannelPostsValue = new String[7]; // Array for ESM, Energy Storage Module ) Posts
JsonObject jsonElementsObject = new Gson().fromJson(new Gson().fromJson(messageJsonSso, JsonObject.class),
JsonObject.class);
@SuppressWarnings("null")
// Prepare actual Json-topic Esm-message and update values for channels
void processIncomingJsonMessageEsm(String topic, String messageJsonEsm) {
String[] esmChannelPostsValue = new String[7]; // Array for ESM, Energy Storage Module ) Posts
JsonObject jsonElementsObject = new Gson().fromJson(new Gson().fromJson(messageJsonEsm, JsonObject.class),
JsonObject.class);
String jsonElementsStringTemp = "";
Gson gson = new Gson();

String jsonElementsStringTemp = "";
// soc
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(0)).toString();
GetGeneralValues soc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[0] = soc.getVal();

// soc
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(0)).toString();
GetGeneralValues soc = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[0] = soc.getVal();
// soh
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(1)).toString();
GetGeneralValues soh = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[1] = soh.getVal();

// soh
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(1)).toString();
GetGeneralValues soh = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[1] = soh.getVal();
// ratedcapacity
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(2)).toString();
GetGeneralValues ratedcapacity = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[2] = ratedcapacity.getVal();

// ratedcapacity
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(2)).toString();
GetGeneralValues ratedcapacity = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[2] = ratedcapacity.getVal();
// id
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(3)).toString();
GetGeneralValues id = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[3] = id.getVal();

// id
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(3)).toString();
GetGeneralValues id = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[3] = id.getVal();
// ratedpower
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(4)).toString();
GetGeneralValues ratedpower = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[4] = ratedpower.getVal();

// ratedpower
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(4)).toString();
GetGeneralValues ratedpower = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[4] = ratedpower.getVal();
// status
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(5)).toString();
GetGeneralValues status = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[5] = status.getVal();

// status
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(5)).toString();
GetGeneralValues status = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[5] = status.getVal();
// ts
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(6)).toString();
GetGeneralValues ts = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[6] = ts.getVal();

// ts
jsonElementsStringTemp = jsonElementsObject.get(EsmJsonElements.getJsonElementsEsm().get(6)).toString();
GetGeneralValues ts = gson.fromJson(jsonElementsStringTemp, GetGeneralValues.class);
esmChannelPostsValue[6] = ts.getVal();
esmChannelsUpdateValues = esmChannelPostsValue;

esmChannelsUpdateValues = esmChannelPostsValue;
}
}

public @Nullable static String[] getEhubChannelUpdateValues() {
Expand Down
Loading

0 comments on commit f31221c

Please sign in to comment.