diff --git a/evcharger-app/CMakeLists.txt b/evcharger-app/CMakeLists.txt index d00fe15..1199ffe 100644 --- a/evcharger-app/CMakeLists.txt +++ b/evcharger-app/CMakeLists.txt @@ -88,6 +88,7 @@ qt_add_qml_module(evcharger-app qml/DeviceScreen.qml qml/DisplaySettingsPage.qml qml/DoubleSpinBox.qml + qml/DurationEditItem.qml qml/EcoTabPage.qml qml/EditValueItem.qml qml/EthernetPage.qml diff --git a/evcharger-app/qml/DurationEditItem.qml b/evcharger-app/qml/DurationEditItem.qml new file mode 100644 index 0000000..525fea3 --- /dev/null +++ b/evcharger-app/qml/DurationEditItem.qml @@ -0,0 +1,95 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +EditValueItem { + id: root + + property int maximumHours: 168 + + function durationText(milliseconds) { + if (milliseconds === null || milliseconds === undefined) + return "—" + + let seconds = Math.max(0, Math.round(Number(milliseconds) / 1000)) + const hours = Math.floor(seconds / 3600) + seconds -= hours * 3600 + const minutes = Math.floor(seconds / 60) + seconds -= minutes * 60 + + const parts = [] + if (hours > 0) + parts.push(qsTr("%1 h").arg(hours)) + if (minutes > 0) + parts.push(qsTr("%1 min").arg(minutes)) + if (seconds > 0 || parts.length === 0) + parts.push(qsTr("%1 s").arg(seconds)) + return parts.join(" ") + } + + valueText: durationText(value) + visible: exists + fullWidth: true + + editableItem: RowLayout { + id: durationEditor + + property real value: 0 + property bool updating: false + + function loadValue() { + if (updating) + return + + updating = true + let seconds = Math.max(0, Math.round(Number(value) / 1000)) + hoursInput.value = Math.min(root.maximumHours, Math.floor(seconds / 3600)) + seconds -= hoursInput.value * 3600 + minutesInput.value = Math.floor(seconds / 60) + secondsInput.value = seconds - minutesInput.value * 60 + updating = false + } + + function updateValue() { + if (!updating) + value = ((hoursInput.value * 60 + minutesInput.value) * 60 + + secondsInput.value) * 1000 + } + + onValueChanged: loadValue() + Component.onCompleted: loadValue() + + ColumnLayout { + Label { text: qsTr("Hours") } + SpinBox { + id: hoursInput + editable: true + from: 0 + to: root.maximumHours + onValueChanged: durationEditor.updateValue() + } + } + + ColumnLayout { + Label { text: qsTr("Minutes") } + SpinBox { + id: minutesInput + editable: true + from: 0 + to: 59 + onValueChanged: durationEditor.updateValue() + } + } + + ColumnLayout { + Label { text: qsTr("Seconds") } + SpinBox { + id: secondsInput + editable: true + from: 0 + to: 59 + onValueChanged: durationEditor.updateValue() + } + } + } +} diff --git a/evcharger-app/qml/FlexibleEnergyTariffPage.qml b/evcharger-app/qml/FlexibleEnergyTariffPage.qml index bb4dd11..b0ffa00 100644 --- a/evcharger-app/qml/FlexibleEnergyTariffPage.qml +++ b/evcharger-app/qml/FlexibleEnergyTariffPage.qml @@ -1,35 +1,741 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts +import QtCharts import EVChargerApp NavigationPage { + id: page + title: qsTr("Flexible energy tariff") + property string tariffCatalogUrl: "https://data.v3.go-e.io/list" + property var tariffCatalog: [] + property var countryChoices: [] + property var providerChoices: [] + property var tariffChoices: [] + property string selectedCountry: "" + property string selectedProvider: "" + property int selectedTariffId: -1 + property bool catalogLoading: false + property string catalogError: "" + property var catalogRequest: null + + readonly property var currentTariff: tariffForId(tariffIdHelper.value) + readonly property var futurePrices: normalizePriceList(priceListHelper.value) + readonly property var futurePriceSummary: summarizePrices(futurePrices) + + onFuturePricesChanged: Qt.callLater(function() { priceChart.rebuild() }) + + function tariffForId(id) { + const numberId = Number(id) + for (let i = 0; i < tariffCatalog.length; ++i) { + if (tariffCatalog[i].id === numberId) + return tariffCatalog[i] + } + return null + } + + function countryName(code) { + try { + const name = Qt.locale("en_" + code).nativeCountryName + if (name) + return name + " (" + code + ")" + } catch (error) { + // Fall back to the ISO code if Qt has no locale for it. + } + return code + } + + function priceUnit() { + return currentTariff && currentTariff.unit ? currentTariff.unit : qsTr("ct/kWh") + } + + function priceText(value) { + if (value === null || value === undefined || isNaN(Number(value))) + return "—" + return qsTr("%1 %2").arg(Qt.locale().toString(Number(value), "f", 2)).arg(priceUnit()) + } + + function dateTimeText(unixSeconds) { + if (unixSeconds === null || unixSeconds === undefined) + return "—" + return Qt.formatDateTime(new Date(Number(unixSeconds) * 1000), "ddd, dd.MM. hh:mm") + } + + function currentPricePeriod(value) { + if (!value || value.start === undefined || value.end === undefined) + return qsTr("No current price period available") + return qsTr("%1–%2") + .arg(dateTimeText(value.start)) + .arg(Qt.formatDateTime(new Date(Number(value.end) * 1000), "hh:mm")) + } + + function normalizePriceList(value) { + const result = [] + if (!value || typeof value !== "object") + return result + + // QVariantList is exposed as an array-like sequence in QML, but is not + // necessarily recognized by JavaScript's Array.isArray(). + if (value.length !== undefined && value.marketprice === undefined) { + for (let i = 0; i < value.length; ++i) { + const entry = value[i] + if (entry && entry.start !== undefined && entry.marketprice !== undefined) + result.push(entry) + } + return result + } + + const marketPrices = value.marketprice + if (value.start === undefined || value.interval === undefined + || !marketPrices || marketPrices.length === undefined) + return result + + let start = Number(value.start) + const interval = Number(value.interval) + for (let i = 0; i < marketPrices.length; ++i) { + result.push({ + start: start, + end: start + interval, + marketprice: marketPrices[i] + }) + start += interval + } + return result + } + + function summarizePrices(prices) { + if (prices.length === 0) + return null + + let lowest = prices[0] + let highest = prices[0] + for (let i = 1; i < prices.length; ++i) { + if (Number(prices[i].marketprice) < Number(lowest.marketprice)) + lowest = prices[i] + if (Number(prices[i].marketprice) > Number(highest.marketprice)) + highest = prices[i] + } + + return { + lowest: lowest, + highest: highest, + availableUntil: prices[prices.length - 1].end + } + } + + function loadTariffCatalog() { + if (catalogLoading) + return + + catalogLoading = true + catalogError = "" + + const request = new XMLHttpRequest() + catalogRequest = request + request.onreadystatechange = function() { + if (request.readyState !== XMLHttpRequest.DONE) + return + + catalogLoading = false + catalogRequest = null + + if (request.status < 200 || request.status >= 300) { + catalogError = qsTr("Could not load the tariff catalog (HTTP %1).").arg(request.status) + return + } + + try { + const response = JSON.parse(request.responseText.toString()) + if (!Array.isArray(response)) + throw new Error("response is not an array") + + const compactCatalog = [] + for (let i = 0; i < response.length; ++i) { + const tariff = response[i] + if (tariff.id === undefined || !tariff.country + || !tariff.companyname || !tariff.name) + continue + compactCatalog.push({ + id: Number(tariff.id), + country: String(tariff.country), + companyname: String(tariff.companyname), + name: String(tariff.name), + interval: Number(tariff.p_interval), + unit: tariff.unit ? String(tariff.unit) : "ct/kWh" + }) + } + + tariffCatalog = compactCatalog + rebuildCountryChoices() + selectTariffFromDevice() + } catch (error) { + catalogError = qsTr("The tariff catalog contains invalid data: %1").arg(error) + } + } + request.open("GET", tariffCatalogUrl) + request.send() + } + + function rebuildCountryChoices() { + const seen = {} + const result = [] + for (let i = 0; i < tariffCatalog.length; ++i) { + const code = tariffCatalog[i].country + if (seen[code]) + continue + seen[code] = true + result.push({ value: code, text: countryName(code) }) + } + result.sort(function(left, right) { return left.text.localeCompare(right.text) }) + countryChoices = result + } + + function rebuildProviderChoices(preferredProvider) { + const seen = {} + const result = [] + for (let i = 0; i < tariffCatalog.length; ++i) { + const tariff = tariffCatalog[i] + if (tariff.country !== selectedCountry || seen[tariff.companyname]) + continue + seen[tariff.companyname] = true + result.push({ value: tariff.companyname, text: tariff.companyname }) + } + result.sort(function(left, right) { return left.text.localeCompare(right.text) }) + providerChoices = result + + selectedProvider = preferredProvider + let index = providerCombo.indexOfValue(selectedProvider) + if (index < 0 && result.length > 0) { + index = 0 + selectedProvider = result[0].value + } + providerCombo.currentIndex = index + rebuildTariffChoices(-1) + } + + function rebuildTariffChoices(preferredTariffId) { + const result = [] + for (let i = 0; i < tariffCatalog.length; ++i) { + const tariff = tariffCatalog[i] + if (tariff.country !== selectedCountry || tariff.companyname !== selectedProvider) + continue + const minutes = tariff.interval > 0 ? tariff.interval / 60 : 0 + result.push({ + value: tariff.id, + text: minutes > 0 + ? qsTr("%1 (%2 min)").arg(tariff.name).arg(minutes) + : tariff.name + }) + } + result.sort(function(left, right) { return left.text.localeCompare(right.text) }) + tariffChoices = result + + selectedTariffId = Number(preferredTariffId) + let index = tariffCombo.indexOfValue(selectedTariffId) + if (index < 0 && result.length > 0) { + index = 0 + selectedTariffId = result[0].value + } + tariffCombo.currentIndex = index + } + + function selectTariffFromDevice() { + if (tariffCatalog.length === 0) + return + + const tariff = tariffForId(tariffIdHelper.value) + if (tariff) { + selectedCountry = tariff.country + countryCombo.currentIndex = countryCombo.indexOfValue(selectedCountry) + rebuildProviderChoices(tariff.companyname) + rebuildTariffChoices(tariff.id) + return + } + + const localeParts = Qt.locale().name.split("_") + selectedCountry = localeParts.length > 1 ? localeParts[1] : "" + let countryIndex = countryCombo.indexOfValue(selectedCountry) + if (countryIndex < 0 && countryChoices.length > 0) { + countryIndex = 0 + selectedCountry = countryChoices[0].value + } + countryCombo.currentIndex = countryIndex + rebuildProviderChoices("") + } + + Component.onCompleted: loadTariffCatalog() + + ApiKeyValueHelper { + id: tariffIdHelper + deviceConnection: theDeviceConnection + apiKey: "awc" + onValueChanged: page.selectTariffFromDevice() + } + + ApiKeyValueHelper { + id: priceLimitHelper + deviceConnection: theDeviceConnection + apiKey: "awp" + onValueChanged: Qt.callLater(function() { priceChart.rebuild() }) + } + + ApiKeyValueHelper { + id: currentPriceHelper + deviceConnection: theDeviceConnection + apiKey: "awcp" + } + + ApiKeyValueHelper { + id: priceListHelper + deviceConnection: theDeviceConnection + apiKey: "awpl" + } + + SetValueHelper { + id: tariffSetter + deviceConnection: theDeviceConnection + apiKey: "awc" + } + + Text { + Layout.fillWidth: true + text: qsTr("Charge when electricity is below your price limit. The charger downloads prices for the selected tariff and plans charging for the cheapest periods.") + wrapMode: Text.Wrap + color: "gray" + } + GeneralOnOffSwitch { apiKey: "ful" - text: qsTr("Charge with flexible energy tariff") + text: checked ? qsTr("Flexible tariff charging on") : qsTr("Flexible tariff charging off") } GeneralOnOffSwitch { apiKey: "awe" - text: qsTr("Charge with flexible energy tariff") + text: checked ? qsTr("Flexible tariff charging on") : qsTr("Flexible tariff charging off") } NavigationItem { - ApiKeyValueHelper { - id: priceLimitHelper - deviceConnection: theDeviceConnection - apiKey: "awp" - } - - visible: logicMode.value == 4 + visible: priceLimitHelper.exists iconSource: "material-icons/grid_guides.svg" title: qsTr("Price limit") - description: qsTr("%0 ct/kWh").arg(Qt.locale().toString(priceLimitHelper.value, 'f', 1)) + description: priceText(priceLimitHelper.value) component: Component { SetPriceLimitPage { } } } + + WhiteBox { + Layout.fillWidth: true + implicitHeight: currentTariffColumn.implicitHeight + 20 + visible: tariffIdHelper.exists + + ColumnLayout { + id: currentTariffColumn + anchors.fill: parent + anchors.margins: 10 + + Text { + Layout.fillWidth: true + text: qsTr("Selected tariff") + font.bold: true + } + + Text { + Layout.fillWidth: true + text: page.currentTariff ? page.currentTariff.name + : qsTr("Tariff ID %1").arg(tariffIdHelper.value) + font.bold: true + wrapMode: Text.Wrap + } + + Text { + Layout.fillWidth: true + visible: page.currentTariff !== null + text: page.currentTariff + ? qsTr("%1 • %2") + .arg(page.currentTariff.companyname) + .arg(page.countryName(page.currentTariff.country)) + : "" + color: "gray" + wrapMode: Text.Wrap + } + } + } + + WhiteBox { + Layout.fillWidth: true + implicitHeight: priceColumn.implicitHeight + 20 + visible: currentPriceHelper.exists || priceListHelper.exists + + ColumnLayout { + id: priceColumn + anchors.fill: parent + anchors.margins: 10 + + Text { + Layout.fillWidth: true + text: qsTr("Electricity prices") + font.bold: true + } + + RowLayout { + Layout.fillWidth: true + + ColumnLayout { + Layout.fillWidth: true + + Text { + text: qsTr("Current price") + font.bold: true + } + Text { + text: currentPriceHelper.value + ? page.priceText(currentPriceHelper.value.marketprice) : "—" + font.pointSize: 18 + } + Text { + Layout.fillWidth: true + text: page.currentPricePeriod(currentPriceHelper.value) + color: "gray" + wrapMode: Text.Wrap + } + } + } + + Text { + Layout.fillWidth: true + visible: page.futurePrices.length > 0 + text: qsTr("Upcoming prices (%1 available)").arg(page.futurePrices.length) + font.bold: true + } + + ChartView { + id: priceChart + + property bool verticalPlotGeometryCaptured: false + property real automaticPlotTop: 0 + property real automaticPlotHeight: 0 + + Layout.fillWidth: true + Layout.preferredHeight: 260 + visible: page.futurePrices.length > 0 + antialiasing: true + legend.visible: true + legend.alignment: Qt.AlignBottom + title: qsTr("Price forecast (%1)").arg(page.priceUnit()) + margins.left: 0 + margins.right: 0 + margins.top: 0 + margins.bottom: 0 + + function useFullHorizontalPlotArea() { + if (width <= 0 || plotArea.height <= 0) + return + + if (!verticalPlotGeometryCaptured) { + automaticPlotTop = plotArea.y + automaticPlotHeight = plotArea.height + verticalPlotGeometryCaptured = true + } + + // Keep Qt's vertical layout for the title, time axis and + // legend, but remove its additional horizontal plot inset. + plotArea = Qt.rect(0, automaticPlotTop, + width, automaticPlotHeight) + } + + onWidthChanged: Qt.callLater(useFullHorizontalPlotArea) + + function rebuild() { + forecastSeries.clear() + priceLimitSeries.clear() + + const prices = page.futurePrices + if (prices.length === 0) + return + + let minimumPrice = Number.POSITIVE_INFINITY + let maximumPrice = Number.NEGATIVE_INFINITY + let firstStart = Number(prices[0].start) * 1000 + let lastEnd = firstStart + 3600000 + + for (let i = 0; i < prices.length; ++i) { + const entry = prices[i] + const start = Number(entry.start) * 1000 + const end = Number(entry.end) * 1000 + const price = Number(entry.marketprice) + if (!isFinite(start) || !isFinite(end) || !isFinite(price)) + continue + + // Two points per interval make the hourly/quarter-hourly + // tariff visible as steps instead of diagonal ramps. + forecastSeries.append(start, price) + forecastSeries.append(Math.max(start, end - 1), price) + minimumPrice = Math.min(minimumPrice, price) + maximumPrice = Math.max(maximumPrice, price) + lastEnd = Math.max(lastEnd, end) + } + + const limit = Number(priceLimitHelper.value) + if (priceLimitHelper.exists && isFinite(limit)) { + priceLimitSeries.append(firstStart, limit) + priceLimitSeries.append(lastEnd, limit) + minimumPrice = Math.min(minimumPrice, limit) + maximumPrice = Math.max(maximumPrice, limit) + } + + if (!isFinite(minimumPrice) || !isFinite(maximumPrice)) + return + + const padding = Math.max(0.5, (maximumPrice - minimumPrice) * 0.1) + timeAxis.min = new Date(firstStart) + timeAxis.max = new Date(lastEnd) + priceAxis.min = minimumPrice - padding + priceAxis.max = maximumPrice + padding + Qt.callLater(useFullHorizontalPlotArea) + } + + Component.onCompleted: { + rebuild() + Qt.callLater(useFullHorizontalPlotArea) + } + + DateTimeAxis { + id: timeAxis + min: new Date() + max: new Date(Date.now() + 3600000) + format: "dd.MM.\nhh:mm" + tickCount: 5 + } + + ValueAxis { + id: priceAxis + min: 0 + max: 1 + tickCount: 6 + labelFormat: "%.1f" + labelsVisible: false + lineVisible: false + } + + LineSeries { + id: forecastSeries + name: qsTr("Tariff") + axisX: timeAxis + axisY: priceAxis + width: 2 + pointsVisible: false + } + + LineSeries { + id: priceLimitSeries + name: qsTr("Price limit") + axisX: timeAxis + axisY: priceAxis + color: "#d32f2f" + width: 2 + pointsVisible: false + } + } + + Text { + Layout.fillWidth: true + visible: page.futurePriceSummary !== null + text: page.futurePriceSummary + ? qsTr("Prices available until %1") + .arg(page.dateTimeText(page.futurePriceSummary.availableUntil)) + : "" + color: "gray" + wrapMode: Text.Wrap + } + + RowLayout { + Layout.fillWidth: true + visible: page.futurePriceSummary !== null + + ColumnLayout { + Layout.fillWidth: true + + Text { + text: qsTr("Lowest") + font.bold: true + } + Text { + text: page.futurePriceSummary + ? page.priceText(page.futurePriceSummary.lowest.marketprice) : "—" + font.pointSize: 16 + } + Text { + text: page.futurePriceSummary + ? page.dateTimeText(page.futurePriceSummary.lowest.start) : "" + color: "gray" + } + } + + ColumnLayout { + Layout.fillWidth: true + + Text { + text: qsTr("Highest") + font.bold: true + } + Text { + text: page.futurePriceSummary + ? page.priceText(page.futurePriceSummary.highest.marketprice) : "—" + font.pointSize: 16 + } + Text { + text: page.futurePriceSummary + ? page.dateTimeText(page.futurePriceSummary.highest.start) : "" + color: "gray" + } + } + } + + Text { + Layout.fillWidth: true + visible: page.futurePrices.length === 0 + text: qsTr("No future prices have been received from the charger yet.") + color: "gray" + wrapMode: Text.Wrap + } + } + } + + Text { + Layout.fillWidth: true + visible: tariffIdHelper.exists + text: qsTr("Tariff selection") + font.bold: true + } + + WhiteBox { + Layout.fillWidth: true + implicitHeight: tariffSelectionColumn.implicitHeight + 20 + visible: tariffIdHelper.exists + + ColumnLayout { + id: tariffSelectionColumn + anchors.fill: parent + anchors.margins: 10 + + BusyIndicator { + Layout.alignment: Qt.AlignHCenter + visible: page.catalogLoading + running: visible + } + + Text { + Layout.fillWidth: true + visible: page.catalogLoading + text: qsTr("Loading available tariffs…") + horizontalAlignment: Text.AlignHCenter + } + + Text { + Layout.fillWidth: true + visible: page.catalogError !== "" + text: page.catalogError + color: "red" + wrapMode: Text.Wrap + } + + Button { + visible: page.catalogError !== "" + text: qsTr("Try again") + onClicked: page.loadTariffCatalog() + } + + Label { + visible: !page.catalogLoading && page.catalogError === "" + text: qsTr("Country") + font.bold: true + } + + ComboBox { + id: countryCombo + Layout.fillWidth: true + visible: !page.catalogLoading && page.catalogError === "" + model: page.countryChoices + textRole: "text" + valueRole: "value" + onActivated: { + page.selectedCountry = currentValue + page.rebuildProviderChoices("") + } + } + + Label { + visible: countryCombo.visible + text: qsTr("Provider") + font.bold: true + } + + ComboBox { + id: providerCombo + Layout.fillWidth: true + visible: countryCombo.visible + model: page.providerChoices + textRole: "text" + valueRole: "value" + onActivated: { + page.selectedProvider = currentValue + page.rebuildTariffChoices(-1) + } + } + + Label { + visible: countryCombo.visible + text: qsTr("Tariff") + font.bold: true + } + + ComboBox { + id: tariffCombo + Layout.fillWidth: true + visible: countryCombo.visible + model: page.tariffChoices + textRole: "text" + valueRole: "value" + onActivated: page.selectedTariffId = Number(currentValue) + } + + Text { + Layout.fillWidth: true + visible: countryCombo.visible + && page.selectedTariffId >= 0 + && page.tariffForId(page.selectedTariffId) + && page.tariffForId(page.selectedTariffId).interval === 900 + text: qsTr("This tariff publishes prices every 15 minutes. It requires charger firmware 60.0 or newer.") + color: "gray" + wrapMode: Text.Wrap + } + + RowLayout { + Layout.fillWidth: true + visible: countryCombo.visible + + Button { + text: qsTr("Save tariff") + enabled: page.selectedTariffId >= 0 + && page.selectedTariffId !== Number(tariffIdHelper.value) + && !tariffSetter.pending + onClicked: tariffSetter.setValue(page.selectedTariffId) + } + + BusyIndicator { + visible: tariffSetter.pending + running: visible + } + + RequestStatusText { + Layout.fillWidth: true + request: tariffSetter + } + } + } + } } diff --git a/evcharger-app/qml/GeneralOnOffSwitch.qml b/evcharger-app/qml/GeneralOnOffSwitch.qml index 3821047..caa73b5 100644 --- a/evcharger-app/qml/GeneralOnOffSwitch.qml +++ b/evcharger-app/qml/GeneralOnOffSwitch.qml @@ -26,10 +26,12 @@ WhiteCheckDelegate { id: valueChanger deviceConnection: theDeviceConnection apiKey: checkDelegate.apiKey - onResponseChanged: checkDelegate.checked = Qt.binding(function(){ return valueHelper.value; }) + onResponseChanged: checkDelegate.checked = Qt.binding(function() { + return valueHelper.value === true + }) } - checked: valueHelper.value + checked: valueHelper.value === true text: valueHelper.value === true ? qsTr("On") : valueHelper.value === false ? qsTr("Off") : qsTr("Unknown") onClicked: { diff --git a/evcharger-app/qml/PvSurplusPage.qml b/evcharger-app/qml/PvSurplusPage.qml index a778093..08aa6df 100644 --- a/evcharger-app/qml/PvSurplusPage.qml +++ b/evcharger-app/qml/PvSurplusPage.qml @@ -3,10 +3,200 @@ import QtQuick.Controls import QtQuick.Layouts NavigationPage { - title: qsTr("PV Surplus") + id: pvSurplusPage + + title: qsTr("PV surplus") + + function wattsText(value) { + return value === null || value === undefined + ? "—" : qsTr("%1 W").arg(Qt.locale().toString(value)) + } GeneralOnOffSwitch { apiKey: "fup" - text: qsTr("Charging with PV surplus") + text: checked ? qsTr("PV surplus charging on") : qsTr("PV surplus charging off") + } + + Text { + Layout.fillWidth: true + text: qsTr("Charging behavior") + font.bold: true + } + + Text { + Layout.fillWidth: true + text: qsTr("Choose when surplus charging starts, stops, and how closely it follows the available power.") + color: "gray" + wrapMode: Text.Wrap + } + + EditValueItem { + text: qsTr("Surplus required to start") + apiKey: "fst" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: 0 + to: 50000 + stepSize: 50 + } + } + + DurationEditItem { + text: qsTr("Surplus must be available for") + apiKey: "pssd" + } + + GeneralOnOffSwitch { + apiKey: "fap" + text: qsTr("Allow charging to pause when surplus is insufficient") + } + + GeneralOnOffSwitch { + apiKey: "acp" + text: qsTr("Allow charging to pause when surplus is insufficient") + } + + DurationEditItem { + text: qsTr("Minimum charging time before a pause") + apiKey: "fmt" + } + + ApiEnumEditItem { + text: qsTr("Power adjustment") + apiKey: "frm" + visible: exists + choices: [ + { value: 0, text: qsTr("Prefer power from grid") }, + { value: 1, text: qsTr("Round to nearest ampere") }, + { value: 2, text: qsTr("Prefer power to grid") } + ] + } + + GeneralOnOffSwitch { + apiKey: "csd" + text: qsTr("Recalculate from current surplus after a long interruption") + } + + Text { + Layout.fillWidth: true + Layout.topMargin: 10 + text: qsTr("Phase switching") + font.bold: true + } + + Text { + Layout.fillWidth: true + text: qsTr("Automatic switching can use one phase at low surplus and three phases at higher power.") + color: "gray" + wrapMode: Text.Wrap + } + + EditValueItem { + text: qsTr("Switch to three phases above") + apiKey: "spl3" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: 0 + to: 50000 + stepSize: 100 + } + } + + DurationEditItem { + text: qsTr("New phase request must remain valid for") + apiKey: "mpwst" + } + + DurationEditItem { + text: qsTr("Minimum time between phase switches") + apiKey: "mptwt" + } + + EditValueItem { + text: qsTr("Phase-switch hysteresis") + apiKey: "psh" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: 0 + to: 20000 + stepSize: 50 + } + } + + Text { + Layout.fillWidth: true + Layout.topMargin: 10 + text: qsTr("Grid target and advanced tuning") + font.bold: true + } + + Text { + Layout.fillWidth: true + text: qsTr("These values fine-tune whether a small amount of power is imported from or exported to the grid.") + color: "gray" + wrapMode: Text.Wrap + } + + EditValueItem { + text: qsTr("Grid power target") + apiKey: "pgt" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: -50000 + to: 50000 + stepSize: 50 + } + } + + GeneralOnOffSwitch { + apiKey: "fzf" + text: qsTr("Zero feed-in mode") + } + + EditValueItem { + text: qsTr("Zero feed-in offset") + apiKey: "zfo" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: -50000 + to: 50000 + stepSize: 50 + } + } + + EditValueItem { + text: qsTr("Grid priority offset") + apiKey: "po" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: -50000 + to: 50000 + stepSize: 50 + } + } + + EditValueItem { + text: qsTr("Stop hysteresis") + apiKey: "sh" + visible: exists + valueText: wattsText(value) + editableItem: SpinBox { + editable: true + from: 0 + to: 20000 + stepSize: 50 + } } } diff --git a/evcharger-app/qml/SetPriceLimitPage.qml b/evcharger-app/qml/SetPriceLimitPage.qml index 562ad8e..4bdb61f 100644 --- a/evcharger-app/qml/SetPriceLimitPage.qml +++ b/evcharger-app/qml/SetPriceLimitPage.qml @@ -13,8 +13,11 @@ NavigationPage { EditValueItem { text: qsTr("Price limit") - valueText: qsTr("%0 ct/kWh").arg(Qt.locale().toString(value, 'f', 1)) + valueText: value === null || value === undefined + ? "—" + : qsTr("%0 ct/kWh").arg(Qt.locale().toString(value, 'f', 1)) apiKey: "awp" + visible: exists editableItem: DoubleSpinBox { from: -1000. to: 1000. diff --git a/evcharger-app/qml/qmldir b/evcharger-app/qml/qmldir index a9518d6..244e301 100644 --- a/evcharger-app/qml/qmldir +++ b/evcharger-app/qml/qmldir @@ -36,6 +36,7 @@ EVChargerApp 1.0 DeviceListScreen.qml EVChargerApp 1.0 DeviceScreen.qml EVChargerApp 1.0 DisplaySettingsPage.qml EVChargerApp 1.0 DoubleSpinBox.qml +EVChargerApp 1.0 DurationEditItem.qml EVChargerApp 1.0 EcoTabPage.qml EVChargerApp 1.0 EditValueItem.qml EVChargerApp 1.0 EthernetPage.qml