Marstek B2500/Zendure Solarflow: Allow setting panel peak values to be honored by the SolarEquipmentStatusActivity

This gets rid of hardcoded 380Wp :P
This commit is contained in:
Andreas Shimokawa
2025-12-25 22:10:02 +01:00
parent d01b6bb844
commit b3e5608dd2
10 changed files with 89 additions and 11 deletions
@@ -681,6 +681,10 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_BATTERY_ALLOW_PASS_THROUGH = "battery_allow_pass_through";
public static final String PREF_OUTPUT_POWER_GRID = "output_power_grid";
public static final String PREF_OFFGRID_MODE = "offgrid_mode";
public static final String PREF_SOLAR_PANEL1_PEAK_W = "solar_panel1_peak_w";
public static final String PREF_SOLAR_PANEL2_PEAK_W = "solar_panel2_peak_w";
public static final String PREF_SOLAR_PANEL3_PEAK_W = "solar_panel3_peak_w";
public static final String PREF_SOLAR_PANEL4_PEAK_W = "solar_panel4_peak_w";
public static final String PREF_DISPLAY_ENABLED = "display_enabled";
public static final String PREF_DISPLAY_ENABLED_ALL_DAY = "display_all_day";
@@ -1365,15 +1365,19 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
setInputTypeFor(PREF_CALENDAR_SYNC_EVENTS_AMOUNT, InputType.TYPE_CLASS_NUMBER);
setInputTypeFor(PREF_CALENDAR_MAX_TITLE_LENGTH, InputType.TYPE_CLASS_NUMBER);
setInputTypeFor(PREF_CALENDAR_MAX_DESC_LENGTH, InputType.TYPE_CLASS_NUMBER);
setNumericInputTypeWithRangeFor(PREF_BATTERY_DISCHARGE_INTERVAL1_WATT, 80, 800, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_DISCHARGE_INTERVAL2_WATT, 80, 800, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_DISCHARGE_INTERVAL3_WATT, 80, 800, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_DISCHARGE_INTERVAL4_WATT, 80, 800, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_DISCHARGE_INTERVAL5_WATT, 80, 800, false);
setNumericInputTypeWithRangeFor(PREF_OUTPUT_POWER_GRID, 0, 2400, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_MINIMUM_CHARGE, 0, 100, false);
setNumericInputTypeWithRangeFor(PREF_BATTERY_MAXIMUM_CHARGE, 0, 100, false);
setNumericInputTypeWithRangeFor(PREF_SOLAR_PANEL1_PEAK_W, 0,1000,false);
setNumericInputTypeWithRangeFor(PREF_SOLAR_PANEL2_PEAK_W, 0,1000,false);
setNumericInputTypeWithRangeFor(PREF_SOLAR_PANEL3_PEAK_W, 0,1000,false);
setNumericInputTypeWithRangeFor(PREF_SOLAR_PANEL4_PEAK_W, 0,1000,false);
new PasswordCapabilityImpl().registerPreferences(getContext(), coordinator.getPasswordCapability(), this);
new HeartRateCapability().registerPreferences(getContext(), coordinator.getHeartRateMeasurementIntervals(), this);
@@ -16,6 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOLAR_PANEL1_PEAK_W;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOLAR_PANEL2_PEAK_W;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOLAR_PANEL3_PEAK_W;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SOLAR_PANEL4_PEAK_W;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -45,6 +50,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.GaugeDrawer;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class SolarEquipmentStatusActivity extends AbstractGBActivity {
public static String ACTION_SEND_SOLAR_EQUIPMENT_STATUS = "send_solar_equipment_status";
@@ -54,11 +60,19 @@ public class SolarEquipmentStatusActivity extends AbstractGBActivity {
public static String EXTRA_PANEL2_WATT = "panel2_watt";
public static String EXTRA_PANEL3_WATT = "panel3_watt";
public static String EXTRA_PANEL4_WATT = "panel4_watt";
public static String EXTRA_PANEL1_WATT_PEAK = "panel1_watt_peak";
public static String EXTRA_PANEL2_WATT_PEAK = "panel2_watt_peak";
public static String EXTRA_PANEL3_WATT_PEAK = "panel3_watt_peak";
public static String EXTRA_PANEL4_WATT_PEAK = "panel4_watt_peak";
public static String EXTRA_OUTPUT1_WATT = "output1_watt";
public static String EXTRA_OUTPUT2_WATT = "output2_watt";
public static String EXTRA_TEMP1 = "temp1";
public static String EXTRA_TEMP2 = "temp2";
public static String EXTRA_DEBUG = "debug";
private int panel1_watt_peak;
private int panel2_watt_peak;
private int panel3_watt_peak;
private int panel4_watt_peak;
private final Map<String, View> widgetMap = new HashMap<>();
private GridLayout gridLayout;
@@ -88,23 +102,23 @@ public class SolarEquipmentStatusActivity extends AbstractGBActivity {
else {
updateGaugeWidget("battery", battery_pct + "%", (float) (battery_pct / 100.0));
}
if (panel1_watt >= 0) {
updateGaugeWidget("panel1", panel1_watt + "W", (float) (panel1_watt / 380.0));
if (panel1_watt >= 0 && panel1_watt_peak > 0) {
updateGaugeWidget("panel1", panel1_watt + "W", (float) (panel1_watt / panel1_watt_peak));
} else {
removeWidget("panel1");
}
if (panel2_watt >= 0) {
updateGaugeWidget("panel2", panel2_watt + "W", (float) (panel2_watt / 380.0));
if (panel2_watt >= 0 && panel2_watt_peak > 0) {
updateGaugeWidget("panel2", panel2_watt + "W", (float) (panel2_watt / panel2_watt_peak));
} else {
removeWidget("panel2");
}
if (panel3_watt >= 0) {
updateGaugeWidget("panel3", panel3_watt + "W", (float) (panel3_watt / 380.0));
if (panel3_watt >= 0 && panel3_watt_peak > 0) {
updateGaugeWidget("panel3", panel3_watt + "W", (float) (panel3_watt / panel3_watt_peak));
} else {
removeWidget("panel3");
}
if (panel4_watt >= 0) {
updateGaugeWidget("panel4", panel4_watt + "W", (float) (panel4_watt / 380.0));
if (panel4_watt >= 0 && panel4_watt_peak > 0) {
updateGaugeWidget("panel4", panel4_watt + "W", (float) (panel4_watt / panel4_watt_peak));
} else {
removeWidget("panel4");
}
@@ -228,6 +242,13 @@ public class SolarEquipmentStatusActivity extends AbstractGBActivity {
Bundle extras = getIntent().getExtras();
if (extras != null) {
gBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
if (gBDevice != null) {
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gBDevice.getAddress()));
panel1_watt_peak = devicePrefs.getInt(PREF_SOLAR_PANEL1_PEAK_W, 400);
panel2_watt_peak = devicePrefs.getInt(PREF_SOLAR_PANEL2_PEAK_W, 400);
panel3_watt_peak = devicePrefs.getInt(PREF_SOLAR_PANEL3_PEAK_W, 400);
panel4_watt_peak = devicePrefs.getInt(PREF_SOLAR_PANEL4_PEAK_W, 400);
}
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_solar_equipment_status);
@@ -77,6 +77,8 @@ public class MarstekB2500DeviceCoordinator extends AbstractBLEDeviceCoordinator
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_solar_panel1_peak_w,
R.xml.devicesettings_solar_panel2_peak_w,
R.xml.devicesettings_battery_allow_pass_through,
R.xml.devicesettings_battery_minimum_charge,
R.xml.devicesettings_battery_discharge_5
@@ -90,6 +90,10 @@ public class SolarFlowDeviceCoordinator extends AbstractBLEDeviceCoordinator {
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_solar_panel1_peak_w,
R.xml.devicesettings_solar_panel2_peak_w,
R.xml.devicesettings_solar_panel3_peak_w,
R.xml.devicesettings_solar_panel4_peak_w,
R.xml.devicesettings_battery_minimum_charge,
R.xml.devicesettings_battery_maximum_charge,
R.xml.devicesettings_output_power_grid,
+5 -2
View File
@@ -721,7 +721,7 @@
<string name="miband_pairing_using_dummy_userdata">No valid user data given, using dummy user data for now.</string>
<string name="miband_pairing_tap_hint">When your Mi Band vibrates and blinks, tap it a few times in a row.</string>
<string name="appinstaller_install">Install</string>
<string name="discovery_connected_devices_hint">Make your device discoverable. Currently connected devices will likely not be discovered. Activate location (e.g. GPS) on Android 6+. Disable Privacy Guard for Gadgetbridge, because it may crash and reboot your phone. If no device is found after a few minutes, try again after rebooting your mobile device.</string>
<string name="discovery_connected_devices_hint">Make your device discoverable. Currently connected devices will likely not be discovered. Activate location (e.g. GPS). Disable Privacy Guard for Gadgetbridge, because it may crash and reboot your phone. If no device is found after a few minutes, try again after rebooting your mobile device.</string>
<string name="discovery_need_to_enter_authkey">This device needs a secret auth key, long press on the device to enter it. More information on the website.</string>
<string name="discovery_entered_invalid_authkey">The secret auth key you entered is invalid! Long press on the device to edit.</string>
<string name="discovery_note">Note:</string>
@@ -4482,7 +4482,10 @@
<string name="notification_pebble_js_service_text">Running Pebble app/watchface JavaScript</string>
<string name="internet_helper_banglejs_permission_missing_title">Permission missing</string>
<string name="internet_helper_banglejs_permission_missing_text">Access to the Bangle.js app loader is currently not allowed by your settings. Please go to the internet helper settings in the external integrations settings to enable it.</string>
<string name="devicetype_solarflow">SolarFlow</string>
<string name="eco">Eco</string>
<string name="prefs_title_offgrid_mode">Off-grid mode</string>
<string name="solar_panel1_peak_w">Solar panel 1 peak W</string>
<string name="solar_panel2_peak_w">Solar panel 2 peak W</string>
<string name="solar_panel3_peak_w">Solar panel 3 peak W</string>
<string name="solar_panel4_peak_w">Solar panel 4 peak W</string>
</resources>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:defaultValue="400"
android:inputType="number"
android:key="solar_panel1_peak_w"
android:title="@string/solar_panel1_peak_w"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:defaultValue="400"
android:inputType="number"
android:key="solar_panel2_peak_w"
android:title="@string/solar_panel2_peak_w"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:defaultValue="400"
android:inputType="number"
android:key="solar_panel3_peak_w"
android:title="@string/solar_panel3_peak_w"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:defaultValue="400"
android:inputType="number"
android:key="solar_panel4_peak_w"
android:title="@string/solar_panel4_peak_w"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>