diff --git a/core/class/netatmo.class.php b/core/class/netatmo.class.php index b75529f..f12a612 100644 --- a/core/class/netatmo.class.php +++ b/core/class/netatmo.class.php @@ -77,12 +77,107 @@ public static function cron10(){ log::add('netatmo','debug','Weather : '.$e->getMessage()); } try { - netatmo_energy::refresh(); + netatmo::refreshClassNetatmo(); } catch (\Exception $e) { log::add('netatmo','debug','Energy : '.$e->getMessage()); } } + public static function refreshClassNetatmo($homesdata = null){ + if($homesdata == null) { + $homesdata = netatmo::request('/homesdata'); + } + $home_ids = array(); + if(isset($homesdata['homes']) && count($homesdata['homes']) > 0){ + foreach ($homesdata['homes'] as $home) { + if(!isset($home['modules'])){ + continue; + } + if(isset($home['modules']) && count($home['modules']) > 0){ + foreach ($home['modules'] as $module) { + $moduleid = $module['id']; + $ArrayAssocModuleIDtoRoom[$moduleid]= $module['room_id']; + } + } + $home_ids[] = $home['id']; + if(!isset($home['therm_mode'])){ + continue; + } + $eqLogic = eqLogic::byLogicalId($home['id'], 'netatmo'); + if(!is_object($eqLogic)){ + continue; + } + if($home['therm_mode'] != 'schedule'){ + $eqLogic->checkAndUpdateCmd('mode',$home['therm_mode']); + continue; + } + if(isset($home['schedules']) && count($home['schedules']) > 0){ + $mode = ''; + foreach ($home['schedules'] as $schedule) { + if(!$schedule['selected']){ + continue; + } + $mode .= $schedule['name'].','; + } + $eqLogic->checkAndUpdateCmd('mode',trim($mode,',')); + } + } + } + if(count($home_ids) == 0){ + return; + } + foreach ($home_ids as $home_id) { + $homestatus = netatmo::request('/homestatus',array('home_id' => $home_id)); + if(isset($homestatus['home']) && isset($homestatus['home']['modules']) && count($homestatus['home']['modules']) > 0){ + foreach ($homestatus['home']['modules'] as $module) { + if ($module['type']=="OTM" || $module['type']=="NATherm1") { + $eqLogic = eqLogic::byLogicalId($ArrayAssocModuleIDtoRoom[$module['id']], 'netatmo'); + if(is_object($eqLogic)){ + foreach ($eqLogic->getCmd('info') as $cmd) { + $logicalId = $cmd->getLogicalId(); + if(isset($module[$logicalId]) && $cmd->getLogicalID()!="reachable"){ + $eqLogic->checkAndUpdateCmd($cmd,$module[$logicalId]); + } + } + } + } + $eqLogic = eqLogic::byLogicalId($module['id'], 'netatmo'); + if(!is_object($eqLogic)){ + continue; + } + foreach ($eqLogic->getCmd('info') as $cmd) { + $logicalId = $cmd->getLogicalId(); + if($logicalId == 'state'){ + $logicalId = 'status'; + } + if(!isset($module[$logicalId])){ + continue; + } + $eqLogic->checkAndUpdateCmd($cmd,$module[$logicalId]); + } + } + } + if(isset($homestatus['home']) && isset($homestatus['home']['rooms']) && count($homestatus['home']['rooms']) > 0){ + foreach ($homestatus['home']['rooms'] as $room) { + $eqLogic = eqLogic::byLogicalId($room['id'], 'netatmo'); + if(!is_object($eqLogic)){ + continue; + } + foreach ($eqLogic->getCmd('info') as $cmd) { + if(!isset($room[$cmd->getLogicalId()])){ + continue; + } + if($cmd->getLogicalId() == 'therm_setpoint_mode' && $room[$cmd->getLogicalId()] != 'schedule' && isset($room['therm_setpoint_end_time'])){ + $eqLogic->checkAndUpdateCmd($cmd,$room[$cmd->getLogicalId()].' ('.__('fini à',__FILE__).' '.date('H:i',$room['therm_setpoint_end_time']).')'); + continue; + } + $eqLogic->checkAndUpdateCmd($cmd,$room[$cmd->getLogicalId()]); + } + } + } + } + } + public static function cronHourly(){ if(config::byKey('mode', 'netatmo') != 'internal'){ sleep(rand(0,120)); @@ -129,8 +224,20 @@ public static function request($_path,$_data = null,$_type='GET'){ if(isset($return['body'])){ $return_temp = $return['body']; if(isset($return_temp['errors'])){ - throw new \Exception(__('Erreur lors de la requete à Netatmo : ',__FILE__).json_encode($return)); - } + foreach ($return_temp['errors'] as $error) { + $eqLogicError = eqLogic::byLogicalId($error[id], 'netatmo'); + if(!is_object($eqLogicError)){ + continue; + } + $error_desc[1] = "Unknown error"; + $error_desc[2] = "Internal error"; + $error_desc[3] = "Parser error"; + $error_desc[4] = "Command unknown node module error"; + $error_desc[5] = "Command invalid params"; + $error_desc[6] = "Unreachable"; + message::add('netatmo','L\'équipement '.$eqLogicError->getName().' est en erreur : '.$error_desc[$error[code]].'('.$error[code].')'); + } + } return $return['body']; } return $return; @@ -239,7 +346,7 @@ public function execute($_options = array()) { netatmo_security::refresh(); } if($eqLogic->getConfiguration('type') == 'energy'){ - netatmo_energy::refresh(); + netatmo::refreshClassNetatmo(); } return; } diff --git a/core/class/netatmo_energy.class.php b/core/class/netatmo_energy.class.php index 7d18652..4e6006f 100644 --- a/core/class/netatmo_energy.class.php +++ b/core/class/netatmo_energy.class.php @@ -118,84 +118,7 @@ public static function sync(){ } public static function refresh($homesdata = null){ - if($homesdata == null) { - $homesdata = netatmo::request('/homesdata'); - } - $home_ids = array(); - if(isset($homesdata['homes']) && count($homesdata['homes']) > 0){ - foreach ($homesdata['homes'] as $home) { - if(!isset($home['modules'])){ - continue; - } - $home_ids[] = $home['id']; - if(!isset($home['therm_mode'])){ - continue; - } - $eqLogic = eqLogic::byLogicalId($home['id'], 'netatmo'); - if(!is_object($eqLogic)){ - continue; - } - if($home['therm_mode'] != 'schedule'){ - $eqLogic->checkAndUpdateCmd('mode',$home['therm_mode']); - continue; - } - if(isset($home['schedules']) && count($home['schedules']) > 0){ - $mode = ''; - foreach ($home['schedules'] as $schedule) { - if(!$schedule['selected']){ - continue; - } - $mode .= $schedule['name'].','; - } - $eqLogic->checkAndUpdateCmd('mode',trim($mode,',')); - } - } - } - if(count($home_ids) == 0){ - return; - } - foreach ($home_ids as $home_id) { - $homestatus = netatmo::request('/homestatus',array('home_id' => $home_id)); - if(isset($homestatus['home']) && isset($homestatus['home']['modules']) && count($homestatus['home']['modules']) > 0){ - foreach ($homestatus['home']['modules'] as $module) { - $eqLogic = eqLogic::byLogicalId($module['id'], 'netatmo'); - if(!is_object($eqLogic)){ - continue; - } - foreach ($eqLogic->getCmd('info') as $cmd) { - $logicalId = $cmd->getLogicalId(); - if($logicalId == 'state'){ - $logicalId = 'status'; - } - if(!isset($module[$logicalId])){ - continue; - } - $eqLogic->checkAndUpdateCmd($cmd,$module[$logicalId]); - } - } - } - if(isset($homestatus['home']) && isset($homestatus['home']['rooms']) && count($homestatus['home']['rooms']) > 0){ - foreach ($homestatus['home']['rooms'] as $room) { - $eqLogic = eqLogic::byLogicalId($room['id'], 'netatmo'); - if(!is_object($eqLogic)){ - continue; - } - foreach ($eqLogic->getCmd('info') as $cmd) { - if(!isset($room[$cmd->getLogicalId()])){ - continue; - } - if($cmd->getLogicalId() == 'therm_setpoint_mode' && $room[$cmd->getLogicalId()] != 'schedule' && isset($room['therm_setpoint_end_time'])){ - $eqLogic->checkAndUpdateCmd($cmd,$room[$cmd->getLogicalId()].' ('.__('fini à',__FILE__).' '.date('H:i',$room['therm_setpoint_end_time']).')'); - continue; - } - $eqLogic->checkAndUpdateCmd($cmd,$room[$cmd->getLogicalId()]); - } - } - } - - - - } + netatmo::refreshClassNetatmo(); } public static function execCmd($_cmd,$_options = array()){ @@ -322,6 +245,6 @@ public static function execCmd($_cmd,$_options = array()){ throw new \Exception('Erreur lors de l éxécution de la commande (commande '.$_cmd->getLogicalId().' inconnue)'); } sleep(10); - self::refresh(); + netatmo::refreshClassNetatmo(); } } diff --git a/core/config/devices/NATherm1.json b/core/config/devices/NATherm1.json index be43bc4..419beb9 100644 --- a/core/config/devices/NATherm1.json +++ b/core/config/devices/NATherm1.json @@ -113,6 +113,22 @@ "maxValue" : 24 }, "logicalId": "mode_off_endtime" - } + }, + { + "name": "Joignabilité", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "reachable" + }, + { + "name": "Etat Mode Comfort Vannes", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "boiler_valve_comfort_boost " + } ] } diff --git a/core/config/devices/NOC.json b/core/config/devices/NOC.json index 0772c0c..0bc912a 100644 --- a/core/config/devices/NOC.json +++ b/core/config/devices/NOC.json @@ -1,14 +1,6 @@ { "name" : "Présence", "commands" : [ - { - "name": "Projecteur", - "type": "info", - "subtype": "string", - "isVisible": 1, - "isHistorized": 0, - "logicalId": "light" - }, { "name": "Auto", "type": "action", @@ -119,6 +111,62 @@ "configuration": { "repeatEventManagement": "always" } - } + }, + { + "name": "Wifi (Etat)", + "type": "info", + "subtype": "string", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "wifi_state" + }, + { + "name": "Wifi (Puissance Signal)", + "type": "info", + "subtype": "numeric", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "wifi_strength" + }, + { + "name": "CarteSD (Etat)", + "type": "info", + "subtype": "string", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "sd_status" + }, + { + "name": "Sirène (Etat)", + "type": "info", + "subtype": "string", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "siren_status" + }, + { + "name": "Connexion (Etat)", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "connection" + }, + { + "name": "Démarrage", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "booting" + }, + { + "name": "Sirène", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "siren" + } ] } diff --git a/core/config/devices/NRV.json b/core/config/devices/NRV.json index 239e97f..75b0a24 100644 --- a/core/config/devices/NRV.json +++ b/core/config/devices/NRV.json @@ -92,6 +92,14 @@ "isHistorized": 0, "generic_type" : "THERMOSTAT_SET_MODE", "logicalId": "mode_auto" + }, + { + "name": "Joignabilité (Etat)", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "reachable" } ] } diff --git a/core/config/devices/OTM.json b/core/config/devices/OTM.json index 3eb6cd3..ea3fb8c 100644 --- a/core/config/devices/OTM.json +++ b/core/config/devices/OTM.json @@ -113,6 +113,30 @@ "maxValue" : 24 }, "logicalId": "mode_hg_endtime" - } + }, + { + "name": "Joignabilité (Etat)", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "reachable" + }, + { + "name": "Retour Erreur Chaudière", + "type": "info", + "subtype": "other", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "boiler_error" + }, + { + "name": "Etat Mode Comfort Vannes", + "type": "info", + "subtype": "binary", + "isVisible": 0, + "isHistorized": 0, + "logicalId": "boiler_valve_comfort_boost" + } ] } diff --git a/core/php/jeeNetatmo.php b/core/php/jeeNetatmo.php index a48548c..bd23a4f 100644 --- a/core/php/jeeNetatmo.php +++ b/core/php/jeeNetatmo.php @@ -40,8 +40,20 @@ } log::add('netatmo', 'debug','[webhook] '. json_encode($data)); if(!isset($data['device_id'])){ - log::add('netatmo', 'debug','[webhook] No device id found'); - die(); + if(isset($data['push_type']) && $data['push_type']='topology_changed'){ + log::add('netatmo', 'debug','[webhook] Topologie changée -> Actualisation (refresh)'); + netatmo::refreshClassNetatmo(); + exit(0); + } + elseif(isset($data['push_type']) && $data['push_type']='home_event_changed') { + if(isset($data['event_type']) && $data['event_type']='schedule'){ + log::add('netatmo', 'debug','[webhook] Changement de Planning signalé'); + } + } + else{ + log::add('netatmo', 'debug','[webhook] Device id not found'); + die(); + } } $eqLogic = null; if(isset($data['module_id'])){ @@ -58,6 +70,15 @@ $home = eqLogic::byLogicalId($data['home_id'], 'netatmo'); } switch ($data['event_type']) { + case 'connection': + $eqLogic->checkAndUpdateCmd('connection',1); + break; + case 'disconnection': + $eqLogic->checkAndUpdateCmd('connection',0); + break; + case 'boot': + $eqLogic->checkAndUpdateCmd('booting',1); + break; case 'on': $eqLogic->checkAndUpdateCmd('monitoring',1); break;