Skip to content

Commit

Permalink
Merge pull request #580 from benderl/fix-formatting
Browse files Browse the repository at this point in the history
Fix formatting
  • Loading branch information
benderl authored Nov 15, 2024
2 parents 617123a + 80a81c8 commit 2068b73
Show file tree
Hide file tree
Showing 282 changed files with 3,086 additions and 9,225 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public/modules/legacy_smart_home/**
public/dataProtection-usageTerms.html
8 changes: 7 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{}
{
"printWidth": 120,
"singleQuote": false,
"singleAttributePerLine": true,
"trailingComma": "all",
"arrowParens": "always"
}
31 changes: 25 additions & 6 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import js from "@eslint/js"
import pluginVue from "eslint-plugin-vue"
import js from "@eslint/js";
import pluginVue from "eslint-plugin-vue";
import prettier from "eslint-plugin-prettier";
import prettierConfig from "eslint-config-prettier";

export default [
js.configs.recommended,
...pluginVue.configs['flat/recommended'],
...pluginVue.configs["flat/recommended"],
{
ignores: ["public/modules/legacy_smart_home/"],
ignores: ["public/modules/legacy_smart_home/", "public/dataProtection-usageTerms.html"],
},
{
files: ["**/*.{vue,js,jsx,cjs,mjs}"],
ignores: ["public/modules/legacy_smart_home/**", "public/dataProtection-usageTerms.html"],
languageOptions: {
ecmaVersion: "latest",
},
}
]
plugins: {
prettier,
},
rules: {
...prettierConfig.rules,
"prettier/prettier": [
"error",
{
printWidth: 120,
singleQuote: false,
singleAttributePerLine: true,
trailingComma: "all",
arrowParens: "always",
},
],
},
},
];
61 changes: 35 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/test-utils": "^2.4.6",
"eslint": "^9.14.0",
"eslint-plugin-vue": "^9.30.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^9.31.0",
"jsdom": "^24.1.3",
"postcss": "^8.4.47",
"postcss-preset-env": "^9.6.0",
Expand Down
84 changes: 20 additions & 64 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export default {
connection: {
protocol: location.protocol == "https:" ? "wss" : "ws",
host: location.hostname,
port:
parseInt(location.port) ||
(location.protocol == "https:" ? 443 : 80),
port: parseInt(location.port) || (location.protocol == "https:" ? 443 : 80),
endpoint: "/ws",
connectTimeout: 4000,
reconnectPeriod: 4000,
Expand Down Expand Up @@ -85,25 +83,20 @@ export default {
*/
async saveValues(topicsToSave = undefined) {
function sleep(milliseconds) {
return new Promise((resolve) =>
setTimeout(resolve, milliseconds),
);
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
console.debug("saving values...");
this.$store.state.local.savingData = true;
// collect data
let topics = {};
if (topicsToSave === undefined) {
console.debug(
"no topics defined, so save everything we have in store",
);
console.debug("no topics defined, so save everything we have in store");
topics = this.$store.state.mqtt;
} else {
if (Array.isArray(topicsToSave)) {
topicsToSave.forEach((topicToSave) => {
topics[topicToSave] =
this.$store.state.mqtt[topicToSave];
topics[topicToSave] = this.$store.state.mqtt[topicToSave];
});
} else {
console.error("expected array, got ", typeof topicsToSave);
Expand Down Expand Up @@ -143,11 +136,7 @@ export default {
* @param {Object} event - Command object to send
*/
sendCommand(event) {
this.doPublish(
"openWB/set/command/" + this.client.options.clientId + "/todo",
event,
false,
);
this.doPublish("openWB/set/command/" + this.client.options.clientId + "/todo", event, false);
},
/**
* Establishes a connection to the configured broker
Expand All @@ -160,8 +149,7 @@ export default {
// mqtts encrypted TCP connection
// wxs WeChat mini app connection
// alis Alipay mini app connection
const { protocol, host, port, endpoint, ...options } =
this.connection;
const { protocol, host, port, endpoint, ...options } = this.connection;
const connectUrl = `${protocol}://${host}:${port}${endpoint}`;
console.debug("connecting to broker:", connectUrl);
try {
Expand All @@ -170,10 +158,7 @@ export default {
console.error("mqtt.connect error", error);
}
this.client.on("connect", () => {
console.debug(
"Connection succeeded! ClientId: ",
this.client.options.clientId,
);
console.debug("Connection succeeded! ClientId: ", this.client.options.clientId);
// required for route guards
this.doSubscribe(["openWB/system/usage_terms_acknowledged"]);
this.doSubscribe(["openWB/system/installAssistantDone"]);
Expand All @@ -190,11 +175,7 @@ export default {
try {
myPayload = JSON.parse(message.toString());
} catch (error) {
console.debug(
"Json parsing failed, fallback to string: ",
topic,
error,
);
console.debug("Json parsing failed, fallback to string: ", topic, error);
myPayload = message.toString();
}
this.$store.commit("updateTopic", {
Expand All @@ -216,10 +197,7 @@ export default {
this.$store.commit("addSubscription", topic);
if (this.$store.getters.subscriptionCount(topic) == 1) {
if (topic.includes("#") || topic.includes("+")) {
console.debug(
"skipping init of wildcard topic:",
topic,
);
console.debug("skipping init of wildcard topic:", topic);
} else {
this.$store.commit("addTopic", {
topic: topic,
Expand Down Expand Up @@ -249,18 +227,10 @@ export default {
});
if (topic.includes("#") || topic.includes("+")) {
console.debug("expanding wildcard topic:", topic);
Object.keys(this.getWildcardTopics(topic)).forEach(
(wildcardTopic) => {
console.debug(
"removing wildcardTopic:",
wildcardTopic,
);
this.$store.commit(
"removeTopic",
wildcardTopic,
);
},
);
Object.keys(this.getWildcardTopics(topic)).forEach((wildcardTopic) => {
console.debug("removing wildcardTopic:", wildcardTopic);
this.$store.commit("removeTopic", wildcardTopic);
});
} else {
console.debug("removing topic:", topic);
this.$store.commit("removeTopic", topic);
Expand All @@ -275,25 +245,16 @@ export default {
qos: qos,
retain: retain,
};
this.client.publish(
topic,
JSON.stringify(payload),
options,
(error) => {
if (error) {
console.error("Publish error", error);
}
},
);
this.client.publish(topic, JSON.stringify(payload), options, (error) => {
if (error) {
console.error("Publish error", error);
}
});
},
postClientMessage(message, type = "secondary") {
console.debug("postMessage:", message, type);
const timestamp = Date.now();
const topic =
"openWB/command/" +
this.mqttClientId +
"/messages/" +
timestamp;
const topic = "openWB/command/" + this.mqttClientId + "/messages/" + timestamp;
this.$store.commit({
type: "addTopic",
topic: topic,
Expand All @@ -312,12 +273,7 @@ export default {
if (!isRegex) {
// build a valid regex based on the provided wildcard topic
baseTopicRegex =
"^" +
baseTopic
.replaceAll("/", "\\/")
.replaceAll("+", "[^+/]+")
.replaceAll("#", "[^#/]+") +
"$";
"^" + baseTopic.replaceAll("/", "\\/").replaceAll("+", "[^+/]+").replaceAll("#", "[^#/]+") + "$";
}
// filter and return all topics matching our regex
return Object.keys(this.$store.state.mqtt)
Expand Down
Loading

0 comments on commit 2068b73

Please sign in to comment.