. */ /* * ***************************Includes********************************* */ require_once __DIR__ . '/../../../../core/php/core.inc.php'; use GuzzleHttp\Client; define('__ROOT__', dirname(dirname(dirname(__FILE__)))); require_once (__ROOT__.'/3rparty/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****************************** */ /* * ***********************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'), "username" => config::byKey('username', 'netatmopro'), "password" => config::byKey('password', 'netatmopro'), "scope" => 'read_station read_homecoach read_presence access_presence read_camera access_camera read_smokedetector read_thermostat write_thermostat'); $scope = ( $update === true ? config::byKey('scope', 'netatmopro') : [] ); 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:: NAWSApiClient'); $client = new Netatmo\Clients\NAWSApiClient($config); $tokens = $client->getAccessToken(); $data = $client->getData(); log::add('netatmopro', 'debug', 'synchronize:: WS:' . var_export($data, true)); foreach ($data['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->createEqLogic($module); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && $eqLogic->getConfiguration('last_message') < $module['last_message'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: M_UPDATE_IN_PROGRESS:' . var_export($module, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $module['dashboard_data'][$key]); } $eqLogic->checkAndUpdateCmd('battery_percent', $module['battery_percent']); $eqLogic->setConfiguration('station_name', $device['station_name']); $eqLogic->setConfiguration('firmware', $module['firmware']); $eqLogic->setConfiguration('rf_status', $module['rf_status']); $eqLogic->setConfiguration('battery_percent', $module['battery_percent']); $eqLogic->setConfiguration('last_message', $module['last_message']); $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->createEqLogic($device); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && $eqLogic->getConfiguration('last_status_store') < $device['last_status_store'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($device, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $device['dashboard_data'][$key]); } $eqLogic->setConfiguration('station_name', $device['station_name']); $eqLogic->setConfiguration('firmware', $device['firmware']); $eqLogic->setConfiguration('wifi_status', $device['wifi_status']); $eqLogic->setConfiguration('last_status_store', $device['last_status_store']); $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:: NAHomeApiClient'); $client = new Netatmo\Clients\NAHomeApiClient($config); $tokens = $client->getAccessToken(); $data = $client->getData(); log::add('netatmopro', 'debug', 'synchronize:: HOME:' . var_export($data, true)); foreach ($data['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->createEqLogic($device); $eqLogic->createCmd(); } if ( is_object($eqLogic) && ( $update === false || ( $update === true && $eqLogic->getConfiguration('last_status_store') < $device['last_status_store'] ) ) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($device, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $device['dashboard_data'][$key]); } $eqLogic->setConfiguration('firmware', $device['firmware']); $eqLogic->setConfiguration('wifi_status', $device['wifi_status']); $eqLogic->setConfiguration('last_status_store', $device['last_status_store']); $eqLogic->save(); $eqLogic->refreshWidget(); } if ($update === false) { $scope[] = 'read_homecoach'; } } } if ( $update === false || ( $update === true && preg_match("/read_presence access_presence read_camera access_camera read_smokedetector/", $scope) ) ) { log::add('netatmopro', 'debug', 'synchronize:: NAWelcomeApiClient'); $client = new Netatmo\Clients\NAWelcomeApiClient($config); $tokens = $client->getAccessToken(); $data = $client->getData(null, 0)->getDecodedBody(); log::add('netatmopro', 'debug', 'synchronize:: SECURITY:' . var_export($data, true)); foreach ($data['homes'] as $home) { foreach ($home['persons'] as $person) { if (!(array_key_exists('pseudo', $person))) continue; $person['type'] = 'NAPerson'; $eqLogic = eqLogic::byLogicalId($person['id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($person, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogic($person, $person['pseudo']); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($person, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $person[$key]); } $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->save(); } } $smokes = $modules = []; if (!empty($home['cameras']) || !empty($home['smokedetectors'])) { 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/gethomedata'; 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' => '{"home_id":"' . $home['id'] . '"}' ]); log::add('netatmopro', 'debug', 'synchronize:: response:' . var_export($response, true)); $wdata = json_decode($response->getBody()->getContents(), true); foreach ($wdata['body']['homes'] as $whome) { foreach ($whome['cameras'] as $wcamera) { if ( array_key_exists('modules', $wcamera) ) { foreach ($wcamera['modules'] as $wmodule) { $modules[$wmodule['id']] = $wmodule; } } } foreach ($whome['smokedetectors'] as $wsmoke) { $smokes[$wsmoke['id']] = $wsmoke; } } log::add('netatmopro', 'debug', 'synchronize:: modules:' . var_export($modules, true)); log::add('netatmopro', 'debug', 'synchronize:: smokes:' . var_export($smokes, true)); } foreach ($home['cameras'] as $camera) { $eqLogic = eqLogic::byLogicalId($camera['id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($camera, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogic($camera); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($camera, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $camera[$key]); } $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->setConfiguration('vpn_url', $camera['vpn_url']); $eqLogic->setConfiguration('is_local', $camera['is_local']); $eqLogic->save(); } if ( array_key_exists('modules', $camera) ) { foreach ($camera['modules'] as $module) { $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); $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', $modules[$module['id']]['firmware']); $eqLogic->setConfiguration('rf', $module['rf']); $eqLogic->setConfiguration('battery_percent', $module['battery_percent']); $eqLogic->batteryStatus($module['battery_percent']); if ( $module['type'] == 'NACamDoorTag' ) { $eqLogic->setConfiguration('category', $module['category']); } $eqLogic->save(); } } } } foreach ($home['smokedetectors'] as $smoke) { $eqLogic = eqLogic::byLogicalId($smoke['id'], 'netatmopro'); if (!is_object($eqLogic) && $update === false) { log::add('netatmopro', 'debug', 'synchronize:: D_CREATE_IN_PROGRESS:' . var_export($smoke, true)); $eqLogic = new netatmopro(); $eqLogic->createEqLogic($smoke); $eqLogic->createCmd(); } if ( is_object($eqLogic) ) { log::add('netatmopro', 'debug', 'synchronize:: D_UPDATE_IN_PROGRESS:' . var_export($smoke, true)); foreach ($eqLogic->getConfiguration('dashboard') as $key) { $eqLogic->checkAndUpdateCmd($key, $smokes[$smoke['id']][$key]); } $eqLogic->setConfiguration('home_id', $home['id']); $eqLogic->setConfiguration('home_name', $home['name']); $eqLogic->setConfiguration('firmware', $smokes[$smoke['id']]['firmware']); $eqLogic->setConfiguration('wifi_strength', $smokes[$smoke['id']]['wifi_strength']); $eqLogic->setConfiguration('battery_percent', $smokes[$smoke['id']]['battery_percent']); $eqLogic->batteryStatus($smokes[$smoke['id']]['battery_percent']); $eqLogic->save(); } } if ($update === false) { $scope[] = 'read_presence access_presence read_camera access_camera read_smokedetector'; } } log::add('netatmopro', 'debug', 'synchronize:: webhook:' . var_export(network::getNetworkAccess('external'), true)); $client->subscribeToWebhook(network::getNetworkAccess('external') . '/plugins/netatmopro/core/php/NAWebhookClient.php?apikey=' . jeedom::getApiKey('netatmopro')); } 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'); 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['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'); log::add('netatmopro', 'debug', 'synchronize:: ENERGY:' . var_export($status, true)); foreach ($status['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['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'; } } } if ( $update === false && !empty($scope) ) { log::add('netatmopro', 'debug', 'synchronize:: scope:' . var_export(implode(';', array_unique($scope)), true)); config::save('scope', implode(';', array_unique($scope)), 'netatmopro'); } } /* * Fonction exécutée automatiquement toutes les minutes par Jeedom */ 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 heures par Jeedom public static function cronHourly() { } */ /* * Fonction exécutée automatiquement tous les jours par Jeedom public static function cronDaily() { } */ public static function cron5() { /* * Netatmo\Exceptions\NAApiErrorType - 13 - Application does not have the good scope rights * Netatmo\Exceptions\NAApiErrorType - 500 - Internal Server Error * Netatmo\Exceptions\NACurlErrorType - 7 - Failed to connect to api.netatmo.com port 443: Connection refused * GuzzleHttp\Exception\ConnectException - 0 - cURL error 7: Failed to connect to app.netatmo.net port 443: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) * GuzzleHttp\Exception\ClientException - 403 - Client error: `POST https://xxx` resulted in a `403 Forbidden` response: {"error":{"code":2,"message":"Invalid access token"}} */ try { netatmopro::synchronize(true); } catch (Netatmo\Exceptions\NAApiErrorType $ex) { if ($ex->getCode() === 13 && $ex->getMessage() == 'Application does not have the good scope rights') { } elseif ($ex->getCode() === 500 && $ex->getMessage() == 'Internal Server Error') { } else { log::add('netatmopro', 'error', 'cron5:: ex:' . var_export('Netatmo\Exceptions\NAApiErrorType' . ' - ' . get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); throw $ex; } } catch (Netatmo\Exceptions\NACurlErrorType $ex) { if ($ex->getCode() === 7 && $ex->getMessage() == 'Failed to connect to api.netatmo.com port 443: Connection refused') { } else { log::add('netatmopro', 'error', 'cron5:: ex:' . var_export('Netatmo\Exceptions\NACurlErrorType' . ' - ' . get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); throw $ex; } } catch (GuzzleHttp\Exception\ClientException $ex) { if ($ex->getCode() === 403 && strpos($ex->getMessage(), '{"code":2,"message":"Invalid access token"}')) { $jar = new \GuzzleHttp\Cookie\FileCookieJar(jeedom::getTmpFolder('netatmopro') . '/b27536f76a9d4d240a34dbd84bc85085', true); $jar->clear(); $jar->save(jeedom::getTmpFolder('netatmopro') . '/b27536f76a9d4d240a34dbd84bc85085'); } else { log::add('netatmopro', 'error', 'cron5:: ex:' . var_export('GuzzleHttp\Exception\ClientException' . ' - ' . get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); throw $ex; } } catch (GuzzleHttp\Exception\ConnectException $ex) { if ($ex->getCode() === 0 && strpos($ex->getMessage(), 'cURL error 7: Failed to connect to app.netatmo.net port 443: Connection refused')) { } else { log::add('netatmopro', 'error', 'cron5:: ex:' . var_export('GuzzleHttp\Exception\ConnectException' . ' - ' . get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); throw $ex; } } catch (Exception $ex) { log::add('netatmopro', 'error', 'cron5:: ex:' . var_export(get_class($ex) . ' - ' . $ex->getCode() . ' - ' . $ex->getMessage(), true)); throw $ex; } } /* * *********************Méthodes d'instance************************* */ public function preInsert() { } public function postInsert() { } public function preSave() { } public function postSave() { } public function preUpdate() { } public function postUpdate() { } public function preRemove() { } public function postRemove() { } /* * Non obligatoire mais permet de modifier l'affichage du widget si vous en avez besoin */ 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' ) { 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 = '