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

add Canada to UI label for USA region #10

Merged
merged 2 commits into from
Jul 21, 2024
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

# v1.0.11
## 2024-07-21
- fix: added Canada to the custom UI
66 changes: 33 additions & 33 deletions homebridge-ui/public/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<link href="css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
<script src="js/bootstrap.min.js" crossorigin="anonymous"></script>

<div id="main" data-bs-theme="dark">
<div class="card">

<div class="card-header" id="uiButtons">
<h5 class="mb-0 text-center">
<button class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#discoverDevices"
Expand All @@ -12,7 +12,7 @@ <h5 class="mb-0 text-center">
</button>
</h5>
</div>

<div class="collapse" id="discoverDevices">
<div class="card-body">
<form>
Expand All @@ -32,7 +32,7 @@ <h5 class="mb-0 text-center">
<option value="Australia">Australia</option>
<option value="China">China</option>
<option value="Russia">Russia</option>
<option value="USA">USA</option>
<option value="USA">USA/Canada</option>
</select>
</div>
<button class="btn btn-primary btn-login" type="submit" id="discoverBtn" style="border: 0;">
Expand All @@ -59,49 +59,49 @@ <h5 class="mb-0 text-center">
</div>
</div>
</div>

</div>

<style>

.hide {
display: none;
}

.disabled {
pointer-events: none;
opacity: 0.5;
}
</style>


<script>

(async () => {
/*********************************************************************
* Initialize Javascript supporting code
*/
homebridge.showSpinner();

const { defaultConfig, defaultDeviceConfig } = await homebridge.request('/getDefaults');
const pluginConfig = await homebridge.getPluginConfig();
const configSchema = await homebridge.getPluginConfigSchema();

if (!pluginConfig.length) {
pluginConfig.push({});
}
let configuration = pluginConfig[0];

// Helper funcion to contol debug messages
function debugLog(s) {
if (configuration.uiDebug) {
console.debug(s);
}
}

debugLog(`Plugin Config:\n${JSON.stringify(configuration, null, 2)}`);
configuration = await homebridge.request('/mergeToDefault', { config: configuration });

/*********************************************************************
* showToast event listener
* Provides information from server-side to the end user.
Expand All @@ -114,13 +114,13 @@ <h5 class="mb-0 text-center">
homebridge.toast.error(event.data.msg);
}
});

/*********************************************************************
* filterOutDefaults
* returns object for config.json that has default values removed
*/
function filterOutDefaults(object, defaults) {

function deleteEmptyObjects(object) {
for (const [k, v] of Object.entries(object)) {
if (!v || typeof v !== 'object' || v === null) {
Expand All @@ -133,7 +133,7 @@ <h5 class="mb-0 text-center">
}
return object;
}

let newObject = {};
for (const [k, v] of Object.entries(object)) {
if (k === 'devices') {
Expand All @@ -150,7 +150,7 @@ <h5 class="mb-0 text-center">
}
return deleteEmptyObjects(newObject);
}

/*********************************************************************
* createForm
* Update the plugin config GUI. Does not save to config.json
Expand All @@ -163,22 +163,22 @@ <h5 class="mb-0 text-center">
await homebridge.updatePluginConfig([changes]);
});
}

createForm(configSchema, configuration);
homebridge.hideSpinner();

/*********************************************************************
* Discover button clicked....
*/
document.getElementById('discoverBtn').addEventListener('click', async (e) => {
e.preventDefault();

const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const region = document.getElementById('region').value;

homebridge.showSpinner();

console.info(`Request login...`);
try {
const devices = await homebridge.request('/discover', { username, password, region });
Expand Down Expand Up @@ -209,7 +209,7 @@ <h5 class="mb-0 text-center">
const td = tr.insertCell();
td.appendChild(document.createTextNode(state.name));
td.setAttribute('scope', 'row');

tr.insertCell().appendChild(document.createTextNode(device.uuid));
tr.insertCell().appendChild(document.createTextNode(device.mac));

Expand All @@ -227,18 +227,18 @@ <h5 class="mb-0 text-center">
id: device.uuid,
name: state.name
};

configuration.devices.push({
...defaultDeviceConfig,
...newDevice
});
debugLog(`Adding new device:\n${JSON.stringify({ ...defaultDeviceConfig, ...newDevice }, null, 2)}`);
// refresh view
createForm(configSchema, configuration);

addCell.removeChild(button);
addCell.appendChild(document.createTextNode('Added'));

homebridge.toast.success('Device added');
});
addCell.appendChild(button);
Expand All @@ -248,17 +248,17 @@ <h5 class="mb-0 text-center">
table.innerHTML += `<tr><td>No devices found!</td></tr>`;
}
document.getElementById('discoverTableWrapper').style.display = 'block';

homebridge.hideSpinner();

} catch (e) {
homebridge.toast.error(e.message);
homebridge.hideSpinner();
return;

}

});
})();
</script>

</script>
18 changes: 9 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge BlueAir Platform",
"name": "homebridge-blueair-purifier",
"version": "1.0.10",
"version": "1.0.11",
"description": "Homebridge plugin for BlueAir purifiers",
"license": "Apache-2.0",
"repository": {
Expand Down
Loading