@Test public void testGetPower() { assertEquals("invalid power", "888", getPower(requestInstantaneousPower("1", Version.MODEL_F523), "*#18*51*113*888##")); assertEquals("invalid power", "888", getPower(requestInstantaneousPower("1", Version.MODEL_F523_A), "*#18*71#0*113*888##")); }
static String getPower(OpenMessage request, String response) { checkArgument(request instanceof EnergyManagement, "invalid request type"); String requestValue = request.getValue(); String requestValueWithoutSuffix = requestValue.substring(0, requestValue.length() - 2); String powerValueWithPrefix = response.replace(requestValueWithoutSuffix, ""); String powerValue = powerValueWithPrefix.substring(1, powerValueWithPrefix.length() - 2); try { checkArgument(powerValue.length()>0 && powerValue.length()<8, "invalid power length"); Integer.parseInt(powerValue); } catch (Throwable t) { powerValue = ""; } return powerValue; }
EnergyManagement extends BaseOpenMessage { static String getPower(OpenMessage request, String response) { checkArgument(request instanceof EnergyManagement, "invalid request type"); String requestValue = request.getValue(); String requestValueWithoutSuffix = requestValue.substring(0, requestValue.length() - 2); String powerValueWithPrefix = response.replace(requestValueWithoutSuffix, ""); String powerValue = powerValueWithPrefix.substring(1, powerValueWithPrefix.length() - 2); try { checkArgument(powerValue.length()>0 && powerValue.length()<8, "invalid power length"); Integer.parseInt(powerValue); } catch (Throwable t) { powerValue = ""; } return powerValue; } }
EnergyManagement extends BaseOpenMessage { static String getPower(OpenMessage request, String response) { checkArgument(request instanceof EnergyManagement, "invalid request type"); String requestValue = request.getValue(); String requestValueWithoutSuffix = requestValue.substring(0, requestValue.length() - 2); String powerValueWithPrefix = response.replace(requestValueWithoutSuffix, ""); String powerValue = powerValueWithPrefix.substring(1, powerValueWithPrefix.length() - 2); try { checkArgument(powerValue.length()>0 && powerValue.length()<8, "invalid power length"); Integer.parseInt(powerValue); } catch (Throwable t) { powerValue = ""; } return powerValue; } private  EnergyManagement(String value); }
EnergyManagement extends BaseOpenMessage { static String getPower(OpenMessage request, String response) { checkArgument(request instanceof EnergyManagement, "invalid request type"); String requestValue = request.getValue(); String requestValueWithoutSuffix = requestValue.substring(0, requestValue.length() - 2); String powerValueWithPrefix = response.replace(requestValueWithoutSuffix, ""); String powerValue = powerValueWithPrefix.substring(1, powerValueWithPrefix.length() - 2); try { checkArgument(powerValue.length()>0 && powerValue.length()<8, "invalid power length"); Integer.parseInt(powerValue); } catch (Throwable t) { powerValue = ""; } return powerValue; } private  EnergyManagement(String value); static EnergyManagement requestInstantaneousPower(String where, Version version); static EnergyManagement requestDailyPower(String where, Version version); static EnergyManagement requestMonthlyPower(String where, Version version); static Func1<List<OpenSession>, List<OpenSession>> handlePowers(Action1<List<String>> onSuccess, Action0 onError); }
EnergyManagement extends BaseOpenMessage { static String getPower(OpenMessage request, String response) { checkArgument(request instanceof EnergyManagement, "invalid request type"); String requestValue = request.getValue(); String requestValueWithoutSuffix = requestValue.substring(0, requestValue.length() - 2); String powerValueWithPrefix = response.replace(requestValueWithoutSuffix, ""); String powerValue = powerValueWithPrefix.substring(1, powerValueWithPrefix.length() - 2); try { checkArgument(powerValue.length()>0 && powerValue.length()<8, "invalid power length"); Integer.parseInt(powerValue); } catch (Throwable t) { powerValue = ""; } return powerValue; } private  EnergyManagement(String value); static EnergyManagement requestInstantaneousPower(String where, Version version); static EnergyManagement requestDailyPower(String where, Version version); static EnergyManagement requestMonthlyPower(String where, Version version); static Func1<List<OpenSession>, List<OpenSession>> handlePowers(Action1<List<String>> onSuccess, Action0 onError);  }