La proposition de mettre un code postal en 2Axxx ne me convient pas. Ce n’est pas un correctif de bug, mais juste un pansement provisoire…
Le code postal est un code à 5 chiffres uniquement :
En 1976, le découpage du département insulaire de la Corse en deux départements a conduit l’Insee à remplacer le code 20 attribué à la Corse par ordre alphabétique, par les deux codes géographiques officiels de département ‹ 2A › (Ajaccio) pour la Corse-du-Sud et ‹ 2B › (Bastia) pour la Haute-Corse.
Les deux premiers chiffres des codes postaux ont été maintenus 20, mais la plupart des communes se sont vues alors attribuer un nouveau code postal, avec le troisième chiffre ‹ 1 › pour la Corse-du-Sud et un ‹ 2 › pour la Haute-Corse, à l’exception d’Ajaccio qui a conservé le ‹ 20000 › . Ainsi la commune de Sotta voit son code passer de ‹ 20284 › au code ‹ 20146 › . Il n’y a donc aucun code postal au-delà du ‹ 20300 ›.
En raison de leur évolution démographique, on a attribué aux communes de Furiani et Biguglia les codes ‹ 20600 › et ‹ 20620 › respectivement.
Il en ressort donc la mise à jour suivante de la fonction getVigilance() pour que cela fonctionne :
public function getVigilance() {
if ($this->getConfiguration('geoloc', 'none') == 'none') {
return;
}
if ($this->getConfiguration('geoloc') == "jeedom") {
$postal = config::byKey('info::postalCode');
$departement = $postal[0] . $postal[1];
if ($departement == '20') {
if ($postal[2] <= '1') {
$departement = '2A';
} else {
$departement = '2B';
}
}
} else {
$departement = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'),'location:department')->execCmd();
}
if ($departement == '92' || $departement == '93' || $departement == '94') {
$departement = '75';
}
$lvigilance = "vert";
$lcrue = "vert";
$lrisque = array();
$lmer = "vert";
$url = 'http://vigilance.meteofrance.com/data/NXFR34_LFPW_.xml';
$result = file($url);
if ($result === false) {
log::add(__CLASS__, 'error', 'Unable to fetch ' . $url);
return;
}
$doc = new DOMDocument();
$doc->load($url);
/* exemple extrait du fichier, il y a différents niveaux possibles pour les risques
<DV dep="33" coul="1"/>
<DV dep="3310" coul="1"/>
<DV dep="34" coul="3">
<risque val="4"/>
<risque val="3"/>
<risque val="2"/>
</DV>
<DV dep="34" coul="2">
<risque val="1"/>
</DV>
<DV dep="3410" coul="2">
<risque val="9"/>
</DV>
<DV dep="35" coul="1"/>
<DV dep="3510" coul="1"/>
*/
$doc2 = new DOMDocument();
$doc2->load('http://vigilance.meteofrance.com/data/NXFR33_LFPW_.xml');
foreach($doc->getElementsByTagName('datavigilance') as $data) {
if ($data->getAttribute('dep') == $departement) {
// On récupère le niveau général
$lvigilance = self::LEVEL[$data->getAttribute('couleur')];
// On cherche les alertes "crue"
foreach($data->getElementsByTagName('crue') as $crue) {
$lcrue = self::LEVEL[$crue->getAttribute('valeur')];
}
foreach($data->getElementsByTagName('risque') as $risque) {
switch ($risque->getAttribute('valeur')) {
case 1:
$lrisque[] = "vent";
break;
case 2:
$lrisque[] = "pluie-inondation";
break;
case 3:
$lrisque[] = "orages";
break;
case 4:
$lrisque[] = "inondations";
break;
case 5:
$lrisque[] = "neige-verglas";
break;
case 6:
$lrisque[] = "canicule";
break;
case 7:
$lrisque[] = "grand-froid";
break;
}
}
}
if ($data->getAttribute('dep') == $departement.'10') {
//alerte mer
switch ($data->getAttribute('couleur')) {
case 0:
$lmer = "vert";
break;
case 1:
$lmer = "vert";
break;
case 2:
$lmer = "jaune";
break;
case 3:
$lmer = "orange";
break;
case 4:
$lmer = "rouge";
break;
}
}
}
if (array_key_exists(0, $lrisque)) {
$lrisque = implode(", ", $lrisque);
} else {
$lrisque = 'RAS';
}
foreach($doc2->getElementsByTagName('DV') as $data) {
if ($data->getAttribute('dep') == $departement) {
$couleur = self::LEVEL[$data->getAttribute('coul')];
foreach($data->getElementsByTagName('risque') as $risque) {
switch ($risque->getAttribute('val')) {
case 1:
if ($lrisque == "RAS") {
$lrisque = "vent ".$couleur;
} else {
$lrisque = $lrisque . ", vent ".$couleur;
}
break;
case 2:
if ($lrisque == "RAS") {
$lrisque = "pluie-inondation ".$couleur;
} else {
$lrisque = $lrisque . ", pluie-inondation ".$couleur;
}
break;
case 3:
if ($lrisque == "RAS") {
$lrisque = "orages ".$couleur;
} else {
$lrisque = $lrisque . ", orages ".$couleur;
}
break;
case 4:
if ($lrisque == "RAS") {
$lrisque = "inondations ".$couleur;
} else {
$lrisque = $lrisque . ", inondations ".$couleur;
}
break;
case 5:
if ($lrisque == "RAS") {
$lrisque = "neige-verglas ".$couleur;
} else {
$lrisque = $lrisque . ", neige-verglas ".$couleur;
}
break;
case 6:
if ($lrisque == "RAS") {
$lrisque = "canicule ".$couleur;
} else {
$lrisque = $lrisque . ", canicule ".$couleur;
}
break;
case 7:
if ($lrisque == "RAS") {
$lrisque = "grand-froid ".$couleur;
} else {
$lrisque = $lrisque . ", grand-froid ".$couleur;
}
break;
case 8:
if ($lrisque == "RAS") {
$lrisque = "avalanches ".$couleur;
} else {
$lrisque = $lrisque . ", avalanches ".$couleur;
}
break;
case 9:
if ($lrisque == "RAS") {
$lrisque = "vagues-submersion ".$couleur;
} else {
$lrisque = $lrisque . ", vagues-submersion ".$couleur;
}
break;
}
}
}
}
log::add(__CLASS__, 'debug', 'Département ' . $departement);
log::add(__CLASS__, 'debug', 'Vigilance ' . $lvigilance);
log::add(__CLASS__, 'debug', 'Crue ' . $lcrue);
log::add(__CLASS__, 'debug', 'Risque ' . $lrisque);
$this->checkAndUpdateCmd('vigilance', $lvigilance);
$this->checkAndUpdateCmd('crue', $lcrue);
$this->checkAndUpdateCmd('risque', $lrisque);
$this->checkAndUpdateCmd('mer', $lmer);
return ;
}
La fonction getLink() est aussi à mettre à jour :
public function getLink() {
if (strpos(network::getNetworkAccess('external'),'https') !== false) {
$protocole='https://';
} else {
$protocole='http://';
}
if ($this->getConfiguration('type') == 'maree') {
$link = $protocole . 'maree.info/' . $this->getConfiguration('port');
}
if ($this->getConfiguration('type') == 'air') {
if ($this->getConfiguration('geoloc') == 'jeedom') {
$latitude = config::byKey('info::latitude');
$longitude = config::byKey('info::longitude');
} else {
$geotrav = eqLogic::byId($this->getConfiguration('geoloc'));
if (!(is_object($geotrav) && $geotrav->getEqType_name() == 'geotrav')) {
return;
}
$geolocval = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'),'location:coordinate')->execCmd();
$geoloctab = explode(',', trim($geolocval));
$latitude = trim($geoloctab[0]);
$longitude = trim($geoloctab[1]);
}
$link = $protocole . 'waqi.info/#/c/' . $latitude . '/' . $longitude . '/9.2z';
}
if ($this->getConfiguration('type') == 'surf') {
$link = $protocole . 'magicseaweed.com/';
}
if ($this->getConfiguration('type') == 'pollen') {
$link = $protocole . 'pollens.fr';
}
if ($this->getConfiguration('type') == 'gdacs') {
$link = $protocole . 'gdacs.org';
}
if ($this->getConfiguration('type') == 'plage') {
if ($this->getConfiguration('geoloc') == 'jeedom') {
$city = config::byKey('info::city');
$postal = config::byKey('info::postalCode');
} else {
$geotrav = eqLogic::byId($this->getConfiguration('geoloc'));
if (!(is_object($geotrav) && $geotrav->getEqType_name() == 'geotrav')) {
return;
}
$postal = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'),'location:zip')->execCmd();
$city = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'),'location:city')->execCmd();
}
$city = str_replace(' ','_',strtolower($city));
$city = preg_replace('#Ç#', 'C', $city);
$city = preg_replace('#ç#', 'c', $city);
$city = preg_replace('#è|é|ê|ë#', 'e', $city);
$city = preg_replace('#à|á|â|ã|ä|å#', 'a', $city);
$city = preg_replace('#ì|í|î|ï#', 'i', $city);
$city = preg_replace('#ð|ò|ó|ô|õ|ö#', 'o', $city);
$city = preg_replace('#ù|ú|û|ü#', 'u', $city);
$city = preg_replace('#ý|ÿ#', 'y', $city);
$city = preg_replace('#Ý#', 'Y', $city);
$city = str_replace('_', '-', $city);
$city = str_replace('\'', '', $city);
$link = $protocole . "www.meteofrance.com/previsions-meteo-plages/". $city ."/".$postal;
}
if ($this->getConfiguration('type') == 'vigilance') {
if ($this->getConfiguration('geoloc') == "jeedom") {
$postal = config::byKey('info::postalCode');
$departement = $postal[0] . $postal[1];
if ($departement == '20') {
if ($postal[2] <= '1') {
$departement = '2A';
} else {
$departement = '2B';
}
}
} else {
$departement = geotravCmd::byEqLogicIdAndLogicalId($this->getConfiguration('geoloc'),'location:department')->execCmd();
}
$link = $protocole . 'vigilance.meteofrance.com/Bulletin_sans.html?a=dept'.$departement.'&b=2&c=';
}
if ($this->getConfiguration('type') == 'crue') {
$link = $protocole . 'www.vigicrues.gouv.fr/niv3-station.php?CdStationHydro=' . $this->getConfiguration('station') . '&CdEntVigiCru=9&GrdSerie=H&ZoomInitial=3&CdStationsSecondaires=';
}
if ($this->getConfiguration('type') == 'pluie1h') {
$city = $this->getConfiguration('villeNom');
$explode = explode(' ',$city);
$city = $explode[0];
$postal = str_replace('(','',$explode[1]);
$postal = str_replace(')','',$postal);
$city = str_replace(' ','_',strtolower($city));
$city = preg_replace('#Ç#', 'C', $city);
$city = preg_replace('#ç#', 'c', $city);
$city = preg_replace('#è|é|ê|ë#', 'e', $city);
$city = preg_replace('#à|á|â|ã|ä|å#', 'a', $city);
$city = preg_replace('#ì|í|î|ï#', 'i', $city);
$city = preg_replace('#ð|ò|ó|ô|õ|ö#', 'o', $city);
$city = preg_replace('#ù|ú|û|ü#', 'u', $city);
$city = preg_replace('#ý|ÿ#', 'y', $city);
$city = preg_replace('#Ý#', 'Y', $city);
$city = str_replace('_', '-', $city);
$city = str_replace('\'', '', $city);
$link = $protocole . 'www.meteofrance.com/previsions-meteo-france/previsions-pluie/'. $city . '/' . $postal;
}
log::add(__CLASS__, 'debug', 'Link value : ' . $link);
return $link;
}
Merci de prendre en compte mes suggestions de corrections.