From ac97ca8068310bbc13dae8f9fd771ec5b53a7e0f Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 24 Oct 2025 01:10:58 +0200 Subject: [PATCH] Fixed equals method and refactored vue folder --- .../web/js/vue/{components => }/App.js | 0 .../vue/components/EventTableRowComponent.js | 2 +- .../vue/{ => lib}/vue-router.esm-browser.js | 0 .../{ => lib}/vue-router.esm-browser.prod.js | 0 .../web/js/vue/{ => lib}/vue.esm-browser.js | 0 .../js/vue/{ => lib}/vue.esm-browser.prod.js | 0 hal-core/resources/web/main_index.tmpl | 30 +++++++++++++++++-- .../src/se/hal/page/JavascriptModules.java | 28 +++++++++++++++-- hal.conf.example | 4 +++ .../ecosense/EcoSenseCloudAPIClient.java | 8 ++--- .../ecosense/device/EccoCubeRadonSensor.java | 14 +++++++-- plugins/hal-vendor-tibber/build.gradle | 24 +++++++++++++++ .../plugin/vendor/tibber/TibberAPIClient.java | 30 ++++++++----------- 13 files changed, 111 insertions(+), 29 deletions(-) rename hal-core/resources/web/js/vue/{components => }/App.js (100%) rename hal-core/resources/web/js/vue/{ => lib}/vue-router.esm-browser.js (100%) rename hal-core/resources/web/js/vue/{ => lib}/vue-router.esm-browser.prod.js (100%) rename hal-core/resources/web/js/vue/{ => lib}/vue.esm-browser.js (100%) rename hal-core/resources/web/js/vue/{ => lib}/vue.esm-browser.prod.js (100%) diff --git a/hal-core/resources/web/js/vue/components/App.js b/hal-core/resources/web/js/vue/App.js similarity index 100% rename from hal-core/resources/web/js/vue/components/App.js rename to hal-core/resources/web/js/vue/App.js diff --git a/hal-core/resources/web/js/vue/components/EventTableRowComponent.js b/hal-core/resources/web/js/vue/components/EventTableRowComponent.js index 0d7afc24..743da530 100644 --- a/hal-core/resources/web/js/vue/components/EventTableRowComponent.js +++ b/hal-core/resources/web/js/vue/components/EventTableRowComponent.js @@ -17,7 +17,7 @@ export default { }, template: ` - {{ event.name }} + {{ event.name }} {{ event.configType }} {{ event.data?.valueStr }} {{ timestamp }} diff --git a/hal-core/resources/web/js/vue/vue-router.esm-browser.js b/hal-core/resources/web/js/vue/lib/vue-router.esm-browser.js similarity index 100% rename from hal-core/resources/web/js/vue/vue-router.esm-browser.js rename to hal-core/resources/web/js/vue/lib/vue-router.esm-browser.js diff --git a/hal-core/resources/web/js/vue/vue-router.esm-browser.prod.js b/hal-core/resources/web/js/vue/lib/vue-router.esm-browser.prod.js similarity index 100% rename from hal-core/resources/web/js/vue/vue-router.esm-browser.prod.js rename to hal-core/resources/web/js/vue/lib/vue-router.esm-browser.prod.js diff --git a/hal-core/resources/web/js/vue/vue.esm-browser.js b/hal-core/resources/web/js/vue/lib/vue.esm-browser.js similarity index 100% rename from hal-core/resources/web/js/vue/vue.esm-browser.js rename to hal-core/resources/web/js/vue/lib/vue.esm-browser.js diff --git a/hal-core/resources/web/js/vue/vue.esm-browser.prod.js b/hal-core/resources/web/js/vue/lib/vue.esm-browser.prod.js similarity index 100% rename from hal-core/resources/web/js/vue/vue.esm-browser.prod.js rename to hal-core/resources/web/js/vue/lib/vue.esm-browser.prod.js diff --git a/hal-core/resources/web/main_index.tmpl b/hal-core/resources/web/main_index.tmpl index 34b6eb2b..f2678740 100644 --- a/hal-core/resources/web/main_index.tmpl +++ b/hal-core/resources/web/main_index.tmpl @@ -1,3 +1,27 @@ + + @@ -53,14 +77,14 @@ diff --git a/hal-core/src/se/hal/page/JavascriptModules.java b/hal-core/src/se/hal/page/JavascriptModules.java index cd69c9ca..86b8153b 100644 --- a/hal-core/src/se/hal/page/JavascriptModules.java +++ b/hal-core/src/se/hal/page/JavascriptModules.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2025 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package se.hal.page; import se.hal.intf.HalJavascriptModule; @@ -7,7 +31,7 @@ public class JavascriptModules implements HalJavascriptModule { @Override public HalJsModule[] getJavascriptModules() { - HalWebPage.getRootNav().createSubNav("Events").createSubNav("event_overview", "Overview"); + HalWebPage.getRootNav().createSubNav("Events").createSubNav("events", "Overview"); return new HalJsModule[] { new HalJsModule("AlertStore", "./js/vue/stores/AlertStore.js"), @@ -19,7 +43,7 @@ public class JavascriptModules implements HalJavascriptModule { new HalJsModule("EventActionComponent", "./js/vue/components/EventActionComponent.js"), new HalJsModulePage("EventDetailPageComponent", "./js/vue/components/EventDetailPageComponent.js", "/event/:id"), - new HalJsModulePage("EventOverviewPageComponent", "./js/vue/components/EventOverviewPageComponent.js", "/event_overview"), + new HalJsModulePage("EventOverviewPageComponent", "./js/vue/components/EventOverviewPageComponent.js", "/events"), new HalJsModule("EventTableComponent", "./js/vue/components/EventTableComponent.js"), new HalJsModule("EventTableRowComponent", "./js/vue/components/EventTableRowComponent.js"), }; diff --git a/hal.conf.example b/hal.conf.example index 977961ba..3982e717 100644 --- a/hal.conf.example +++ b/hal.conf.example @@ -36,6 +36,10 @@ hal_core.http_port=8080 ## Tibber Plugin #hal_tibber.token= +## EcoSense plugin +#hal_vendor_ecosense.username= +#hal_vendor_ecosense.password= + ## Zigbee plugin #hal_zigbee.com_port=COM4 #hal_zigbee.dongle=CC2531|CONBEE|XBEE diff --git a/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/EcoSenseCloudAPIClient.java b/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/EcoSenseCloudAPIClient.java index 7c9f85ea..8e5e11ff 100644 --- a/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/EcoSenseCloudAPIClient.java +++ b/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/EcoSenseCloudAPIClient.java @@ -41,6 +41,8 @@ import zutil.parser.json.JSONWriter; import java.io.IOException; import java.net.MalformedURLException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; @@ -59,8 +61,6 @@ public class EcoSenseCloudAPIClient { private static final String USER_POOL_REGION = "us-west-2"; private static final String API_URL = "https://api.cloud.ecosense.io/api"; - private static SimpleDateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); //2025-10-22T14:09:29.691533 - private String username; private String password; /** The authenticated Amazon Cognito ID token. */ @@ -147,8 +147,8 @@ public class EcoSenseCloudAPIClient { ecoSenseDevice.wifiName = deviceNode.getString("wifi_name"); try { - ecoSenseDevice.lastRadonUpdateTime = DATE_PARSER.parse(deviceNode.getString("last_radon_update_time")).getTime(); - ecoSenseDevice.lastUpdateTime = DATE_PARSER.parse(deviceNode.getString("last_update_time")).getTime(); + ecoSenseDevice.lastRadonUpdateTime = LocalDateTime.parse(deviceNode.getString("last_radon_update_time")).toInstant(ZoneOffset.UTC).toEpochMilli(); + ecoSenseDevice.lastUpdateTime = LocalDateTime.parse(deviceNode.getString("last_update_time")).toInstant(ZoneOffset.UTC).toEpochMilli(); } catch (Exception e) { logger.log(Level.WARNING, "Was unable to parse timestamp from EcoSense API.", e); } diff --git a/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/device/EccoCubeRadonSensor.java b/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/device/EccoCubeRadonSensor.java index 4c0d302a..abefcded 100644 --- a/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/device/EccoCubeRadonSensor.java +++ b/plugins/hal-vendor-ecosense/src/se/hal/plugin/vendor/ecosense/device/EccoCubeRadonSensor.java @@ -30,6 +30,8 @@ import se.hal.intf.HalSensorData; import se.hal.plugin.vendor.ecosense.EcoSenseController; import se.hal.struct.devicedata.RadonSensorData; +import java.util.Objects; + /** * A sensor that calculate current radon level */ @@ -63,7 +65,15 @@ public class EccoCubeRadonSensor implements HalSensorConfig { } @Override - public boolean equals(Object obj) { - return false; + public final boolean equals(Object o) { + if (!(o instanceof EccoCubeRadonSensor)) return false; + + EccoCubeRadonSensor that = (EccoCubeRadonSensor) o; + return Objects.equals(serialNumber, that.serialNumber); + } + + @Override + public int hashCode() { + return Objects.hashCode(serialNumber); } } diff --git a/plugins/hal-vendor-tibber/build.gradle b/plugins/hal-vendor-tibber/build.gradle index 81fb360f..6c541ab2 100644 --- a/plugins/hal-vendor-tibber/build.gradle +++ b/plugins/hal-vendor-tibber/build.gradle @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2025 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + dependencies { implementation project(':hal-core') } diff --git a/plugins/hal-vendor-tibber/src/se/hal/plugin/vendor/tibber/TibberAPIClient.java b/plugins/hal-vendor-tibber/src/se/hal/plugin/vendor/tibber/TibberAPIClient.java index 3b6c11b0..dd84aa4e 100644 --- a/plugins/hal-vendor-tibber/src/se/hal/plugin/vendor/tibber/TibberAPIClient.java +++ b/plugins/hal-vendor-tibber/src/se/hal/plugin/vendor/tibber/TibberAPIClient.java @@ -35,6 +35,8 @@ import zutil.parser.json.JSONParser; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.logging.Logger; /** @@ -44,7 +46,6 @@ public class TibberAPIClient { private static final Logger logger = LogUtil.getLogger(); private static final String TIBBER_API_ENDPOINT = "https://api.tibber.com/v1-beta/gql"; - private static SimpleDateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); // 2024-12-28T23:00:00.000+01:00 private String tibberToken; @@ -80,16 +81,16 @@ public class TibberAPIClient { "consumptionUnit " + // Should be Kwh "}" + "}" + - "currentSubscription {" + - "priceInfo {" + - "current {" + - "total " + - "energy " + - "tax " + - "startsAt " + - "}" + - "}" + - "}" + +// "currentSubscription {" + +// "priceInfo {" + +// "current {" + +// "total " + +// "energy " + +// "tax " + +// "startsAt " + +// "}" + +// "}" + +// "}" + "}" + "}" + "}\"" + @@ -100,12 +101,7 @@ public class TibberAPIClient { // unitPrice=0.1507875, cost=0.3131856375, from=2024-12-28T21:00:00.000+01:00, consumption=2.077, to=2024-12-28T22:00:00.000+01:00, unitPriceVAT=0.0301575, consumptionUnit=kWh TibberConsumption consumption = new TibberConsumption(); - - try { - consumption.timestamp = DATE_PARSER.parse(data.getString("from")).getTime(); - } catch (ParseException e) { - logger.warning("Was unable to parse timestamp from Tibber API."); - } + consumption.timestamp = LocalDateTime.parse(data.getString("from")).toInstant(ZoneOffset.UTC).toEpochMilli(); if (data.get("cost") != null) { consumption.cost = data.getDouble("cost");