. */ /* * ***************************Includes********************************* */ require_once __DIR__ . '/../../../../core/php/core.inc.php'; use GuzzleHttp\Client; define('__ROOT__', dirname(dirname(dirname(__FILE__)))); require_once (__ROOT__.'/3rdparty/Netatmo-API-PHP/src/Netatmo/autoload.php'); define('__CSSICON__', str_replace($_SERVER['DOCUMENT_ROOT'], '', __ROOT__.'/core/css/icon/')); /*error_reporting(-1);*/ class netatmopro extends eqLogic { /* * *************************Attributs****************************** */ /* * Permet de définir les possibilités de personnalisation du widget (en cas d'utilisation de la fonction 'toHtml' par exemple) * Tableau multidimensionnel - exemple: array('custom' => true, 'custom::layout' => false) public static $_widgetPossibility = array(); */ public static $_typeToInfo = array( 'NAMain' => array( 'id' => '_id', 'name' => 'module_name', 'dashboard' => array( 'Temperature' => 'time_utc', 'CO2' => 'time_utc', 'Humidity' => 'time_utc', 'Noise' => 'time_utc', 'Pressure' => 'time_utc', #'AbsolutePressure' => 'time_utc', 'min_temp'=> 'date_min_temp', 'max_temp' => 'date_max_temp', 'temp_trend' => 'time_utc', 'pressure_trend' => 'time_utc' ), 'configuration' => array('station_name', 'date_setup', 'last_setup', 'last_status_store', 'firmware', 'last_upgrade', 'wifi_status', 'reachable', 'co2_calibrating') ), 'NAModule1' => array( 'id' => '_id', 'name' => 'module_name', 'dashboard' => array( 'Temperature' => 'time_utc', 'Humidity' => 'time_utc', 'min_temp' => 'date_min_temp', 'max_temp' => 'date_max_temp', 'temp_trend' => 'time_utc' ), 'configuration' => array('last_setup', 'battery_percent', 'reachable', 'firmware', 'last_message', 'last_seen', 'rf_status', 'battery_vp') ), 'NAModule2' => array( 'id' => '_id', 'name' => 'module_name', 'dashboard' => array( 'WindStrength' => 'time_utc', 'WindAngle' => 'time_utc', 'GustStrength' => 'time_utc', 'GustAngle' => 'time_utc', 'max_wind_str' => 'date_max_wind_str', 'max_wind_angle' => 'date_max_wind_str' ), 'configuration' => array('last_setup', 'battery_percent', 'reachable', 'firmware', 'last_message', 'last_seen', 'rf_status', 'battery_vp') ), 'NAModule3' => array( 'id' => '_id', 'name' => 'module_name', 'dashboard' => array( 'Rain' => 'time_utc', 'sum_rain_1' => 'time_utc', 'sum_rain_24' => 'time_utc' ), 'configuration' => array('last_setup', 'battery_percent', 'reachable', 'firmware', 'last_message', 'last_seen', 'rf_status', 'battery_vp') ), 'NAModule4' => array( 'id' => '_id', 'name' => 'module_name', 'dashboard' => array( 'Temperature' => 'time_utc', 'CO2' => 'time_utc', 'Humidity' => 'time_utc', 'min_temp' => 'date_min_temp', 'max_temp' => 'date_max_temp', 'temp_trend' => 'time_utc' ), 'configuration' => array('last_setup', 'battery_percent', 'reachable', 'firmware', 'last_message', 'last_seen', 'rf_status', 'battery_vp') ), 'NHC' => array( 'id' => '_id', 'name' => 'station_name', 'dashboard' => array( 'Temperature' => 'time_utc', 'CO2' => 'time_utc', 'Humidity' => 'time_utc', 'Noise' => 'time_utc', 'Pressure' => 'time_utc', #'AbsolutePressure' => 'time_utc', 'health_idx' => 'time_utc', 'min_temp' => 'date_min_temp', 'max_temp' => 'date_max_temp' ), 'configuration' => array('date_setup', 'last_setup', 'last_status_store', 'module_name', 'firmware', 'last_upgrade', 'wifi_status', 'reachable', 'co2_calibrating') ), 'NOC' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('sd_status', 'alim_status', 'floodlight', 'monitoring'), 'configuration' => array('firmware_revision', 'wifi_state', 'wifi_strength', 'vpn_url', 'is_local') ), 'NACamera' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('sd_status', 'alim_status', 'monitoring'), 'configuration' => array('firmware_revision', 'vpn_url', 'is_local') ), 'NAPerson' => array( 'id' => 'id', 'name' => 'pseudo', 'dashboard' => array('last_seen', 'out_of_sight'), 'configuration' => array() ), 'NCO' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('last_seen'), 'configuration' => array('firmware_revision', 'wifi_strength') ), 'NSD' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('last_seen'), 'configuration' => array('firmware_revision', 'wifi_strength') ), 'NIS' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('last_seen', 'status', 'monitoring'), 'configuration' => array('battery_state', 'battery_level', 'firmware_revision', 'rf_state', 'rf_strength') ), 'NACamDoorTag' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('last_seen', 'last_activity', 'status'), 'configuration' => array('battery_state', 'battery_level', 'firmware_revision', 'rf_state', 'rf_strength', 'reachable') ), 'NDB' => array( 'id' => 'id', 'name' => 'name', 'dashboard' => array('sd_status', 'alim_status'), 'configuration' => array('firmware_revision', 'wifi_state', 'wifi_strength', 'vpn_url', 'is_local') ) ); /* * ***********************Methode static*************************** */ public static function synchronize($update = true) { log::add('netatmopro', 'debug', 'synchronize:: update:' . var_export($update, true)); $dayweek = array('1' => 'Lundi', '2' => 'Mardi', '3' => 'Mercredi', '4' => 'Jeudi', '5' => 'Vendredi', '6' => 'Samedi', '7' => 'Dimanche'); $config = array("client_id" => config::byKey('client_id', 'netatmopro'), "client_secret" => config::byKey('client_secret', 'netatmopro'), "access_token" => config::byKey('access_token', 'netatmopro'), "refresh_token" => config::byKey('refresh_token', 'netatmopro'), "expires_at" => config::byKey('expires_at', 'netatmopro'), "scope" => 'read_station read_magellan write_magellan read_bubendorff write_bubendorff read_smarther write_smarther read_thermostat write_thermostat read_camera write_camera access_camera read_doorbell access_doorbell read_mx write_mx read_presence write_presence access_presence read_homecoach read_carbonmonoxidedetector read_smokedetector read_mhs1 write_mhs1'); $scope = ( $update === true ? config::byKey('scope', 'netatmopro') : [] ); $webhook = false; log::add('netatmopro', 'debug', 'synchronize:: scope:' . var_export($scope, true)); if ( $update === false || ( $update === true && preg_match("/read_station/", $scope) ) ) { log::add('netatmopro', 'debug', 'synchronize:: Weather'); $data = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/getstationsdata'); log::add('netatmopro', 'debug', 'synchronize:: Weather:' . var_export($data, true)); foreach ($data['body']['devices'] as $device) { foreach ($device['modules'] as $module) { $eqLogic = eqLogic::byLogicalId($module['_id'], 'netatmopro'); if ( !is_object($eqLogic) && $update === false ) { log::add('netatmopro', 'debug', 'synchronize:: M_CREATE_IN_PROGRESS:' . var_export($module, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogicV2($module); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && array_key_exists('dashboard_data', $module) && $eqLogic->getConfiguration('time_utc') < $module['dashboard_data']['time_utc'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: M_UPDATE_IN_PROGRESS:' . var_export($module, true)); if (array_key_exists('dashboard_data', $module)) { foreach (netatmopro::$_typeToInfo[$module['type']]['dashboard'] as $key => $value) { $eqLogic->checkAndUpdateCmd($key, $module['dashboard_data'][$key], date('Y-m-d H:i:s', $module['dashboard_data'][$value])); } $eqLogic->setConfiguration('time_utc', $module['dashboard_data']['time_utc']); } $eqLogic->checkAndUpdateCmd('battery_percent', $module['battery_percent'], date('Y-m-d H:i:s', $module['last_message'])); foreach (netatmopro::$_typeToInfo[$module['type']]['configuration'] as $key) { if ( array_key_exists($key, $module) ) { $eqLogic->setConfiguration($key, $module[$key]); } } $eqLogic->setConfiguration('station_name', $device['station_name']); $eqLogic->batteryStatus($module['battery_percent']); $eqLogic->save(); $eqLogic->refreshWidget(); } } $eqLogic = eqLogic::byLogicalId($device['_id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($device, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogicV2($device); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && array_key_exists('dashboard_data', $device) && $eqLogic->getConfiguration('time_utc') < $device['dashboard_data']['time_utc'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($device, true)); if (array_key_exists('dashboard_data', $device)) { foreach (netatmopro::$_typeToInfo[$device['type']]['dashboard'] as $key => $value) { $eqLogic->checkAndUpdateCmd($key, $device['dashboard_data'][$key], date('Y-m-d H:i:s', $device['dashboard_data'][$value])); } $eqLogic->setConfiguration('time_utc', $device['dashboard_data']['time_utc']); } foreach (netatmopro::$_typeToInfo[$device['type']]['configuration'] as $key) { if ( array_key_exists($key, $device) ) { $eqLogic->setConfiguration($key, $device[$key]); } } $eqLogic->save(); $eqLogic->refreshWidget(); } if ($update === false) { $scope[] = 'read_station'; } } } if ( $update === false || ( $update === true && preg_match("/read_homecoach/", $scope) ) ) { log::add('netatmopro', 'debug', 'synchronize:: Aircare'); $data = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/gethomecoachsdata'); log::add('netatmopro', 'debug', 'synchronize:: Aircare:' . var_export($data, true)); foreach ($data['body']['devices'] as $device) { $eqLogic = eqLogic::byLogicalId($device['_id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($device, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogicV2($device); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && array_key_exists('dashboard_data', $device) && $eqLogic->getConfiguration('time_utc') < $device['dashboard_data']['time_utc'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($device, true)); if (array_key_exists('dashboard_data', $device)) { foreach (netatmopro::$_typeToInfo[$device['type']]['dashboard'] as $key => $value) { $eqLogic->checkAndUpdateCmd($key, $device['dashboard_data'][$key], date('Y-m-d H:i:s', $device['dashboard_data'][$value])); } $eqLogic->setConfiguration('time_utc', $device['dashboard_data']['time_utc']); } foreach (netatmopro::$_typeToInfo[$device['type']]['configuration'] as $key) { if ( array_key_exists($key, $device) ) { $eqLogic->setConfiguration($key, $device[$key]); } } $eqLogic->save(); $eqLogic->refreshWidget(); } if ($update === false) { $scope[] = 'read_homecoach'; } } } if ( $update === false || ( $update === true && preg_match("/read_camera write_camera access_camera read_doorbell access_doorbell read_presence write_presence access_presence read_carbonmonoxidedetector read_smokedetector/", $scope) ) ) { log::add('netatmopro', 'debug', 'synchronize:: Home + Security'); $hsdata = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/homesdata'); log::add('netatmopro', 'debug', 'synchronize:: Home + Security (homesdata):' . var_export($hsdata, true)); foreach ($hsdata['body']['homes'] as $home) { if (array_key_exists('modules', $home)) { foreach ($home['modules'] as $module) { if (!in_array($module['type'], array('NOC', 'NACamera', 'NCO', 'NSD', 'NIS', 'NACamDoorTag', 'NDB'))) continue; $eqLogic = eqLogic::byLogicalId($module['id'], 'netatmopro'); if ( !is_object($eqLogic) && $update === false ) { log::add('netatmopro', 'debug', 'synchronize:: M_CREATE_IN_PROGRESS:' . var_export($module, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogicV2($module); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->setConfiguration('setup_date', $module['setup_date']); $eqLogic->save(); } } } if (array_key_exists('persons', $home)) { foreach ($home['persons'] as $person) { if (!(array_key_exists('pseudo', $person))) continue; $eqLogic = eqLogic::byLogicalId($person['id'], 'netatmopro'); if ( !is_object($eqLogic) && $update === false ) { log::add('netatmopro', 'debug', 'synchronize:: P_CREATE_IN_PROGRESS:' . var_export($person, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogicV2($person, 'NAPerson'); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->save(); } } } $data = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/homestatus?home_id=' . $home['id']); log::add('netatmopro', 'debug', 'synchronize:: Home + Security (homestatus):' . var_export($data, true)); if (array_key_exists('body', $data)) { foreach ($data['body']['home']['modules'] as $module) { if (!in_array($module['type'], array('NOC', 'NACamera', 'NCO', 'NSD', 'NIS', 'NACamDoorTag', 'NDB'))) continue; $eqLogic = eqLogic::byLogicalId($module['id'], 'netatmopro'); if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: M_UPDATE_IN_PROGRESS:' . var_export($module, true)); foreach (netatmopro::$_typeToInfo[$module['type']]['dashboard'] as $key ) { $eqLogic->checkAndUpdateCmd($key, $module[$key]); } foreach (netatmopro::$_typeToInfo[$module['type']]['configuration'] as $key) { $eqLogic->setConfiguration($key, $module[$key]); } $eqLogic->save(); $eqLogic->refreshWidget(); } } if (array_key_exists('persons', $data['body']['home'])) { foreach ($data['body']['home']['persons'] as $person) { $eqLogic = eqLogic::byLogicalId($person['id'], 'netatmopro'); if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: P_UPDATE_IN_PROGRESS:' . var_export($person, true)); foreach (netatmopro::$_typeToInfo['NAPerson']['dashboard'] as $key ) { $eqLogic->checkAndUpdateCmd($key, $person[$key]); } $eqLogic->save(); $eqLogic->refreshWidget(); } } } } if ($update === false) { $scope[] = 'read_camera write_camera access_camera read_doorbell access_doorbell read_presence write_presence access_presence read_carbonmonoxidedetector read_smokedetector'; $webhook = true; } } } if ( $update === false || ( $update === true && preg_match("/read_thermostat write_thermostat/", $scope) ) ) { log::add('netatmopro', 'debug', 'synchronize:: NATherm2ApiClient'); #$client = new Netatmo\Clients\NATherm2ApiClient($config); #$tokens = $client->getAccessToken(); #$data = $client->getData(null, 'NAPlug'); $data = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/homesdata?gateway_types=NAPlug'); log::add('netatmopro', 'debug', 'synchronize:: ENERGY:' . var_export($data, true)); netatmopro::GetGuzzleHd($guzzle, $jar); log::add('netatmopro', 'debug', 'synchronize:: guzzle:' . var_export($guzzle, true)); log::add('netatmopro', 'debug', 'synchronize:: jar:' . var_export($jar, true)); $uri = 'https://app.netatmo.net/api/homesdata'; log::add('netatmopro', 'debug', 'synchronize:: uri:' . var_export($uri, true)); $response = $guzzle->request('POST', $uri, [ 'headers' => [ 'Authorization' => 'Bearer ' . urldecode($jar->getCookieByName('netatmocomaccess_token')->getValue()) ], 'body' => '{"gateway_types":["NAPlug"],"detailed_config":true,"home_id":null,"gateway_parameters":{"NAPlug":{"sync_measures":true}}}' ]); log::add('netatmopro', 'debug', 'synchronize:: response:' . var_export($response, true)); $wdata = json_decode($response->getBody()->getContents(), true); foreach ($wdata['body']['homes'] as $whome) { $homes[$whome['id']] = $whome; } log::add('netatmopro', 'debug', 'synchronize:: homes:' . var_export($homes, true)); foreach ($data['body']['homes'] as $home) { if (!(array_key_exists('rooms', $home) && array_key_exists('modules', $home) && array_key_exists('schedules', $home))) continue; $rooms = $modules = $schedules = []; foreach ($home['rooms'] as $room) { $rooms[$room['id']] = $room; } foreach ($home['modules'] as $module) { $modules[$module['id']] = $module; } foreach ($home['schedules'] as $schedule) { $schedules[$schedule['id']] = $schedule; } #$status = $client->getStatus($home['id'], 'NAPlug'); $status = netatmopro::NARequest('GET', 'https://app.netatmo.net/api/homestatus?home_id=' . $home['id'] . '&device_types=NAPlug'); log::add('netatmopro', 'debug', 'synchronize:: ENERGY:' . var_export($status, true)); foreach ($status['body']['home']['rooms'] as $room) { $room['type'] = 'NARoom'; $rooms[$room['id']]['status'] = $room; $eqLogic = eqLogic::byLogicalId($room['id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($room, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogic($room, $rooms[$room['id']]['name']); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($room, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $room[$key]); } $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->setConfiguration('room_type', $rooms[$room['id']]['type']); $eqLogic->save(); } } foreach ($status['body']['home']['modules'] as $module) { if ( $module['type'] == 'NOC' || $module['type'] == 'NACamera' ) continue; $eqLogic = eqLogic::byLogicalId($module['id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($module, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogic($module, $modules[$module['id']]['name']); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($module, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $module[$key]); } $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->setConfiguration('firmware_revision', $module['firmware_revision']); if ( $module['type'] == 'NAPlug' ) { $eqLogic->setConfiguration('wifi_strength', $module['wifi_strength']); $cmd = $eqLogic->getCmd('action', 'switchhomeschedule'); if ( is_object($cmd) ) { $listValue = ''; foreach ($schedules as $kschedule => $vschedule) { $listValue .= $kschedule . '|' . $vschedule['name'] . ';'; if ( array_key_exists('selected', $vschedule) && $vschedule['selected'] == true ) { $eqLogic->checkAndUpdateCmd('homes_schedule', $vschedule['name']); $monday = date('U',strtotime('Monday this week')); $now = time(); log::add('netatmopro', 'debug', 'synchronize:: monday:' . var_export($monday, true)); foreach (array_reverse($vschedule['timetable']) as $ktimetable => $vtimetable) { if ($now-$monday >= $vtimetable['m_offset']*60) { log::add('netatmopro', 'debug', 'synchronize:: vtimetable:' . var_export($vtimetable, true)); break; } } foreach ($vschedule['zones'] as $kzones => $vzones) { if ($vtimetable['zone_id'] == $vzones['id']) { log::add('netatmopro', 'debug', 'synchronize:: vzones:' . var_export($vzones, true)); break; } } $eqLogic->checkAndUpdateCmd('therm_setpoint_zone', $vzones['name']); log::add('netatmopro', 'debug', 'synchronize:: therm_setpoint_zone:' . var_export($vzones['name'], true)); if ( count($vschedule['timetable'])-$ktimetable < count($vschedule['timetable']) ) { $nschedule = $monday + ($vschedule['timetable'][count($vschedule['timetable'])-$ktimetable]['m_offset']*60); if (date("z-Y",$now) == date("z-Y",$nschedule)) { $eqLogic->checkAndUpdateCmd('therm_setpoint_timetable', 'Jusqu\'à ' . date("H:i",$nschedule)); } else { $eqLogic->checkAndUpdateCmd('therm_setpoint_timetable', 'Jusqu\'à ' . $dayweek[date("N",$nschedule)] . ' ' . date("H:i",$nschedule)); } } else { $nschedule = date('U',strtotime('Monday next week')); $eqLogic->checkAndUpdateCmd('therm_setpoint_timetable', 'Jusqu\'à Lundi 00:00'); } } } log::add('netatmopro', 'debug', 'synchronize:: switchhomeschedule:' . var_export($listValue, true)); $cmd->setConfiguration('listValue', substr($listValue, 0, -1)); $cmd->save(); } $eqLogic->checkAndUpdateCmd('therm_mode', $home['therm_mode']); $eqLogic->checkAndUpdateCmd('therm_heating_priority', $homes[$home['id']]['therm_heating_priority']); } else { $eqLogic->setConfiguration('room_id', $rooms[$modules[$module['id']]['room_id']]['id']); $eqLogic->setConfiguration('room_name', $rooms[$modules[$module['id']]['room_id']]['name']); $eqLogic->setConfiguration('room_type', $rooms[$modules[$module['id']]['room_id']]['type']); $eqLogic->setConfiguration('bridge', $module['bridge']); $eqLogic->setConfiguration('rf_strength', $module['rf_strength']); $eqLogic->setConfiguration('battery_level', $module['battery_level']); $eqLogic->setConfiguration('battery_state', $module['battery_state']); $eqLogic->batteryStatus(($module['battery_state'] == 'full' ? 100 : (($module['battery_state'] == 'high' ? 80 : ($module['battery_state'] == 'medium' ? 50 : 20 ))))); } $eqLogic->save(); } } if ($update === false) { $scope[] = 'read_thermostat write_thermostat'; $webhook = true; } } } if ( $update === false ) { if (!empty($scope)) { log::add('netatmopro', 'debug', 'synchronize:: scope:' . var_export(implode(';', array_unique($scope)), true)); config::save('scope', implode(';', array_unique($scope)), 'netatmopro'); } if ( $webhook === true ) { log::add('netatmopro', 'debug', 'synchronize:: webhook:' . var_export(network::getNetworkAccess('external'), true)); if (filter_var(network::getNetworkAccess('external'), FILTER_VALIDATE_URL)) { #$client = new Netatmo\Clients\NAWelcomeApiClient($config); #$tokens = $client->getAccessToken(); #$client->subscribeToWebhook(network::getNetworkAccess('external') . '/plugins/netatmopro/core/php/NAWebhookClient.php?apikey=' . jeedom::getApiKey('netatmopro')); $data = netatmopro::NARequest('POST', 'https://api.netatmo.com/api/addwebhook?url=' . urlencode(network::getNetworkAccess('external') . '/plugins/netatmopro/core/php/NAWebhookClient.php?apikey=' . jeedom::getApiKey('netatmopro'))); } } } } /* * Fonction exécutée automatiquement toutes les minutes par Jeedom public static function cron() { } */ public static function cron() { $refresh = config::byKey('refresh', 'netatmopro'); log::add('netatmopro', 'debug', 'cron:: refresh:' . var_export($refresh, true)); if (!empty($refresh) && $refresh == true) { config::save('refresh', false, 'netatmopro'); netatmopro::cron5(); } } /* * Fonction exécutée automatiquement toutes les 5 minutes par Jeedom public static function cron5() { } */ public static function cron5() { #if ( time() > config::byKey('expires_at', 'netatmopro') ) { # netatmopro::cronHourly(); #} try { netatmopro::synchronize(true); } catch (Exception $ex) { log::add('netatmopro', 'alert', 'cron5:: ex:' . var_export(get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); } } /* * Fonction exécutée automatiquement toutes les 10 minutes par Jeedom public static function cron10() { } */ /* * Fonction exécutée automatiquement toutes les 15 minutes par Jeedom public static function cron15() { } */ /* * Fonction exécutée automatiquement toutes les 30 minutes par Jeedom public static function cron30() { } */ /* * Fonction exécutée automatiquement toutes les heures par Jeedom */ public static function cronHourly() { #$config = array("client_id" => config::byKey('client_id', 'netatmopro'), # "client_secret" => config::byKey('client_secret', 'netatmopro'), # "access_token" => config::byKey('access_token', 'netatmopro'), # "refresh_token" => config::byKey('refresh_token', 'netatmopro'), # "expires_at" => config::byKey('expires_at', 'netatmopro'), # "scope" => 'read_station read_magellan write_magellan read_bubendorff write_bubendorff read_smarther write_smarther read_thermostat write_thermostat read_camera write_camera access_camera read_doorbell access_doorbell read_mx write_mx read_presence write_presence access_presence read_homecoach read_carbonmonoxidedetector read_smokedetector read_mhs1 write_mhs1'); #$client = new Netatmo\Clients\NAWSApiClient($config); #$tokens = $client->getAccessToken(); #log::add('netatmopro', 'debug', 'cronHourly:: jtokens:' . var_export(array("access_token" => config::byKey('access_token', 'netatmopro'), "refresh_token" => config::byKey('refresh_token', 'netatmopro'), "expires_at" => config::byKey('expires_at', 'netatmopro')), true)); #log::add('netatmopro', 'debug', 'cronHourly:: ntokens:' . var_export(array("access_token" => $client->_getAccessToken(), "refresh_token" => $client->_getRefreshToken(), "expires_at" => $client->_getExpiresAt()), true)); #config::save('access_token', $client->_getAccessToken(), 'netatmopro'); #config::save('refresh_token', $client->_getRefreshToken(), 'netatmopro'); #config::save('expires_at', $client->_getExpiresAt(), 'netatmopro'); } /* * Fonction exécutée automatiquement tous les jours par Jeedom public static function cronDaily() { } */ /* * *********************Méthodes d'instance************************* */ // Fonction exécutée automatiquement avant la création de l'équipement public function preInsert() { } // Fonction exécutée automatiquement après la création de l'équipement public function postInsert() { } // Fonction exécutée automatiquement avant la mise à jour de l'équipement public function preUpdate() { } // Fonction exécutée automatiquement après la mise à jour de l'équipement public function postUpdate() { } // Fonction exécutée automatiquement avant la sauvegarde (création ou mise à jour) de l'équipement public function preSave() { } // Fonction exécutée automatiquement après la sauvegarde (création ou mise à jour) de l'équipement public function postSave() { } // Fonction exécutée automatiquement avant la suppression de l'équipement public function preRemove() { } // Fonction exécutée automatiquement après la suppression de l'équipement public function postRemove() { } /* * Non obligatoire : permet de modifier l'affichage du widget (également utilisable par les commandes) public function toHtml($_version = 'dashboard') { } */ public function toHtml($_version = 'dashboard') { if ( $this->getConfiguration('type') == 'NAPerson' || $this->getConfiguration('type') == 'NAPlug' || $this->getConfiguration('type') == 'NATherm1' || $this->getConfiguration('type') == 'NARoom' || $this->getConfiguration('type') == 'NRV' || $this->getConfiguration('type') == 'NSD' || $this->getConfiguration('type') == 'NIS' || $this->getConfiguration('type') == 'NACamDoorTag' || $this->getConfiguration('type') == 'NDB' ) { return parent::toHtml(); } $replace = $this->preToHtml($_version); if (!is_array($replace)) { return $replace; } $version = jeedom::versionAlias($_version); $array = array( 'down' => '', 'up' => '', 'stable' => '', ); foreach ($this->getCmd() as $cmd) { if ($cmd->getType() == 'info') { $replace['#' . $cmd->getLogicalId() . '#'] = $cmd->execCmd(); } } if ( $this->getConfiguration('type') == 'NAMain' ) { $replace['#last_status_store#'] = date('H:i:s', $this->getConfiguration('last_status_store')); $replace['#TemperatureCSS#'] = $this->temperatureToCSS($replace['#Temperature#']); $replace['#temp_symbol#'] = (array_key_exists($replace['#temp_trend#'], $array) ? $array[$replace['#temp_trend#']] : ''); $replace['#pressure_symbol#'] = (array_key_exists($replace['#pressure_trend#'], $array) ? $array[$replace['#pressure_trend#']] : ''); } elseif ( $this->getConfiguration('type') == 'NAModule1' ) { $replace['#last_message#'] = date('H:i:s', $this->getConfiguration('last_message')); $replace['#TemperatureCSS#'] = $this->temperatureToCSS($replace['#Temperature#']); $replace['#temp_symbol#'] = (array_key_exists($replace['#temp_trend#'], $array) ? $array[$replace['#temp_trend#']] : ''); } elseif ( $this->getConfiguration('type') == 'NAModule2' ) { $replace['#last_message#'] = date('H:i:s', $this->getConfiguration('last_message')); $replace['#WindStrengthText#'] = $this->WindStrengthToLib($replace['#WindStrength#']); $replace['#WindAngleText#'] = $this->WindAngleToLib($replace['#WindAngle#']); $replace['#WingAngleCSS#'] = ".thearrow2,.thearrow2:after{left:50%;top:0;transition-duration:3s}.thearrow2:after,.thearrow2:before{content:'';position:absolute;box-sizing: border-box;}.thearrow2{transform:rotate(" . $replace['#WindAngle#'] . "deg);position:absolute;z-index:200;margin-left:-5px;width:10px;height:50%;transform-origin:50% 100%}.thearrow2:after{background-color:NONE;width:0;height:0;border-style:solid;border-width:14px 9px 0;border-color:RGBA(255,121,58,1) transparent transparent;transform:translate(-50%,-50%)}.thearrow2:before{width:6px;height:6px;z-index:9;left:2px;top:-5px;border:2px solid;border-radius:100%}"; } elseif ( $this->getConfiguration('type') == 'NAModule3' ) { $replace['#last_message#'] = date('H:i:s', $this->getConfiguration('last_message')); $SumRain24CSS1 = '
'; $SumRain24CSS2 = '