/**
  * Get virtual stations (OWM).
  *
  * @return  array   An array containing the virtual stations.
  * @since    1.0.0
  * @access   protected
  */
 protected function get_virtual_stations()
 {
     $result = array();
     $stations = $this->get_all_owm_stations();
     if (count($stations) > 0) {
         foreach ($stations as $station) {
             $sub = array();
             $sub['_id'] = Owm_Client::get_unique_owm_id($station['station_id']);
             $sub['module_name'] = $station['station_name'];
             $sub['station_name'] = $station['station_name'];
             $sub['wifi_status'] = 0;
             $sub['firmware'] = LWS_VERSION;
             $sub['type'] = 'NAMain';
             $sub['data_type'] = array();
             $dd = array();
             $dd['time_utc'] = time();
             $plc = array();
             $plc['altitude'] = $station['loc_altitude'];
             $plc['city'] = $station['loc_city'];
             $plc['country'] = $station['loc_country_code'];
             $plc['timezone'] = $station['loc_timezone'];
             $plc['improveLocProposed'] = true;
             $plc['location'] = array($station['loc_longitude'], $station['loc_latitude']);
             $sub['place'] = $plc;
             $sub['dashboard_data'] = $dd;
             $result['devices'][] = $sub;
         }
     }
     return $result;
 }
 /**
  * Callback method for querying datas by the lcd control.
  *
  * @since    1.0.0
  */
 public function lws_query_lcd_datas_callback()
 {
     $device_id = wp_kses($_POST['device_id'], array());
     $module_id = wp_kses($_POST['module_id'], array());
     $measure_type = wp_kses($_POST['measure_type'], array());
     $computed = !(bool) get_option('live_weather_station_settings')[3];
     if (strtolower($module_id) == 'outdoor' || strtolower($measure_type) == 'aggregated' && Owm_Client::is_owm_module($module_id)) {
         $raw_datas = $this->get_outdoor_datas($device_id, true);
         $measure_type == 'outdoor';
     } elseif (strtolower($module_id) == 'aggregated') {
         $raw_datas = $this->get_all_datas($device_id, true);
     } else {
         $raw_datas = $this->get_module_datas($module_id, true);
     }
     $response = array();
     if (array_key_exists('condition', $raw_datas)) {
         $measure['min'] = 0;
         $measure['max'] = 0;
         $measure['value'] = 0;
         $measure['unit'] = '';
         $measure['decimals'] = 1;
         $measure['sub_unit'] = '';
         $measure['show_sub_unit'] = false;
         $measure['show_min_max'] = false;
         $measure['title'] = __('Error code ', 'live-weather-station') . $raw_datas['condition']['value'];
         if ($raw_datas['condition']['value'] == 3 || $raw_datas['condition']['value'] == 4) {
             $save_locale = setlocale(LC_ALL, '');
             setlocale(LC_ALL, get_locale());
             $measure['title'] = iconv('UTF-8', 'ASCII//TRANSLIT', __('No data', 'live-weather-station'));
             setlocale(LC_ALL, $save_locale);
         }
         $measure['battery'] = 'full';
         $measure['trend'] = '';
         $measure['show_trend'] = false;
         $measure['show_alarm'] = true;
         $measure['signal'] = 0;
         $response[] = $measure;
     } else {
         $datas = $this->format_lcd_datas($raw_datas, $measure_type, $computed);
         if ($datas['condition']['value'] != 0) {
             $measure['min'] = 0;
             $measure['max'] = 0;
             $measure['value'] = 0;
             $measure['unit'] = '';
             $measure['decimals'] = 1;
             $measure['sub_unit'] = '';
             $measure['show_sub_unit'] = false;
             $measure['show_min_max'] = false;
             $measure['title'] = __('Error code ', 'live-weather-station') . $datas['condition']['value'];
             if ($datas['condition']['value'] == 3 || $datas['condition']['value'] == 4) {
                 $save_locale = setlocale(LC_ALL, '');
                 setlocale(LC_ALL, get_locale());
                 $measure['title'] = iconv('UTF-8', 'ASCII//TRANSLIT', __('No data', 'live-weather-station'));
                 setlocale(LC_ALL, $save_locale);
             }
             $measure['battery'] = 'full';
             $measure['trend'] = '';
             $measure['show_trend'] = false;
             $measure['show_alarm'] = true;
             $measure['signal'] = 0;
             $response[] = $measure;
         } else {
             $response = $datas['datas'];
         }
     }
     exit(json_encode($response));
 }
        ?>
    <div id="normal-sortables" class="meta-box-sortables ui-sortable">
        <div id="referrers" class="postbox ">
            <div class="handlediv" title="<?php 
        echo __('Click to toggle', 'live-weather-station');
        ?>
"><br></div>
            <h3 class="hndle"><span><?php 
        echo $device['station_name'];
        ?>
</span></h3>
            <div class="inside">
                <table cellspacing="0">
                    <tbody>
                    <?php 
        if (!Owm_Client::is_owm_station($device['_id'])) {
            ?>
                    <tr>
                        <th scope="row" width="20%" align="left"><img class="lws-logo" src="<?php 
            echo LWS_ADMIN_URL . 'images/NAMain.png';
            ?>
" /><span class="lws-module-name"><?php 
            echo $device['module_name'];
            ?>
</span></th>
                        <td width="5%"/>
                        <td align="left">
                            <span>
                                <?php 
            esc_attr_e('Location', 'live-weather-station');
            echo ': ' . $device['place']['city'] . ', ' . $device['place']['country'];
 /**
  * Get station's datas.
  *
  * @return  array   An array containing the available station's datas ready to convert to a JS array.
  * @param   boolean     $full The array must contain all measured data types including operational datas.
  * @param   boolean     $aggregated The array must contain aggregated data types.
  * @param   boolean     $reduced The array is reduced. i.e. contains only modules and measures.
  * @param   boolean     $computed The array must contain computed data types.
  * @param   boolean     $mono The array must contain min/max.
  * @since    1.0.0
  * @access   protected
  */
 protected function get_js_array($datas, $full = true, $aggregated = false, $reduced = false, $computed = false, $mono = false)
 {
     $result = array();
     if (count($datas) == 0) {
         return $result;
     }
     foreach ($datas['devices'] as $device) {
         $netatmo = !Owm_Client::is_owm_station($device['_id']);
         $t_module = array();
         if ($aggregated && count($device['modules']) > 1 && $netatmo) {
             $sample = array();
             $sample['device_id'] = 'aggregated';
             $sample['device_name'] = $device['station_name'];
             $sample['module_id'] = 'aggregated';
             $sample['module_type'] = 'aggregated';
             $sample['module_name'] = __('[all modules]', 'live-weather-station');
             $sample['measure_values'] = $device['dashboard_data'];
             $sample['battery_vp'] = 0;
             $sample['rf_status'] = $device['wifi_status'];
             $sample['place'] = $device['place'];
             $t_module[] = array($sample['module_name'], $sample['device_id'], $this->get_td_measure($sample, $full, $aggregated, $reduced, $computed, $mono));
         }
         if ($netatmo || $full) {
             $sample = array();
             $sample['device_id'] = $device['_id'];
             $sample['device_name'] = $device['station_name'];
             $sample['module_id'] = $device['_id'];
             $sample['module_type'] = $device['type'];
             $sample['module_name'] = $device['module_name'];
             $sample['measure_values'] = $device['dashboard_data'];
             $sample['battery_vp'] = 0;
             $sample['rf_status'] = $device['wifi_status'];
             $sample['firmware'] = $device['firmware'];
             $sample['place'] = $device['place'];
             $t_module[] = array($device['module_name'], $device['_id'], $this->get_td_measure($sample, $full, $aggregated, $reduced, $computed, $mono));
         }
         foreach ($device['modules'] as $module) {
             if (($module['type'] == 'NAComputed' || $module['type'] == 'NAEphemer') && !$computed) {
                 continue;
             }
             if ($module['type'] == 'NAEphemer' && ($computed && !$full)) {
                 continue;
             }
             $sample = array();
             $sample['device_id'] = $device['_id'];
             $sample['device_name'] = $device['station_name'];
             $sample['module_id'] = $module['_id'];
             $sample['module_type'] = $module['type'];
             $sample['module_name'] = $module['module_name'];
             $sample['measure_values'] = $module['dashboard_data'];
             $sample['battery_vp'] = $module['battery_vp'];
             $sample['rf_status'] = $module['rf_status'];
             $sample['firmware'] = $module['firmware'];
             $sample['place'] = $device['place'];
             $t_module[] = array($module['module_name'], $module['_id'], $this->get_td_measure($sample, $full, $aggregated, $reduced, $computed, $mono));
         }
         $result[] = array($device['station_name'], $device['_id'], $t_module);
     }
     return $result;
 }