Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Nov 15, 2024
1 parent 1fc8a8e commit 80a81c8
Show file tree
Hide file tree
Showing 277 changed files with 3,014 additions and 9,191 deletions.
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
13 changes: 1 addition & 12 deletions src/components/OpenwbBaseAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ export default {
props: {
subtype: {
validator: function (value) {
return (
[
"info",
"success",
"warning",
"danger",
"primary",
"secondary",
"light",
"dark",
].indexOf(value) !== -1
);
return ["info", "success", "warning", "danger", "primary", "secondary", "light", "dark"].indexOf(value) !== -1;
},
default: "secondary",
},
Expand Down
20 changes: 4 additions & 16 deletions src/components/OpenwbBaseArrayInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@
class="form-control"
v-bind="$attrs"
@keyup.enter="addTag"
>
/>
<div class="input-group-append">
<div
class="input-group-text"
:class="
newTagValid
? 'bg-success clickable'
: 'not-clickable'
"
:class="newTagValid ? 'bg-success clickable' : 'not-clickable'"
@click="addTag"
>
<slot name="input-add">
Expand Down Expand Up @@ -92,12 +88,7 @@ import {
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(
fasTag,
fasTimesCircle,
fasPlus,
fasInfoCircle,
);
library.add(fasTag, fasTimesCircle, fasPlus, fasInfoCircle);
export default {
name: "OpenwbArrayInput",
Expand Down Expand Up @@ -139,10 +130,7 @@ export default {
},
newTagValid: {
get() {
return (
this.newTag.length > 0 &&
!this.value.includes(this.newTag)
);
return this.newTag.length > 0 && !this.value.includes(this.newTag);
},
},
},
Expand Down
13 changes: 3 additions & 10 deletions src/components/OpenwbBaseButtonGroupInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,21 @@
v-for="button in buttons"
:key="button.value"
class="btn"
:class="[
value == button.buttonValue ? 'active' : '',
button.class ? button.class : 'btn-outline-info',
]"
:class="[value == button.buttonValue ? 'active' : '', button.class ? button.class : 'btn-outline-info']"
>
<input
v-model="value"
type="radio"
:value="button.buttonValue"
v-bind="$attrs"
>
/>
<slot :name="'label-' + button.buttonValue">
{{ button.text }}
</slot>
<font-awesome-icon
fixed-width
:icon="['fas', 'check']"
:style="[
value == button.buttonValue
? 'visibility: visible'
: 'visibility: hidden',
]"
:style="[value == button.buttonValue ? 'visibility: visible' : 'visibility: hidden']"
/>
</label>
</div>
Expand Down
13 changes: 1 addition & 12 deletions src/components/OpenwbBaseButtonInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ export default {
subtype: {
type: String,
validator: function (value) {
return (
[
"info",
"success",
"warning",
"danger",
"primary",
"secondary",
"light",
"dark",
].indexOf(value) !== -1
);
return ["info", "success", "warning", "danger", "primary", "secondary", "light", "dark"].indexOf(value) !== -1;
},
default: "secondary",
},
Expand Down
24 changes: 4 additions & 20 deletions src/components/OpenwbBaseCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
<font-awesome-icon
v-if="collapsible"
fixed-width
:icon="
isCollapsed
? ['fas', 'chevron-right']
: ['fas', 'chevron-down']
"
:icon="isCollapsed ? ['fas', 'chevron-right'] : ['fas', 'chevron-down']"
/>
</span>
</div>
Expand All @@ -59,10 +55,7 @@

<script>
import { library } from "@fortawesome/fontawesome-svg-core";
import {
faChevronRight as fasChevronRight,
faChevronDown as fasChevronDown,
} from "@fortawesome/free-solid-svg-icons";
import { faChevronRight as fasChevronRight, faChevronDown as fasChevronDown } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(fasChevronRight, fasChevronDown);
Expand All @@ -78,17 +71,8 @@ export default {
subtype: {
validator: function (value) {
return (
[
"info",
"success",
"warning",
"danger",
"primary",
"secondary",
"light",
"dark",
"pink",
].indexOf(value) !== -1
["info", "success", "warning", "danger", "primary", "secondary", "light", "dark", "pink"].indexOf(value) !==
-1
);
},
default: "secondary",
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenwbBaseCheckboxInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class="form-control"
type="checkbox"
v-bind="$attrs"
>
/>
</div>
</template>
</openwb-base-setting-element>
Expand Down
27 changes: 10 additions & 17 deletions src/components/OpenwbBaseCopyToClipboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

<script>
import { library } from "@fortawesome/fontawesome-svg-core";
import {
faClipboard as fasClipboard,
faClipboardCheck as fasClipboardCheck,
} from "@fortawesome/free-solid-svg-icons";
import { faClipboard as fasClipboard, faClipboardCheck as fasClipboardCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(fasClipboard, fasClipboardCheck);
Expand All @@ -42,20 +39,16 @@ export default {
// event.target may be our icon, so we use a ref here
console.debug(this.$refs["slot-wrapper"].innerText);
if (this.clipboardApiAvailable) {
navigator.clipboard
.writeText(this.$refs["slot-wrapper"].innerText)
.then(
() => {
this.isCopied = true;
},
() => {
console.error("copy to clipboard failed");
},
);
} else {
console.debug(
"clipboard api not supported/enabled, fallback to select",
navigator.clipboard.writeText(this.$refs["slot-wrapper"].innerText).then(
() => {
this.isCopied = true;
},
() => {
console.error("copy to clipboard failed");
},
);
} else {
console.debug("clipboard api not supported/enabled, fallback to select");
if (window.getSelection) {
console.debug("using 'window.getSelection'");
const selection = window.getSelection();
Expand Down
Loading

0 comments on commit 80a81c8

Please sign in to comment.