diff --git a/core/ajax/z2m.ajax.php b/core/ajax/z2m.ajax.php index 7fec40bd..808dc07e 100644 --- a/core/ajax/z2m.ajax.php +++ b/core/ajax/z2m.ajax.php @@ -28,7 +28,7 @@ if (init('action') == 'include') { $data = array( 'value' => (init('mode') == 1), - 'time' => 180 + 'time' => (init('mode') == 1) ? 180 : 0 ); if(init('id') != 'all'){ $data['device'] = init('id'); diff --git a/core/class/z2m.class.php b/core/class/z2m.class.php index 1be60302..5ec871f9 100644 --- a/core/class/z2m.class.php +++ b/core/class/z2m.class.php @@ -570,15 +570,15 @@ public static function handle_bridge($_datas) { ));*/ break; case 'error': - log::add('z2m', 'error', __('Z2M à renvoyé une erreur : ', __FILE__) . $_datas['logging']['message']); + log::add('z2m', 'error', __('Z2M a renvoyé une erreur : ', __FILE__) . $_datas['logging']['message']); break; } } if (isset($_datas['response']['status']) && $_datas['response']['status'] != 'ok') { - log::add('z2m', 'error', __('Z2M à renvoyé une erreur : ', __FILE__) . json_encode($_datas['response'])); + log::add('z2m', 'error', __('Z2M a renvoyé une erreur : ', __FILE__) . json_encode($_datas['response'])); } if (isset($_datas['response']['permit_join'])) { - if ($_datas['response']['permit_join']['data']['value'] || $_datas['response']['permit_join']['status'] == 'ok') { + if ($_datas['response']['permit_join']['data']['time'] > 0) { event::add('jeedom::alert', array( 'level' => 'success', 'page' => 'z2m', diff --git a/desktop/php/z2m.php b/desktop/php/z2m.php index 24bc9461..362f1053 100644 --- a/desktop/php/z2m.php +++ b/desktop/php/z2m.php @@ -28,12 +28,12 @@ sendVarToJS('z2m_devices', $devices); sendVarToJS('devices_attr', $deviceAttr); $bridge_infos = z2m::getDeviceInfo('bridge1'); -if($bridge_infos['permit_join'] && isset($bridge_infos['permit_join_timeout'])){ +if($bridge_infos['permit_join'] && isset($bridge_infos['permit_join_end'])){ event::add('jeedom::alert', array( 'level' => 'success', 'page' => 'z2m', 'message' => __('Mode inclusion actif', __FILE__), - 'ttl' => $bridge_infos['permit_join_timeout'] * 1000 + 'ttl' => $bridge_infos['permit_join_end'] - time() * 1000 )); } ?> diff --git a/mobile/html/z2m.html b/mobile/html/z2m.html new file mode 100644 index 00000000..07230f6b --- /dev/null +++ b/mobile/html/z2m.html @@ -0,0 +1,19 @@ + +
+
+
+
+
+ +
{{Activer inclusion}}
+
+
+
+
+ +
{{Désactiver inclusion}}
+
+
+
+ + diff --git a/mobile/html/z2m.php b/mobile/html/z2m.php new file mode 100644 index 00000000..998440dc --- /dev/null +++ b/mobile/html/z2m.php @@ -0,0 +1,37 @@ +getId()); +$eqLogics = eqLogic::byType($plugin->getId()); + +foreach ($eqLogics as $eqLogic) { + $devices[$eqLogic->getLogicalId()] = array( + 'HumanNameFull' => $eqLogic->getHumanName(true), + 'HumanName' => $eqLogic->getHumanName(), + 'id' => $eqLogic->getId(), + 'img' => $eqLogic->getImgFilePath(), + 'device_type' => $eqLogic->getConfiguration('device_type','EndDevice'), + 'isgroup' => $eqLogic->getConfiguration('isgroup', 0), + 'isChild' => $eqLogic->getConfiguration('isChild', 0), + 'ieee' => z2m::convert_from_addr(explode('|', $eqLogic->getLogicalId())[0]) + ); + $deviceAttr[$eqLogic->getId()] = array( + 'isgroup' => $eqLogic->getConfiguration('isgroup', 0), + 'multipleEndpoints' => $eqLogic->getConfiguration('multipleEndpoints', 0), + 'isChild' => $eqLogic->getConfiguration('isChild', 0) + ); +} +$devices[0] = array('HumanNameFull' => 'Contrôleur', 'HumanName' => 'Contrôleur', 'id' => 0, 'img' => 'plugins/z2m/core/config/devices/coordinator.png'); +sendVarToJS('z2m_devices', $devices); +sendVarToJS('devices_attr', $deviceAttr); +$bridge_infos = z2m::getDeviceInfo('bridge1'); +if($bridge_infos['permit_join'] && isset($bridge_infos['permit_join_end'])){ + $ttl = $bridge_infos['permit_join_end'] - time() * 1000; + event::add('jeedom::alert', array( + 'level' => 'success', + 'page' => 'z2m', + 'message' => __('Mode inclusion actif pendant '. intdiv($ttl, 1000) . 's', __FILE__), + 'ttl' => $ttl + )); +} +?> diff --git a/mobile/js/z2m.js b/mobile/js/z2m.js new file mode 100644 index 00000000..c01c5f39 --- /dev/null +++ b/mobile/js/z2m.js @@ -0,0 +1,73 @@ +"use strict" + +$('body').attr('data-page', 'z2m') + +$('#searchContainer').hide() + +var $bottompanel_routerlist + +function initz2mpromptRouter() { + $bottompanel_routerlist = $('#changeIncludeStateEnable') + $bottompanel_routerlist.empty() + $bottompanel_routerlist.append(' Tout') + $bottompanel_routerlist.append(' Coordinateur') + for(var i in z2m_devices){ + if(z2m_devices[i].isgroup == 1 || z2m_devices[i].isChild == 1 || z2m_devices[i].device_type != 'Router'){ + continue; + } + $bottompanel_routerlist.append(' ' + z2m_devices[i].HumanName + '') + } + $bottompanel_routerlist.append('
') + + $bottompanel_routerlist = $('#changeIncludeStateDisable') + $bottompanel_routerlist.empty() + $bottompanel_routerlist.append(' Tout') + $bottompanel_routerlist.append(' Coordinateur') + for(var i in z2m_devices){ + if(z2m_devices[i].isgroup == 1 || z2m_devices[i].isChild == 1 || z2m_devices[i].device_type != 'Router'){ + continue; + } + $bottompanel_routerlist.append(' ' + z2m_devices[i].HumanName + '') + } + $bottompanel_routerlist.append('
') +} + +$('#changeIncludeStateEnable').off('click', '.routers').on('click', '.routers', function(e) { + jeedom.z2m.bridge.include({ + id: $(this).attr('data-id'), + mode : 1, + error: function(error) { + $('#div_alert').showAlert({message: error.message, level: 'danger'}) + }, + success: function() { + $('#div_alert').showAlert({message: '{{Lancement du mode inclusion}}', level: 'success'}) + $('#changeIncludeStateEnable').hide() + } + }) +}) + +$('#changeIncludeStateDisable').off('click', '.routers').on('click', '.routers', function(e) { + jeedom.z2m.bridge.include({ + id: $(this).attr('data-id'), + mode : 0, + error: function(error) { + $('#div_alert').showAlert({message: error.message, level: 'danger'}) + }, + success: function() { + $('#div_alert').showAlert({message: '{{Désactivation du mode inclusion}}', level: 'success'}) + $('#changeIncludeStateDisable').hide() + } + }) + }) + +$('body').off('z2m::includeDevice').on('z2m::includeDevice', function(_event, _options) { +if (modifyWithoutSave) { + $('#div_alert').showAlert({ + message: '{{Un périphérique vient d\'être inclu/exclu. Veuillez réactualiser la page}}', + level: 'warning' + }); +} else if (_options != '') { + window.location.href = 'index.php?v=d&p=z2m&m=z2m&id=' + _options; +} +}) +initz2mpromptRouter(); diff --git a/resources/post-install.sh b/resources/post-install.sh index 6a1169b9..94208ab4 100644 --- a/resources/post-install.sh +++ b/resources/post-install.sh @@ -41,7 +41,7 @@ if [ -n "${wanted_z2m_version}" ] && [ $(echo $wanted_z2m_version | head -c 1) - npm ci npm run build else - npm install -g pnpm + npm install -g pnpm@10.12.1 pnpm i --frozen-lockfile pnpm run build fi