Skip to content

Commit

Permalink
[fronius] Deduplicate the URL parsing routine
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Mar 1, 2022
1 parent 494f682 commit 02b7731
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
* @author Peter Schraffl - Added device status and error status channels
* @author Thomas Kordelle - Added inverter power, battery state of charge and PV solar yield
* @author Hannes Spenger - Added ohmpilot & meter power sum
* @author Jimmy Tanagra - Implement a common url parsing method
*/
@NonNullByDefault
public class FroniusBindingConstants {

private static final String BINDING_ID = "fronius";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_INVERTER = new ThingTypeUID(BINDING_ID, "powerinverter");
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final ThingTypeUID THING_TYPE_INVERTER = new ThingTypeUID(BINDING_ID, "powerinverter");
public static final ThingTypeUID THING_TYPE_METER = new ThingTypeUID(BINDING_ID, "meter");
public static final ThingTypeUID THING_TYPE_OHMPILOT = new ThingTypeUID(BINDING_ID, "ohmpilot");

// List of all Channel ids
// Inverter channels
public static final String INVERTER_DATA_CHANNEL_DAY_ENERGY = "inverterdatachanneldayenergy";
public static final String INVERTER_DATA_CHANNEL_PAC = "inverterdatachannelpac";
public static final String INVERTER_DATA_CHANNEL_TOTAL = "inverterdatachanneltotal";
Expand All @@ -47,10 +48,17 @@ public class FroniusBindingConstants {
public static final String INVERTER_DATA_CHANNEL_UDC = "inverterdatachanneludc";
public static final String INVERTER_DATA_CHANNEL_DEVICE_STATUS_ERROR_CODE = "inverterdatadevicestatuserrorcode";
public static final String INVERTER_DATA_CHANNEL_DEVICE_STATUS_STATUS_CODE = "inverterdatadevicestatusstatuscode";

// Power Flow channels
public static final String POWER_FLOW_P_GRID = "powerflowchannelpgrid";
public static final String POWER_FLOW_P_LOAD = "powerflowchannelpload";
public static final String POWER_FLOW_P_AKKU = "powerflowchannelpakku";
public static final String POWER_FLOW_P_PV = "powerflowchannelppv";

public static final String POWER_FLOW_INVERTER_1_POWER = "powerflowinverter1power";
public static final String POWER_FLOW_INVERTER_1_SOC = "powerflowinverter1soc";

// Meter channels
public static final String METER_ENABLE = "enable";
public static final String METER_LOCATION = "location";
public static final String METER_CURRENT_AC_PHASE_1 = "currentacphase1";
Expand All @@ -68,29 +76,41 @@ public class FroniusBindingConstants {
public static final String METER_POWER_FACTOR_PHASE_3 = "powerfactorphase3";
public static final String METER_ENERGY_REAL_SUM_CONSUMED = "energyrealsumconsumed";
public static final String METER_ENERGY_REAL_SUM_PRODUCED = "energyrealsumproduced";

// OhmPilot channels
public static final String OHMPILOT_POWER_REAL_SUM = "powerrealsum";
public static final String OHMPILOT_ENERGY_REAL_SUM_CONSUMED = "energyrealsumconsumed";
public static final String OHMPILOT_ENERGY_SENSOR_TEMPERATURE_CHANNEL_1 = "temperaturechannel1";
public static final String OHMPILOT_ERROR_CODE = "errorcode";
public static final String OHMPILOT_STATE_CODE = "statecode";

/*
* part of POWERFLOW_REALTIME_DATA using Symo Gen24
* "Inverters" : {
* "1" : {
* "Battery_Mode" : "normal",
* "DT" : 1,
* "P" : 356,
* "SOC" : 95.199996948242188
* }
* },
*/
public static final String POWER_FLOW_INVERTER_1_POWER = "powerflowinverter1power";
public static final String POWER_FLOW_INVERTER_1_SOC = "powerflowinverter1soc";

// List of all Urls
public static final String INVERTER_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%&DataCollection=CommonInverterData";
public static final String POWERFLOW_REALTIME_DATA = "http://%IP%/solar_api/v1/GetPowerFlowRealtimeData.fcgi";
public static final String METER_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%&DataCollection=MeterRealtimeData";
public static final String OHMPILOT_REALTIME_DATA_URL = "http://%IP%/solar_api/v1/GetOhmPilotRealtimeData.cgi?Scope=Device&DeviceId=%DEVICEID%";

public static String getInverterDataUrl(String ip, int deviceId) {
return parseUrl(INVERTER_REALTIME_DATA_URL, ip, deviceId);
}

public static String getPowerFlowDataUrl(String ip) {
return parseUrl(POWERFLOW_REALTIME_DATA, ip);
}

public static String getMeterDataUrl(String ip, int deviceId) {
return parseUrl(METER_REALTIME_DATA_URL, ip, deviceId);
}

public static String getOhmPilotDataUrl(String ip, int deviceId) {
return parseUrl(OHMPILOT_REALTIME_DATA_URL, ip, deviceId);
}

public static String parseUrl(String url, String ip) {
return url.replace("%IP%", ip == null ? "" : ip.trim());
}

public static String parseUrl(String url, String ip, int deviceId) {
return parseUrl(url, ip).replace("%DEVICEID%", Integer.toString(deviceId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusB
*/
private MeterRealtimeResponseDTO getMeterRealtimeData(String ip, int deviceId)
throws FroniusCommunicationException {
String location = FroniusBindingConstants.METER_REALTIME_DATA_URL.replace("%IP%",
(ip != null ? ip.trim() : ""));
location = location.replace("%DEVICEID%", Integer.toString(deviceId));
String location = FroniusBindingConstants.getMeterDataUrl(ip, deviceId);
return collectDataFromUrl(MeterRealtimeResponseDTO.class, location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusB
*/
private OhmpilotRealtimeResponseDTO getOhmpilotRealtimeData(String ip, int deviceId)
throws FroniusCommunicationException {
String location = FroniusBindingConstants.OHMPILOT_REALTIME_DATA_URL.replace("%IP%",
(ip != null ? ip.trim() : ""));
location = location.replace("%DEVICEID%", Integer.toString(deviceId));
String location = FroniusBindingConstants.getOhmPilotDataUrl(ip, deviceId);
return collectDataFromUrl(OhmpilotRealtimeResponseDTO.class, location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ private void updateData(FroniusBridgeConfiguration bridgeConfiguration, FroniusB
* @return {PowerFlowRealtimeResponse} the object representation of the json response
*/
private PowerFlowRealtimeResponse getPowerFlowRealtime(String ip) throws FroniusCommunicationException {
String location = FroniusBindingConstants.POWERFLOW_REALTIME_DATA.replace("%IP%",
(ip != null ? ip.trim() : ""));
String location = FroniusBindingConstants.getPowerFlowDataUrl(ip);
return collectDataFromUrl(PowerFlowRealtimeResponse.class, location);
}

Expand All @@ -193,9 +192,7 @@ private PowerFlowRealtimeResponse getPowerFlowRealtime(String ip) throws Fronius
* @return {InverterRealtimeResponse} the object representation of the json response
*/
private InverterRealtimeResponse getRealtimeData(String ip, int deviceId) throws FroniusCommunicationException {
String location = FroniusBindingConstants.INVERTER_REALTIME_DATA_URL.replace("%IP%",
(ip != null ? ip.trim() : ""));
location = location.replace("%DEVICEID%", Integer.toString(deviceId));
String location = FroniusBindingConstants.getInverterDataUrl(ip, deviceId);
return collectDataFromUrl(InverterRealtimeResponse.class, location);
}
}

0 comments on commit 02b7731

Please sign in to comment.