Bonjour merci de ta réponse effectivement j'ai trouvé a peu près la même chose dans un plugin qui ressemblait a ce que je voulais du coup j'ai fais ça mais ça fonctionne pas j'ai une erreur de classe inexistante mais j'arrive pas à trouver pourquoi :
Code : Tout sélectionner
public function postSave()
{
$info = $this->getCmd(null, 'now');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Instantané', __FILE__));
$info->setLogicalId('now');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('W');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_NOW');
$info->save();
$info = $this->getCmd(null, 'daily');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Journalier', __FILE__));
$info->setLogicalId('daily');
$info->setEqLogic_id($this->getId());
$info->setUnite('Wh');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_DAILY');
$info->save();
$info = $this->getCmd(null, 'lifetime');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Cumulé', __FILE__));
$info->setLogicalId('lifetime');
$info->setEqLogic_id($this->getId());
$info->setUnite('Wh');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_LIFETIME');
$info->save();
$info = $this->getCmd(null, 'SevenDays');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Cumulé 7 Jours', __FILE__));
$info->setLogicalId('SevenDays');
$info->setEqLogic_id($this->getId());
$info->setUnite('Wh');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_SevenDays');
$info->save();
// Si configuration Envoy-S Metered
if ($this->getConfiguration('type') == 'metered'){
// Creation info Conso Instantanée
$info = $this->getCmd(null, 'cnow');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Conso Instantané', __FILE__));
$info->setLogicalId('cnow');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('W');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_CNOW');
$info->save();
// Creation info Conso Nette Instantanée
$info = $this->getCmd(null, 'cnnow');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Conso Nette Instantané', __FILE__));
$info->setLogicalId('cnnow');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('W');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_CNNOW');
$info->save();
// Creation info Tension
$info = $this->getCmd(null, 'volt');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Tension', __FILE__));
$info->setLogicalId('volt');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('V');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_VOLT');
$info->save();
// Creation info Intensité
$info = $this->getCmd(null, 'amp');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Intensité', __FILE__));
$info->setLogicalId('amp');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('A');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_AMP');
$info->save();
}
// Si case batterie cochée
if($this->getConfiguration('acb') == '1'){
// Creation info nombre batterie
$info = $this->getCmd(null, 'nbbat');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Nombre Batterie', __FILE__));
$info->setLogicalId('nbbat');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(0);
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_BAT');
$info->save();
// Creation info batterie wNow
$info = $this->getCmd(null, 'bwnow');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Puissance Intantané Batterie', __FILE__));
$info->setLogicalId('bwnow');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('W');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_BWNOW');
$info->save();
// Creation info capacitée restante batterie
$info = $this->getCmd(null, 'bwhnow');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Capacitée Restante Batterie', __FILE__));
$info->setLogicalId('bwhnow');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('Wh');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_BWHNOW');
$info->save();
// Creation info capacitée restante batterie %
$info = $this->getCmd(null, 'percentFull');
if (!is_object($info)) {
$info = new enphase_prodCmd();
}
$info->setName(__('Capacitée Restante Batterie %', __FILE__));
$info->setLogicalId('percentFull');
$info->setEqLogic_id($this->getId());
$info->setIsHistorized(1);
$info->setUnite('%');
$info->setType('info');
$info->setSubType('numeric');
$info->setDisplay('generic_type', 'ENPHASE_BATPERCENT');
$info->save();
// Supression des commandes si batterie décoché
}elseif ($this->getConfiguration('acb') == '0') {
$info = $this->getCmd(null, 'nbbat');
if ( is_object($info)) {
$info->remove();
}
info = $this->getCmd(null, 'bwnow');
if ( is_object($info)) {
$info->remove();
}
info = $this->getCmd(null, 'bwhnow');
if ( is_object($info)) {
$info->remove();
}
info = $this->getCmd(null, 'percentFull');
if ( is_object($info)) {
$info->remove();
}
}
}
public function preUpdate()
{
switch ('') {
case $this->getConfiguration('ip'):
throw new Exception(__('L\'adresse IP ne peut être vide', __FILE__));
case $this->getConfiguration('user'):
throw new Exception(__('L\'identifiant ne peut être vide', __FILE__));
case $this->getConfiguration('pass'):
throw new Exception(__('Le mot de passe ne peut être vide', __FILE__));
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getConfiguration('ip') . '/api/v1/production/inverters');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $this->getConfiguration('user') . ":" . $this->getConfiguration('pass'));
$response = curl_exec($ch);
curl_close($ch);
$json_data = json_decode($response, true);
log::add('enphase_prod', 'debug', 'retour :'. $this->getConfiguration('ip'). ":".$this->getConfiguration('user') . ":" . $this->getConfiguration('pass') . ":" . count($json_data).":" .$json_data['status']);
if ($json_data['status'] == 401) {
throw new Exception(__('impossible de se connecte au controleur, merci de verifié vos parametre', __FILE__));
}
//Vérification du type d'envoy, présence de pinces ou non
if($this->getConfiguration('type') == 'metered'){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getConfiguration('ip') . '/production.json');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $this->getConfiguration('user') . ":" . $this->getConfiguration('pass'));
$response = curl_exec($ch);
curl_close($ch);
var_dump(json_decode($response));
$json_data = json_decode($response);
log::add('enphase_prod', 'debug', 'retour :'.$json_data->{"storage"}[0]->{"activeCount"} . $json_data->{"consumption"}[0]->{"activeCount"});
if ($json_data->{"production"}[1]->{"activeCount"} == 0 && $json_data->{"consumption"}[0]->{"activeCount"} == 0) {
throw new Exception(__('Vous n avez pas de pinces ampérométrique sur le système ou elle ne sont pas activées, merci de verifié vos paramètres de votre Envoy-S Metered, sinon basculer sur Envoy-s', __FILE__));
}
}
//Vérification de la présence de batterie si coché
if($this->getConfiguration('acb') == '1'){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getConfiguration('ip') . '/production.json');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $this->getConfiguration('user') . ":" . $this->getConfiguration('pass'));
$response = curl_exec($ch);
curl_close($ch);
var_dump(json_decode($response));
$json_data = json_decode($response);
log::add('enphase_prod', 'debug', 'retour :'.$json_data->{"storage"}[0]->{"activeCount"});
if ($json_data->{"storage"}[0]->{"activeCount"} == 0) {
throw new Exception(__('impossible de trouver des batteries, merci de verifié vos paramètres', __FILE__));
}
}
}
public function postUpdate()