Comme annoncé, ce forum est passé en lecture seule au 1er janvier 2020. Désormais nous vous invitons à vous rendre sur notre nouvelle page communauté :
Image

A très bientôt !

Activation d'un menu déroulant et d'une checkbox

Cette partie est dédiée à la programmation sur le logiciel JEEDOM
freeman32
Timide
Messages : 428
Inscription : 27 mars 2016, 10:44

Activation d'un menu déroulant et d'une checkbox

Message par freeman32 » 08 sept. 2019, 08:35

Bonjour je m'essaie a modifier un plugin pour mon apprentissage personnel, j'ai créer un menu déroulant et une checkbox dans un plugin, seulement je ne sais comment faire pour m'en servir:
plugin enphase prod menu.png
plugin enphase prod menu.png (27.1 Kio) Consulté 2311 fois
Je veux que le menu déroulant me servent a choisir le type de machine sachant que celle-ci ne vont pas chercher les mêmes info et pour la case batterie il y en a ou il y 'en a pas. Actuellement le plugin fonctionnel par défaut est pour la machine dans le menu. Je vous met le code que j'ai mis dans le desktop/php pour créer le menu et la checkbox pour partit sur une bonne base :

Code : Tout sélectionner

<label class="col-sm-3 control-label">{{Type}}</label>
								<div class="col-sm-3">
									<select class=" form-control eqLogicAttr" data-l1key="configuration" data-l2key="type">
									<option value="envoy">Envoy-S</option>
									<option value="metered">Envoy-S Metered</option>
									</select>
								</div>
                            </div>
                            <div class="form-group">
							<label class="col-sm-3 control-label"></label>
								<div class="col-sm-9">
								<label class="checkbox-inline"><input type="checkbox" class="eqLogicAttr" data-l1key="configuration" data-l2key="acb" checked/>{{Batterie}}</label>
								</div>
							</div>
Je souhaiterais ensuite choisir entre 3 template pour le widget mais on verra ca plus tard

Merci de votre aide bon dimanche !
Gigabyte Brix + Debian 9.9 + Jeedom 3.3.24
UZB Sigma Designs + RFXCom + Ecodevice
8 Sondes Oregon + 1 Consomètre Oregon
Station Météo Netatmo + Pluviomètre + Anémomètre
8 FGRM-222
3 FGS-222
1 Qubino ZMNHJD1
1 Qubino ZMNHBD1

Mips2648
Actif
Messages : 932
Inscription : 08 sept. 2018, 17:09

Re: Activation d'un menu déroulant et d'une checkbox

Message par Mips2648 » 09 sept. 2019, 14:35

Salut,

Dans le code, généralement dans le fichier de la class eqLogic du plugin, pour récupérer la valeur tu fais peux faire

Code : Tout sélectionner

$eqLogic->getConfiguration('type')
$eqLogic ayant été initialisé avec ton équipement ou $this si tu es dans la class de l'eqLogic.

le 2eme argument est la valeur par défaut, par exemple, la checkbox qui serait décochée par défaut:

Code : Tout sélectionner

$eqLogic->getConfiguration('acb', 0)
Développeur et auteur des plugins suivants, (entre autre Arlo, Solaredge, Design Image, Gotify...) et aidant sur plein d'autres!

Si vous voulez contribuer, un don fait toujours plaisir : https://paypal.me/mips2648

freeman32
Timide
Messages : 428
Inscription : 27 mars 2016, 10:44

Re: Activation d'un menu déroulant et d'une checkbox

Message par freeman32 » 09 sept. 2019, 18:09

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()
Gigabyte Brix + Debian 9.9 + Jeedom 3.3.24
UZB Sigma Designs + RFXCom + Ecodevice
8 Sondes Oregon + 1 Consomètre Oregon
Station Météo Netatmo + Pluviomètre + Anémomètre
8 FGRM-222
3 FGS-222
1 Qubino ZMNHJD1
1 Qubino ZMNHBD1

freeman32
Timide
Messages : 428
Inscription : 27 mars 2016, 10:44

Re: Activation d'un menu déroulant et d'une checkbox

Message par freeman32 » 09 sept. 2019, 20:27

C'est bon j'ai fini par trouver mon erreur il manquait un $ a 3 endroit avant un info maintenant j'ai un autre problème mais avec le même code avec les $ en plus, si je fais un save dans le plugin j'ai ça :
erreur save.png
erreur save.png (170.89 Kio) Consulté 2244 fois
Et si je fais un save avec la case batterie cochée j'ai ça :
erreur save batterie.png
erreur save batterie.png (239.39 Kio) Consulté 2244 fois
Est ce normal et pourquoi ?

merci bonne soirée !
Gigabyte Brix + Debian 9.9 + Jeedom 3.3.24
UZB Sigma Designs + RFXCom + Ecodevice
8 Sondes Oregon + 1 Consomètre Oregon
Station Météo Netatmo + Pluviomètre + Anémomètre
8 FGRM-222
3 FGS-222
1 Qubino ZMNHJD1
1 Qubino ZMNHBD1

Répondre

Revenir vers « Développements sur Jeedom »

Qui est en ligne ?

Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 6 invités