Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use new Home Assistant remote learn_command api #49

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
"no-unused-vars": 0,
"vue/no-v-html": 0,
"eol-last": 0,
"space-before-function-paren": 0
"space-before-function-paren": 0,
"vue/multi-word-component-names": 0,
}
}
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build & Deploy

on:
push:
branches:
- master

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- uses: actions/upload-pages-artifact@v1
with:
path: 'dist'

deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/configure-pages@v1
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ bower_components
# node-waf configuration
.lock-wscript

# Built files
dist

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@
"html.format.wrapLineLength": 0,
"css.fileExtensions": [
"scss"
]
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
2 changes: 1 addition & 1 deletion build/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const webpack = require('webpack')
const merge = require('webpack-merge')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')

const HOST = 'localhost'
Expand Down
2 changes: 1 addition & 1 deletion build/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
const merge = require('webpack-merge')
const { merge } = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

Expand Down
14 changes: 0 additions & 14 deletions dist/index.html

This file was deleted.

40 changes: 0 additions & 40 deletions dist/main.css

This file was deleted.

1 change: 0 additions & 1 deletion dist/main.js

This file was deleted.

57 changes: 0 additions & 57 deletions dist/vendor.js

This file was deleted.

63 changes: 57 additions & 6 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,75 @@ import swal from "sweetalert";
export default {
watchScoketMsgs(evData, sendTarget) { },
exportFileSaver(_jsonData) {
let blob = new Blob([JSON.stringify(_jsonData, "")], {
let blob = new Blob([JSON.stringify(_jsonData, null, 2)], {
type: "application/json;charset=utf-8"
});
FileSaver.saveAs(blob, "your-ir-code.json");
swal("Good job!", "Your file was downloaded! Please note that the device_code field only accepts positive numbers. The .json extension is not required.", "success", {
button: "Oki!"
});
},
sendBroadlinkLearnCmd(_ip) {
extractCodesFromStorageCodesFile({ storageCodesFile, irData, storageFileDeviceKey }) {
const reader = new FileReader();
reader.readAsText(storageCodesFile);
reader.addEventListener(
"load",
() => {
const storageCodesFileContents = JSON.parse(reader.result);
const codes = storageCodesFileContents && storageCodesFileContents.data[storageFileDeviceKey];

if (!codes) {
throw Error(`Can't find codes for "${storageFileDeviceKey}"`);
}

for (const irCommand of Object.values(irData)) {
irCommand.irCode = codes[irCommand.key] || irCommand.irCode;
}
},
{ once: true }
);
},
get nextSocketMessageId() {
store.commit("socketId", store.state.socketId + 1);
return store.state.socketId;
},
sendBroadlinkLearnCmd({ remoteId, command, storageFileDeviceKey }) {
const messageId = this.nextSocketMessageId;
store.state.socket.send(JSON.stringify({
id: store.state.socketId++,
id: messageId,
type: "call_service",
domain: "broadlink",
service: "learn",
service: "learn_command",
domain: "remote",
service_data: {
host: _ip
command,
command_type: "ir",
device: storageFileDeviceKey,
timeout: 10
},
target: {
entity_id: remoteId
}
}));
return messageId;
},
getRemotes() {
return new Promise((resolve) => {
const messageId = this.nextSocketMessageId;
store.state.socket.addEventListener("message", (event) => {
const data = JSON.parse(event.data);
if (data.id === messageId) {
if (data.type === "result" && data.success === true) {
resolve(
data.result.filter(entity => entity.device_id && entity.entity_id.match(/^remote\./))
);
}
}
});
store.state.socket.send(JSON.stringify({
id: messageId,
type: "config/entity_registry/list"
}));
});
},
getDupicateItem(_str1, _str2) {
let temp = [];
Expand Down
30 changes: 27 additions & 3 deletions lib/store.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import Vue from "vue";
import Vuex from "Vuex";
import Vuex from "vuex";
import VuexPersistence from "vuex-persist";
import config from "./config";

const vuexPersistence = new VuexPersistence({
reducer: (state) => {
const { socket, socketId, socketStatus, socketMsgs, ...remainingState } = state;
return remainingState;
}
});

Vue.use(Vuex);
const store = new Vuex.Store({
state: {
socket: undefined,
socketId: 70,
socketId: 0,
socketStatus: config.socketStatus.notConnect,
socketMsgs: undefined,

hassInfo: undefined
}
},
mutations: {
...generateMutations(["socket", "socketId", "socketStatus", "socketMsgs", "hassInfo"])
},
plugins: [vuexPersistence.plugin]
});

function generateMutations(stateNames) {
return Object.fromEntries(
stateNames.map(
stateName => [
stateName,
(state, newValue) => { state[stateName] = newValue; }
]
)
);
}

export default store;
Loading