getData_ functions check return false if no data

This commit is contained in:
KiboOst
2019-12-07 13:37:06 +01:00
parent 37ca955c08
commit d66ae0a6c6
2 changed files with 45 additions and 34 deletions

View File

@@ -96,6 +96,9 @@ Vous pouvez bien sûr personnaliser le fichier, pour lire un autre json avec d'a
## Version history ## Version history
#### v 0.12 (2019-12-07)
- Modified: getData_perhour(), getData_perday(), getData_permonth(), getData_peryear() now return false if data from Enedis are not correct (server down, etc).
#### v0.1 (2018-02-25) #### v0.1 (2018-02-25)
- Première version ! - Première version !

View File

@@ -8,7 +8,7 @@
class Linky{ class Linky{
public $_version = '0.11'; public $_version = '0.12';
public function getData_perhour($date) public function getData_perhour($date)
{ {
@@ -22,6 +22,8 @@ class Linky{
$resource_id = 'urlCdcHeure'; $resource_id = 'urlCdcHeure';
$result = $this->getData($resource_id, $startDate, $endDate); $result = $this->getData($resource_id, $startDate, $endDate);
if (!isset($result['graphe']['data'])) return false;
//format this correctly: //format this correctly:
$returnData = array(); $returnData = array();
$startHour = new DateTime('23:30'); $startHour = new DateTime('23:30');
@@ -56,6 +58,8 @@ class Linky{
$resource_id = 'urlCdcJour'; $resource_id = 'urlCdcJour';
$result = $this->getData($resource_id, $startDate, $endDate); $result = $this->getData($resource_id, $startDate, $endDate);
if (!isset($result['graphe']['data'])) return false;
//format this correctly: //format this correctly:
$returnData = array(); $returnData = array();
@@ -81,6 +85,8 @@ class Linky{
$resource_id = 'urlCdcMois'; $resource_id = 'urlCdcMois';
$result = $this->getData($resource_id, $startDate, $endDate); $result = $this->getData($resource_id, $startDate, $endDate);
if (!isset($result['graphe']['data'])) return false;
//format this correctly: //format this correctly:
$fromMonth = DateTime::createFromFormat('d/m/Y', $startDate); $fromMonth = DateTime::createFromFormat('d/m/Y', $startDate);
$returnData = array(); $returnData = array();
@@ -108,6 +114,8 @@ class Linky{
$resource_id = 'urlCdcAn'; $resource_id = 'urlCdcAn';
$result = $this->getData($resource_id, null, null); $result = $this->getData($resource_id, null, null);
if (!isset($result['graphe']['data'])) return false;
//format this correctly: //format this correctly:
$fromYear = new DateTime(); $fromYear = new DateTime();
$returnData = array(); $returnData = array();