From 643c971c514f8b9ce24955c67db7eab73a7c46ce Mon Sep 17 00:00:00 2001 From: Galadril Date: Wed, 5 Jul 2023 21:56:49 +0200 Subject: [PATCH] #695 Changes for Thermostat mode devices --- .../domoticz/adapters/DashboardAdapter.java | 61 ++++++++++++++++--- .../domoticz/adapters/UtilityAdapter.java | 49 ++++++--------- .../domoticz/fragments/Dashboard.java | 61 +++++++++++++++++++ .../nl/hnogames/domoticz/fragments/Plan.java | 61 +++++++++++++++++++ .../hnogames/domoticz/fragments/Switches.java | 57 +++++++++++++++++ .../domoticz/fragments/Utilities.java | 52 ++++++++++++++-- .../interfaces/switchesClickListener.java | 1 + .../main/res/layout/utilities_row_default.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/version.properties | 8 +-- .../domoticzapi/Containers/DevicesInfo.java | 44 ++++++++++++- .../domoticzapi/Containers/UtilitiesInfo.java | 3 + .../nl/hnogames/domoticzapi/Domoticz.java | 13 ++++ .../hnogames/domoticzapi/DomoticzIcons.java | 3 +- domoticzapi/version.properties | 2 +- 15 files changed, 367 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/nl/hnogames/domoticz/adapters/DashboardAdapter.java b/app/src/main/java/nl/hnogames/domoticz/adapters/DashboardAdapter.java index c544cecd..47b19df8 100644 --- a/app/src/main/java/nl/hnogames/domoticz/adapters/DashboardAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/adapters/DashboardAdapter.java @@ -80,6 +80,7 @@ import nl.hnogames.domoticz.utils.UsefulBits; import nl.hnogames.domoticzapi.Containers.ConfigInfo; import nl.hnogames.domoticzapi.Containers.DevicesInfo; +import nl.hnogames.domoticzapi.Containers.UtilitiesInfo; import nl.hnogames.domoticzapi.Domoticz; import nl.hnogames.domoticzapi.DomoticzIcons; import nl.hnogames.domoticzapi.DomoticzValues; @@ -248,10 +249,15 @@ private void setSwitchRowData(DevicesInfo mDeviceInfo, if (mDeviceInfo.getType() != null && mDeviceInfo.getType().equals("advertisement")) { setButtons(holder, Buttons.ADS); setAdsLayout(holder); - } else if (mDeviceInfo.getSubType() != null && mDeviceInfo.getSubType().equals(DomoticzValues.Device.Utility.SubType.SMARTWARES)) { + } else if ((mDeviceInfo.getType() != null && DomoticzValues.Device.Utility.Type.THERMOSTAT.equalsIgnoreCase(mDeviceInfo.getType())) || + (mDeviceInfo.getSubType() != null && DomoticzValues.Device.Utility.SubType.SMARTWARES.equalsIgnoreCase(mDeviceInfo.getSubType()))) { setButtons(holder, Buttons.BUTTON_ON); setThermostatRowData(mDeviceInfo, holder); - } else { + }else if ((mDeviceInfo.getType() != null && DomoticzValues.Device.Utility.Type.GENERAL.equalsIgnoreCase(mDeviceInfo.getType())) && + (mDeviceInfo.getSubType() != null && DomoticzValues.Device.Utility.SubType.THERMOSTAT_MODE.equalsIgnoreCase(mDeviceInfo.getSubType()))) { + setButtons(holder, Buttons.SELECTOR); + setThermostatRowData(mDeviceInfo, holder); + } else { switch (mDeviceInfo.getType()) { case DomoticzValues.Scene.Type.GROUP: setButtons(holder, Buttons.BUTTONS); @@ -780,6 +786,7 @@ private void setThermostatRowData(DevicesInfo mDeviceInfo, DataObjectHolder hold final double setPoint = mDeviceInfo.getSetPoint(); if (holder.isProtected) holder.buttonOn.setEnabled(false); + holder.buttonOn.setText(context.getString(R.string.set_temperature)); holder.buttonOn.setOnClickListener(v -> handleThermostatClick((DevicesInfo) v.getTag())); holder.buttonOn.setTag(mDeviceInfo); @@ -794,10 +801,45 @@ private void setThermostatRowData(DevicesInfo mDeviceInfo, DataObjectHolder hold holder.signal_level.setText(text); } - if (holder.switch_battery_level != null) { - String setPointText = - context.getString(R.string.set_point) + ": " + setPoint; - holder.switch_battery_level.setText(setPointText); + int loadMode = mDeviceInfo.getModeId(); + final ArrayList modes = mDeviceInfo.getModes(); + if (modes != null && modes.size() > 0) { + holder.spSelector.setId(mDeviceInfo.getIdx()); + holder.spSelector.setVisibility(View.VISIBLE); + ArrayAdapter dataAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, modes); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + holder.spSelector.setAdapter(dataAdapter); + holder.spSelector.setSelection(loadMode); + holder.spSelector.setTag(mDeviceInfo); + + if (holder.switch_battery_level != null) { + String modeText = + context.getString(R.string.set_mode) + ": " + modes.get(loadMode); + holder.switch_battery_level.setText(modeText); + } + + holder.spSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + if ((holder.spSelector.getId()) == mDeviceInfo.getIdx()) { + holder.spSelector.setId(mDeviceInfo.getIdx() * 3); + } else { + String selValue = holder.spSelector.getItemAtPosition(arg2).toString(); + handleModeSelectorChange(mDeviceInfo, arg2, selValue); + } + } + + @Override + public void onNothingSelected(AdapterView arg0) {} + }); + } + else{ + holder.spSelector.setVisibility(View.GONE); + if (holder.switch_battery_level != null) { + String setPointText = + context.getString(R.string.set_point) + ": " + setPoint; + holder.switch_battery_level.setText(setPointText); + } } Picasso.get().load(DomoticzIcons.getDrawableIcon( @@ -858,6 +900,12 @@ public void onAdFailedToLoad(LoadAdError errorCode) { } } + private void handleModeSelectorChange(DevicesInfo device, int id, String mode) { + if (device != null) { + listener.OnModeChanged(device, id, mode); + } + } + /** * Set the data for temperature devices * @@ -1825,7 +1873,6 @@ public void setButtons(DataObjectHolder holder, int button) { holder.contentWrapper.setVisibility(View.VISIBLE); if (holder.adview != null) holder.adview.setVisibility(View.GONE); - break; case Buttons.SELECTOR: if (holder.contentWrapper != null) holder.contentWrapper.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/nl/hnogames/domoticz/adapters/UtilityAdapter.java b/app/src/main/java/nl/hnogames/domoticz/adapters/UtilityAdapter.java index b1626d08..8d8263b1 100644 --- a/app/src/main/java/nl/hnogames/domoticz/adapters/UtilityAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/adapters/UtilityAdapter.java @@ -236,8 +236,6 @@ public void onAdFailedToLoad(LoadAdError errorCode) { } private void CreateTextRow(DataObjectHolder holder, UtilitiesInfo mUtilitiesInfo) { - holder.isProtected = mUtilitiesInfo.isProtected(); - holder.name.setText(mUtilitiesInfo.getName()); holder.data.setText(context.getString(R.string.data) + ": " + mUtilitiesInfo.getData()); holder.hardware.setText(context.getString(R.string.hardware) + ": " + mUtilitiesInfo.getHardwareName()); @@ -300,8 +298,6 @@ private void handleLogButtonClick(int idx) { } private void CreateDefaultRow(DataObjectHolder holder, UtilitiesInfo mUtilitiesInfo) { - holder.isProtected = mUtilitiesInfo.isProtected(); - holder.name.setText(mUtilitiesInfo.getName()); holder.data.setText(context.getString(R.string.data) + ": " + mUtilitiesInfo.getData()); holder.hardware.setText(context.getString(R.string.hardware) + ": " + mUtilitiesInfo.getHardwareName()); @@ -389,33 +385,13 @@ public void unLiked(LikeButton likeButton) { private void CreateThermostatRow(DataObjectHolder holder, UtilitiesInfo mUtilitiesInfo, final double setPoint) { int layoutResourceId; - holder.isProtected = mUtilitiesInfo.isProtected(); - if (holder.isProtected) - holder.on_button.setEnabled(false); - holder.on_button.setText(context.getString(R.string.set_temperature)); holder.on_button.setId(mUtilitiesInfo.getIdx()); holder.on_button.setOnClickListener(v -> handleThermostatClick(v.getId())); - int loadMode = mUtilitiesInfo.getModeId(); - final ArrayList modes = mUtilitiesInfo.getModes(); - if (modes != null && modes.size() > 0) { - holder.spSelector.setId(mUtilitiesInfo.getIdx()); - holder.spSelector.setVisibility(View.VISIBLE); - ArrayAdapter dataAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, modes); - dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - holder.spSelector.setAdapter(dataAdapter); - holder.spSelector.setSelection(loadMode); - holder.spSelector.setTag(mUtilitiesInfo); - } - else{ - holder.spSelector.setVisibility(View.GONE); - } - holder.spSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override - public void onItemSelected(AdapterView arg0, View arg1, - int arg2, long arg3) { + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { if ((holder.spSelector.getId()) == mUtilitiesInfo.getIdx()) { holder.spSelector.setId(mUtilitiesInfo.getIdx() * 3); } else { @@ -472,8 +448,26 @@ public void onNothingSelected(AdapterView arg0) {} holder.name.setText(mUtilitiesInfo.getName()); holder.hardware.setText(mUtilitiesInfo.getLastUpdate()); - holder.data.setText(context.getString(R.string.set_point) + ": " + setPoint); Picasso.get().load(DomoticzIcons.getDrawableIcon(mUtilitiesInfo.getTypeImg(), mUtilitiesInfo.getType(), mUtilitiesInfo.getSubType(), false, false, null)).into(holder.iconRow); + + int loadMode = mUtilitiesInfo.getModeId(); + final ArrayList modes = mUtilitiesInfo.getModes(); + if (modes != null && modes.size() > 0) { + holder.spSelector.setId(mUtilitiesInfo.getIdx()); + holder.spSelector.setVisibility(View.VISIBLE); + ArrayAdapter dataAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, modes); + dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + holder.spSelector.setAdapter(dataAdapter); + holder.spSelector.setSelection(loadMode); + holder.spSelector.setTag(mUtilitiesInfo); + + holder.on_button.setVisibility(View.GONE); + holder.data.setText(context.getString(R.string.set_mode) + ": " + modes.get(loadMode)); + } + else{ + holder.spSelector.setVisibility(View.GONE); + holder.data.setText(context.getString(R.string.set_point) + ": " + setPoint); + } } private void handleSelectorChange(UtilitiesInfo device, int id, String mode) { @@ -556,7 +550,6 @@ public void setButtons(DataObjectHolder holder, int button) { case Buttons.THERMOSTAT_MODE: if (holder.contentWrapper != null) holder.contentWrapper.setVisibility(View.VISIBLE); - holder.on_button.setVisibility(View.VISIBLE); holder.dayButton.setVisibility(View.VISIBLE); holder.monthButton.setVisibility(View.VISIBLE); holder.weekButton.setVisibility(View.VISIBLE); @@ -627,8 +620,6 @@ public static class DataObjectHolder extends RecyclerView.ViewHolder implements TextView data; TextView hardware; ImageView iconRow; - Boolean isProtected; - Chip dayButton; Chip monthButton; Chip yearButton; diff --git a/app/src/main/java/nl/hnogames/domoticz/fragments/Dashboard.java b/app/src/main/java/nl/hnogames/domoticz/fragments/Dashboard.java index 7db03613..d3c54482 100644 --- a/app/src/main/java/nl/hnogames/domoticz/fragments/Dashboard.java +++ b/app/src/main/java/nl/hnogames/domoticz/fragments/Dashboard.java @@ -47,6 +47,8 @@ import com.skydoves.colorpickerview.ColorPickerDialog; import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -78,6 +80,8 @@ import nl.hnogames.domoticzapi.Containers.DevicesInfo; import nl.hnogames.domoticzapi.Containers.PlanInfo; import nl.hnogames.domoticzapi.Containers.SunRiseInfo; +import nl.hnogames.domoticzapi.Containers.UserInfo; +import nl.hnogames.domoticzapi.Containers.UtilitiesInfo; import nl.hnogames.domoticzapi.Domoticz; import nl.hnogames.domoticzapi.DomoticzValues; import nl.hnogames.domoticzapi.Interfaces.DevicesReceiver; @@ -1040,6 +1044,63 @@ public void onCameraFullScreenClick(DevicesInfo device, String name) { CameraUtil.ProcessImage(mContext, device.getCameraIdx(), name); } + @Override + public void OnModeChanged(DevicesInfo utility, int mode, String modeName) { + UserInfo user = getCurrentUser(mContext, StaticHelper.getDomoticz(mContext)); + if (user != null && user.getRights() <= 0) { + UsefulBits.showSnackbar(mContext, frameLayout, mContext.getString(R.string.security_no_rights), Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_no_rights); + refreshFragment(); + return; + } + + addDebugText("OnModeChanged"); + addDebugText("Set idx " + utility.getIdx() + " to " + modeName); + if (utility.isProtected()) { + PasswordDialog passwordDialog = new PasswordDialog( + mContext, StaticHelper.getDomoticz(mContext)); + passwordDialog.show(); + passwordDialog.onDismissListener(new PasswordDialog.DismissListener() { + @Override + public void onDismiss(String password) { + SetThermostatMode(utility, mode, password); + } + + @Override + public void onCancel() {} + }); + } else { + SetThermostatMode(utility, mode, null); + } + } + + private void SetThermostatMode(DevicesInfo utility, int mode, String password) { + StaticHelper.getDomoticz(mContext).setAction(utility.getIdx(), + DomoticzValues.Json.Url.Set.THERMOSTAT, + DomoticzValues.Device.Thermostat.Action.TMODE, + mode, + password, + new setCommandReceiver() { + @Override + public void onReceiveResult(String result) { + if (result.contains("WRONG CODE")) { + UsefulBits.showSnackbar(mContext, frameLayout, R.string.security_wrong_code, Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_wrong_code); + } else { + successHandling(result, false); + processDashboard(); + } + } + + @Override + public void onError(Exception error) { + errorHandling(error); + } + }); + } + private void setState(final DevicesInfo device, int state, final String password) { StaticHelper.getDomoticz(mContext).setModalAction(device.getIdx(), state, diff --git a/app/src/main/java/nl/hnogames/domoticz/fragments/Plan.java b/app/src/main/java/nl/hnogames/domoticz/fragments/Plan.java index a047bf96..be015c53 100644 --- a/app/src/main/java/nl/hnogames/domoticz/fragments/Plan.java +++ b/app/src/main/java/nl/hnogames/domoticz/fragments/Plan.java @@ -47,6 +47,8 @@ import com.skydoves.colorpickerview.ColorPickerDialog; import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -78,6 +80,8 @@ import nl.hnogames.domoticzapi.Containers.DevicesInfo; import nl.hnogames.domoticzapi.Containers.PlanInfo; import nl.hnogames.domoticzapi.Containers.SunRiseInfo; +import nl.hnogames.domoticzapi.Containers.UserInfo; +import nl.hnogames.domoticzapi.Containers.UtilitiesInfo; import nl.hnogames.domoticzapi.Domoticz; import nl.hnogames.domoticzapi.DomoticzValues; import nl.hnogames.domoticzapi.Interfaces.DevicesReceiver; @@ -1027,6 +1031,63 @@ public void onCameraFullScreenClick(DevicesInfo device, String name) { CameraUtil.ProcessImage(mContext, device.getCameraIdx(), name); } + @Override + public void OnModeChanged(DevicesInfo utility, int mode, String modeName) { + UserInfo user = getCurrentUser(mContext, StaticHelper.getDomoticz(mContext)); + if (user != null && user.getRights() <= 0) { + UsefulBits.showSnackbar(mContext, frameLayout, mContext.getString(R.string.security_no_rights), Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_no_rights); + refreshFragment(); + return; + } + + addDebugText("OnModeChanged"); + addDebugText("Set idx " + utility.getIdx() + " to " + modeName); + if (utility.isProtected()) { + PasswordDialog passwordDialog = new PasswordDialog( + mContext, StaticHelper.getDomoticz(mContext)); + passwordDialog.show(); + passwordDialog.onDismissListener(new PasswordDialog.DismissListener() { + @Override + public void onDismiss(String password) { + SetThermostatMode(utility, mode, password); + } + + @Override + public void onCancel() {} + }); + } else { + SetThermostatMode(utility, mode, null); + } + } + + private void SetThermostatMode(DevicesInfo utility, int mode, String password) { + StaticHelper.getDomoticz(mContext).setAction(utility.getIdx(), + DomoticzValues.Json.Url.Set.THERMOSTAT, + DomoticzValues.Device.Thermostat.Action.TMODE, + mode, + password, + new setCommandReceiver() { + @Override + public void onReceiveResult(String result) { + if (result.contains("WRONG CODE")) { + UsefulBits.showSnackbar(mContext, frameLayout, R.string.security_wrong_code, Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_wrong_code); + } else { + successHandling(result, false); + processDashboard(); + } + } + + @Override + public void onError(Exception error) { + errorHandling(error); + } + }); + } + private void setState(final DevicesInfo device, int state, final String password) { StaticHelper.getDomoticz(mContext).setModalAction(device.getIdx(), state, diff --git a/app/src/main/java/nl/hnogames/domoticz/fragments/Switches.java b/app/src/main/java/nl/hnogames/domoticz/fragments/Switches.java index bfac4caf..e5f9e327 100644 --- a/app/src/main/java/nl/hnogames/domoticz/fragments/Switches.java +++ b/app/src/main/java/nl/hnogames/domoticz/fragments/Switches.java @@ -80,6 +80,7 @@ import nl.hnogames.domoticzapi.Containers.NotificationInfo; import nl.hnogames.domoticzapi.Containers.SwitchLogInfo; import nl.hnogames.domoticzapi.Containers.SwitchTimerInfo; +import nl.hnogames.domoticzapi.Containers.UserInfo; import nl.hnogames.domoticzapi.Domoticz; import nl.hnogames.domoticzapi.DomoticzValues; import nl.hnogames.domoticzapi.Interfaces.DevicesReceiver; @@ -775,6 +776,62 @@ public void onCameraFullScreenClick(DevicesInfo device, String name) { CameraUtil.ProcessImage(mContext, device.getCameraIdx(), name); } + @Override + public void OnModeChanged(DevicesInfo utility, int mode, String modeName) { + UserInfo user = getCurrentUser(mContext, StaticHelper.getDomoticz(mContext)); + if (user != null && user.getRights() <= 0) { + UsefulBits.showSnackbar(mContext, frameLayout, mContext.getString(R.string.security_no_rights), Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_no_rights); + refreshFragment(); + return; + } + + addDebugText("OnModeChanged"); + addDebugText("Set idx " + utility.getIdx() + " to " + modeName); + if (utility.isProtected()) { + PasswordDialog passwordDialog = new PasswordDialog( + mContext, StaticHelper.getDomoticz(mContext)); + passwordDialog.show(); + passwordDialog.onDismissListener(new PasswordDialog.DismissListener() { + @Override + public void onDismiss(String password) { + SetThermostatMode(utility, mode, password); + } + + @Override + public void onCancel() {} + }); + } else { + SetThermostatMode(utility, mode, null); + } + } + + private void SetThermostatMode(DevicesInfo utility, int mode, String password) { + StaticHelper.getDomoticz(mContext).setAction(utility.getIdx(), + DomoticzValues.Json.Url.Set.THERMOSTAT, + DomoticzValues.Device.Thermostat.Action.TMODE, + mode, + password, + new setCommandReceiver() { + @Override + public void onReceiveResult(String result) { + if (result.contains("WRONG CODE")) { + UsefulBits.showSnackbar(mContext, frameLayout, R.string.security_wrong_code, Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_wrong_code); + } else { + successHandling(result, false); + } + } + + @Override + public void onError(Exception error) { + errorHandling(error); + } + }); + } + private void setState(final DevicesInfo device, int state, final String password) { StaticHelper.getDomoticz(mContext).setModalAction(device.getIdx(), state, diff --git a/app/src/main/java/nl/hnogames/domoticz/fragments/Utilities.java b/app/src/main/java/nl/hnogames/domoticz/fragments/Utilities.java index 95018e43..f4476777 100644 --- a/app/src/main/java/nl/hnogames/domoticz/fragments/Utilities.java +++ b/app/src/main/java/nl/hnogames/domoticz/fragments/Utilities.java @@ -36,6 +36,8 @@ import com.afollestad.materialdialogs.DialogAction; import com.google.android.material.snackbar.Snackbar; +import org.json.JSONObject; + import java.util.ArrayList; import nl.hnogames.domoticz.GraphActivity; @@ -191,6 +193,7 @@ private void createListView() { adapter.setData(AddAdsDevice(mUtilitiesInfos)); adapter.notifyDataSetChanged(); } + if (mItemTouchHelper == null) { mItemTouchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback(adapter, isTablet)); } @@ -294,6 +297,18 @@ private void updateThermostatSetPointValue(int idx, double newSetPoint) { notifyDataSetChanged(); } + private void updateThermostatModeValue(int idx, int newMode) { + addDebugText("updateThermostatModeValue"); + + for (UtilitiesInfo info : mUtilitiesInfos) { + if (info.getIdx() == idx) { + info.setModeId(newMode); + break; + } + } + + notifyDataSetChanged(); + } /** * Notifies the list view adapter the data has changed and refreshes the list view @@ -338,7 +353,7 @@ public void onClick(UtilitiesInfo utility) { } @Override - public void OnModeChanged(UtilitiesInfo utility, int id, String mode) { + public void OnModeChanged(UtilitiesInfo utility, int mode, String modeName) { UserInfo user = getCurrentUser(mContext, StaticHelper.getDomoticz(mContext)); if (user != null && user.getRights() <= 0) { UsefulBits.showSnackbar(mContext, frameLayout, mContext.getString(R.string.security_no_rights), Snackbar.LENGTH_SHORT); @@ -349,16 +364,43 @@ public void OnModeChanged(UtilitiesInfo utility, int id, String mode) { } addDebugText("OnModeChanged"); - addDebugText("Set idx " + utility.getIdx() + " to " + mode); + addDebugText("Set idx " + utility.getIdx() + " to " + modeName); + + if (utility.isProtected()) { + PasswordDialog passwordDialog = new PasswordDialog( + mContext, StaticHelper.getDomoticz(mContext)); + passwordDialog.show(); + passwordDialog.onDismissListener(new PasswordDialog.DismissListener() { + @Override + public void onDismiss(String password) { + SetThermostatMode(utility, mode, password); + } + + @Override + public void onCancel() {} + }); + } else { + SetThermostatMode(utility, mode, null); + } + } + + private void SetThermostatMode(UtilitiesInfo utility, int mode, String password) { StaticHelper.getDomoticz(mContext).setAction(utility.getIdx(), DomoticzValues.Json.Url.Set.THERMOSTAT, DomoticzValues.Device.Thermostat.Action.TMODE, - id, - null, + mode, + password, new setCommandReceiver() { @Override public void onReceiveResult(String result) { - successHandling(result, false); + if (result.contains("WRONG CODE")) { + UsefulBits.showSnackbar(mContext, frameLayout, R.string.security_wrong_code, Snackbar.LENGTH_SHORT); + if (getActivity() instanceof MainActivity) + ((MainActivity) getActivity()).Talk(R.string.security_wrong_code); + } else { + updateThermostatModeValue(utility.getIdx(), mode); + successHandling(result, false); + } } @Override diff --git a/app/src/main/java/nl/hnogames/domoticz/interfaces/switchesClickListener.java b/app/src/main/java/nl/hnogames/domoticz/interfaces/switchesClickListener.java index 0b410537..c45dc576 100644 --- a/app/src/main/java/nl/hnogames/domoticz/interfaces/switchesClickListener.java +++ b/app/src/main/java/nl/hnogames/domoticz/interfaces/switchesClickListener.java @@ -62,4 +62,5 @@ public interface switchesClickListener { boolean onItemLongClicked(DevicesInfo device); void onCameraFullScreenClick(DevicesInfo device, String name); + void OnModeChanged(DevicesInfo utility, int id, String mode); } \ No newline at end of file diff --git a/app/src/main/res/layout/utilities_row_default.xml b/app/src/main/res/layout/utilities_row_default.xml index b8871a04..4bd51726 100644 --- a/app/src/main/res/layout/utilities_row_default.xml +++ b/app/src/main/res/layout/utilities_row_default.xml @@ -152,6 +152,7 @@ Status RGB color or warm white + Mode Set point Set point min value Min temperature that you can set for your thermostat diff --git a/app/version.properties b/app/version.properties index 5dfc4baa..bc8f866f 100644 --- a/app/version.properties +++ b/app/version.properties @@ -1,4 +1,4 @@ -#Wed Jul 05 13:12:52 CEST 2023 -VERSION_BUILD=9374 -VERSION_CODE=675 -VERSION_PATCH=364 +#Wed Jul 05 21:54:03 CEST 2023 +VERSION_BUILD=9388 +VERSION_CODE=676 +VERSION_PATCH=365 diff --git a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/DevicesInfo.java b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/DevicesInfo.java index 8e1487e8..79ea9f15 100644 --- a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/DevicesInfo.java +++ b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/DevicesInfo.java @@ -61,6 +61,8 @@ public class DevicesInfo implements Comparable, Serializable { private String HardwareName; private String TypeImg; private String PlanID; + private String Modes; + private int Mode; private int batteryLevel; private int maxDimLevel; private int signalLevel; @@ -112,7 +114,6 @@ public DevicesInfo(JSONObject row) throws JSONException { } catch (Exception e) { level = 0; } - if (row.has("Rain")) Rain = row.getString("Rain"); if (row.has("RainRate")) @@ -129,7 +130,18 @@ public DevicesInfo(JSONObject row) throws JSONException { Chill = row.getString("Chill"); if (row.has("Speed")) Speed = row.getString("Speed"); - + if (row.has("Modes")) { + Modes = row.getString("Modes"); + if (UsefulBits.isBase64Encoded(Modes)) + Modes = UsefulBits.decodeBase64(Modes); + } + if (row.has("Mode")) { + try { + Mode = row.getInt("Mode"); + } catch (Exception ex) { + Mode = 0; + } + } if (row.has("DewPoint")) { try { DewPoint = row.getLong("DewPoint"); @@ -542,6 +554,34 @@ public Date getLastUpdateDateTime() { return null; } + public int getModeId() { + return Mode; + } + public void setModeId(int mode) { + Mode = mode; + } + + public void SetModeId(int mode) { + this.Mode = mode; + } + + public ArrayList getModes() { + if (UsefulBits.isEmpty(Modes)) + return null; + String[] names = Pattern.compile(";", Pattern.LITERAL).split(Modes); + + ArrayList newNames = new ArrayList(); + for (String value : names) { + try { + Integer.parseInt(value); + } catch (NumberFormatException e) { + newNames.add(Html.fromHtml(value).toString()); + } + } + + return newNames; + } + public String getJsonObject() { return this.jsonObject; } diff --git a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/UtilitiesInfo.java b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/UtilitiesInfo.java index 651b80d9..5e5a9cde 100644 --- a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/UtilitiesInfo.java +++ b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Containers/UtilitiesInfo.java @@ -160,6 +160,9 @@ public void setSignalLevel(int signalLevel) { public int getModeId() { return Mode; } + public void setModeId(int mode) { + Mode = mode; + } public void SetModeId(int mode) { this.Mode = mode; diff --git a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Domoticz.java b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Domoticz.java index deb5b80f..dc7cc065 100644 --- a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Domoticz.java +++ b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/Domoticz.java @@ -637,6 +637,19 @@ public void setAction(int idx, GetRequest(parser, url, true); } + @SuppressWarnings("SpellCheckingInspection") + public void setAction(int idx, + int jsonUrl, + int jsonAction, + double value, + setCommandReceiver receiver) { + setCommandParser parser = new setCommandParser(receiver); + String url = mDomoticzUrls.constructSetUrl(jsonUrl, idx, jsonAction, value); + + Log.v(TAG, "Action: " + url); + GetRequest(parser, url, true); + } + @SuppressWarnings("SpellCheckingInspection") public void setRGBColorAction(int idx, int jsonUrl, diff --git a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/DomoticzIcons.java b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/DomoticzIcons.java index 523ed540..6e42c8bd 100644 --- a/domoticzapi/src/main/java/nl/hnogames/domoticzapi/DomoticzIcons.java +++ b/domoticzapi/src/main/java/nl/hnogames/domoticzapi/DomoticzIcons.java @@ -175,11 +175,10 @@ public static int getDrawableIcon(String imgType, String Type, String switchType case "alert": return R.drawable.loudspeakers; case "gauge": + case "mode": return R.drawable.thermostat; case "clock": return R.drawable.clock_b; - case "mode": - return R.drawable.defaultimage; case "utility": case "scale": return R.drawable.solar_panel; diff --git a/domoticzapi/version.properties b/domoticzapi/version.properties index 8ca874ca..3ccbf88c 100644 --- a/domoticzapi/version.properties +++ b/domoticzapi/version.properties @@ -1,4 +1,4 @@ -#Wed Jul 05 13:12:53 CEST 2023 +#Wed Jul 05 21:54:03 CEST 2023 VERSION_BUILD=3675 VERSION_CODE=254 VERSION_PATCH=254