Skip to content

Commit

Permalink
Merge pull request #25 from asgothian/Temp
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
asgothian authored Jan 30, 2025
2 parents 82bf0ec + 1371f9d commit 9c12225
Show file tree
Hide file tree
Showing 17 changed files with 989 additions and 407 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ admin/i18n/*/flat.txt
debugidentify.js
.devcontainer
docs

*.png
.dev-server/
127 changes: 105 additions & 22 deletions admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ function getGroupCard(dev) {
<button name="editgrp" class="right btn-flat btn-small">
<i class="material-icons icon-green">edit</i>
</button>
<button name="swapimage" class="right btn-flat btn-small tooltipped" title="Edit">
<i class="material-icons icon-black">image</i>
</button>
</div>
</div>
</div>
Expand All @@ -218,7 +221,7 @@ function getCard(dev) {
id = dev._id,
type = (dev.common.type ? dev.common.type : 'unknown'),
type_url = (dev.common.type ? sanitizeModelParameter(dev.common.type) : 'unknown'),
img_src = dev.icon || dev.common.icon,
img_src = dev.common.icon || dev.icon,
rooms = [],
isActive = (dev.common.deactivated ? false : true),
lang = systemLang || 'en',
Expand Down Expand Up @@ -285,6 +288,9 @@ function getCard(dev) {
<button name="edit" class="right btn-flat btn-small tooltipped" title="Edit">
<i class="material-icons icon-green">edit</i>
</button>
<button name="swapimage" class="right btn-flat btn-small tooltipped" title="Select Image">
<i class="material-icons icon-black">image</i>
</button>
<button name="reconfigure" class="right btn-flat btn-small tooltipped" title="Reconfigure">
<i class="material-icons icon-red">sync</i>
</button>
Expand Down Expand Up @@ -627,6 +633,13 @@ function showDevices() {
const name = getDevName(dev_block);
toggleDebugDevice(id, name);

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
function toggleDebugDevice
.
});

$('.card-reveal-buttons button[name=\'swapimage\']').click(function () {
const dev_block = $(this).parents('div.device');
const id = getDevId(dev_block);
selectImageOverride(id);
});

$('.card-reveal-buttons button[name=\'editgrp\']').click(function () {
const dev_block = $(this).parents('div.device');
const id = dev_block.attr('id').replace(namespace + '.group_', '');
Expand Down Expand Up @@ -772,7 +785,6 @@ function checkDebugDevice(id) {
return -1;
}
async function toggleDebugDevice(id) {
console.warn('toggleDebugDevices with id ' + id);
sendTo(namespace, 'setDeviceDebug', {id:id}, function (msg) {
sendTo(namespace, 'getDebugDevices', {}, function(msg) {
if (msg && typeof (msg.debugDevices == 'array')) {
Expand All @@ -786,6 +798,58 @@ async function toggleDebugDevice(id) {
});
}


function updateDeviceImage(device, image, global) {
console.warn(`update device image : ${JSON.stringify(device)} : ${image} : ${global}`);
sendTo(namespace, 'updateDeviceImage', {target: device, image: image, global:global}, function(msg) {
if (msg && msg.hasOwnProperty.error) {
showMessage(msg.error, _('Error'));
}
getDevices();
});
}

async function selectImageOverride(id) {
const dev = devices.find((d) => d._id == id);
let localImages = undefined;

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable localImages.
const selectItems= [''];
sendTo(namespace, 'getLocalImages', {}, function(msg) {
if (msg && msg.imageData) {
// const element = $('#localimages');
const imagedata = msg.imageData;
imagedata.unshift( { file:'none', name:'default', data:dev.common.icon || dev.icon});

list2select('#images', imagedata, selectItems,
function (key, image) {
return image.name
},
function (key, image) {
return image.file;
},
function (key, image) {
if (image.file == 'none') {
return `data-icon="${image.data}"`;
} else {
return `data-icon="data:image/png; base64, ${image.data}"`;
}
},
);

$('#chooseimage a.btn[name=\'save\']').unbind('click');
$('#chooseimage a.btn[name=\'save\']').click(() => {
const image = $('#chooseimage').find('#images option:selected').val();
const global = $('#chooseimage').find('#globaloverride').prop('checked');
console.warn(`update device image : ${id} : ${image} : ${global}`);
updateDeviceImage(id, image, global);
// console.warn(`selected image file name is ${newName}`);
// updateDev(id, newName, groupsbyid);
});
$('#chooseimage').modal('open');
Materialize.updateTextFields();
}
});
}

function getDevices() {
getCoordinatorInfo();
sendTo(namespace, 'getDebugDevices', {}, function(msg) {
Expand Down Expand Up @@ -835,14 +899,26 @@ function getMap() {
});
}

function getRandomExtPanID()
{
const bytes = [];
for (var i = 0;i<16;i++) {
bytes.push(Math.floor(Math.random() * 16).toString(16));
}
return bytes.join('');
}


// the function loadSettings has to exist ...

function load(settings, onChange) {
if (settings.panID === undefined) {
settings.panID = 6754;
// settings.panID = 6754;
settings.panID = Math.floor(Math.random() * 10000);
}
if (settings.extPanID === undefined) {
settings.extPanID = 'DDDDDDDDDDDDDDDD';
// settings.extPanID = 'DDDDDDDDDDDDDDDD';
settings.extPanID = getRandomExtPanID();
}
// fix for previous wrong value
if (settings.extPanID === 'DDDDDDDDDDDDDDD') {
Expand Down Expand Up @@ -885,6 +961,7 @@ function load(settings, onChange) {
}
}


getComPorts(onChange);

//dialog = new MatDialog({EndingTop: '50%'});
Expand Down Expand Up @@ -1106,7 +1183,7 @@ socket.on('stateChange', function (id, state) {
socket.on('objectChange', function (id, obj) {
if (id.substring(0, namespaceLen) !== namespace) return;
//console.log('objectChange', id, obj);
if (obj && obj.type == 'device' && obj.common.type !== 'group') {
if (obj && obj.type == 'device') { // && obj.common.type !== 'group') {
updateDevice(id);
}
if (!obj) {
Expand Down Expand Up @@ -1169,7 +1246,7 @@ function showNetworkMap(devices, map) {
label: (dev.link_quality > 0 ? dev.common.name : `${dev.common.name}\n(disconnected)`),
title: dev._id.replace(namespace + '.', '') + extInfo,
shape: 'circularImage',
image: dev.icon,
image: dev.common.icon || dev.icon,
imagePadding: {top: 5, bottom: 5, left: 5, right: 5},
color: {background: 'white', highlight: {background: 'white'}},
font: {color: '#007700'},
Expand Down Expand Up @@ -2691,17 +2768,18 @@ function addExcludeDialog() {
}

function addExclude(exclude_model) {
sendTo(namespace, 'addExclude', {
exclude_model: exclude_model
}, function (msg) {
closeWaitingDialog();
if (msg) {
if (msg.error) {
showMessage(msg.error, _('Error'));
if (typeof exclude_model == 'object' && exclude_model.hasOwnProperty('common'))
sendTo(namespace, 'addExclude', { exclude_model: exclude_model }, function (msg) {
closeWaitingDialog();
if (msg) {
if (msg.error) {
showMessage(msg.error, _('Error'));
}
}
}
getExclude();
});
console.log('getting excludes ?');
getExclude();
});
else closeWaitingDialog();
}

function getExclude() {
Expand All @@ -2710,10 +2788,10 @@ function getExclude() {
if (msg.error) {
showMessage(msg.error, _('Error'));
} else {
excludes = msg;
excludes = msg.legacy;
showExclude();
}
}
} else console.warn('getExclude without msg')
});
}

Expand All @@ -2725,10 +2803,14 @@ function showExclude() {
return;
}

excludes.forEach(b => {
const exclude_id = b.id;
excludes.forEach(id => {
// const b = devices.find((item) => item._id.contains(id));
const exclude_id = id.key;
const exclude_icon = id.value;

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable exclude_icon.

const exclude_dev = devices.find((d) => d.common.type == exclude_id) || {common: {name: exclude_id}};
// console.warn('showExcludes for id ' + exclude_id + ' with b = ' + JSON.stringify(exclude_dev));

// exclude_icon = (exclude_dev.icon) ? `<img src="${exclude_dev.icon}" width="64px">` : '';

const modelUrl = (!exclude_id) ? '' : `<a href="https://www.zigbee2mqtt.io/devices/${sanitizeModelParameter(exclude_id)}.html" target="_blank" rel="noopener noreferrer">${exclude_id}</a>`;
Expand Down Expand Up @@ -2761,7 +2843,7 @@ function showExclude() {
$('#exclude button[name=\'delete\']').click(function () {
const exclude_id = $(this).parents('.exclude')[0].id;
deleteExcludeConfirmation(exclude_id);
deleteExclude(exclude_id);
//deleteExclude(exclude_id);
});
}

Expand All @@ -2786,6 +2868,7 @@ function deleteExclude(id) {
showMessage(msg.error, _('Error'));
}
}
console.log('getting excludes ?');
getExclude();
});
}
Expand Down Expand Up @@ -2872,7 +2955,7 @@ function getDashCard(dev, groupImage, groupstatus) {
const title = dev.common.name,
id = dev._id,
type = dev.common.type,
img_src = (groupImage ? groupImage : dev.icon || dev.common.icon),
img_src = (groupImage ? groupImage : dev.common.icon || dev.icon),
isActive = !dev.common.deactivated,
rooms = [],
lang = systemLang || 'en';
Expand Down
31 changes: 25 additions & 6 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ <h5 class="translate">Zigbee adapter</h5>
<li class="tab col s2"><a href="#tab-sett" id="settings" class="translate tooltipped">Settings</a></li>
<!--<li class="tab col s2"><a href="#tab-map" id="tabmap" class="translate tooltipped">Network map</a></li> -->
<!--<li class="tab col s1"><a href="#tab-binding" class="translate tooltipped">Binding</a></li> -->
<li class="tab col s2"><a href="#tab-exclude" class="translate tooltipped">Excludes</a></li>
<li class="tab col s2"><a href="#tab-exclude" class="translate tooltipped">Local Overrides</a></li>
<li class="tab col s2"><a href="#tab-main" id="devs" class="translate tooltipped">Devices</a></li>
<li class="tab col s2"><a href="#tab-dev" id="develop" class="translate tooltipped">Developer</a>
</li>
Expand Down Expand Up @@ -1327,13 +1327,32 @@ <h3 class="translate">Edit Group</h3>
</div>
</div>
</div>
</div>
<div id="chooseimage" class="modal">
<div class="modal-content">
<div class="row">
<h3 class="translate">Image override</h3>
<div class="row">
<div class="col s12 input-field">
<select id="images" class="icons">
</select>
<label for="images" class="translate">Image</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col s19 input-field">
<input id="globaloverride" type="checkbox" class="value"/>
<label class="translate" for="globaloverride">Apply to model</label>
</div>
</div>
<div class="modal-footer">
<a name="save" href="#!"
class="modal-action modal-close waves-effect waves-green btn green translate">Save</a>
<a name="save" href="#!" class="modal-action modal-close waves-effect waves-green btn green translate">Save</a>
<a href="#!" class="modal-action modal-close waves-effect waves-red btn-flat translate">Cancel</a>
</div>
</div>

<div id="codeentry" class="modal">
<div class="modal-content">
<div class="addgroup">
Expand Down Expand Up @@ -1529,12 +1548,12 @@ <h3 class="translate">Binding configuration</h3>
<div id="excludemodaledit" class="modal">
<div class="modal-content">
<div class="row">
<h3 class="translate">Exclude configuration</h3>
<h3 class="translate">Custom device configuration</h3>
<div class="row">
<div class="col s9 input-field">
<select id="exclude_target" class="icons">
</select>
<label for="exclude_target" class="translate">exclude device</label>
<label for="exclude_target" class="translate">use legacy implementation for device</label>
</div>
</div>
</div>
Expand Down
28 changes: 27 additions & 1 deletion admin/tab_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,33 @@ <h3 class="translate">Edit Group</h3>
</div>
</div>

<div id="modaldelete" class="modal">
<div id="chooseimage" class="modal">
<div class="modal-content">
<div class="row">
<h3 class="translate">Image override</h3>
<div class="row">
<div class="col s12 input-field">
<select id="images" class="icons">
</select>
<label for="images" class="translate">Image</label>
</div>
</div>
</div>
<div class="row">
<div class="col s19 input-field">
<input id="globaloverride" type="checkbox" class="value"/>
<label class="translate" for="globaloverride">Apply to model</label>
</div>
</div>
</div>
<div class="modal-footer">
<a name="save" href="#!" class="modal-action modal-close waves-effect waves-green btn green translate">Save</a>
<a href="#!" class="modal-action modal-close waves-effect waves-red btn-flat translate">Cancel</a>
</div>
</div>


<div id="modaldelete" class="modal">
<div class="modal-content">
<h3 class="translate">Delete confirmation</h3>
<p>A bunch of text</p>
Expand Down
2 changes: 1 addition & 1 deletion lib/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Binding {
await this.doBindUnbind(type, bind_source, bind_source_ep, 'coordinator', '1');
this.debug('Successfully ' + (type === 'bind' ? 'bound' : 'unbound') + ' Coordinator from ' + bind_source);
} catch (e) {
this.error(`Could not ${type} Coordinator from ${bind_source}: ${(e && e.message ? e.message : 'no error message')} ${(e && e.stack ? e.stack : 'no call stack')}`);
this.error(`Could not ${type} Coordinator from ${bind_source}: ${JSON.stringify(e)}`);
}
}
} catch (error) {
Expand Down
Loading

0 comments on commit 9c12225

Please sign in to comment.