Skip to content

Commit

Permalink
add toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
zoic21 authored Aug 10, 2024
1 parent 690b291 commit fdf2152
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/class/gsh.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
include_file('core', 'gsh_LockUnlock', 'class', 'gsh');
include_file('core', 'gsh_MediaState', 'class', 'gsh');
include_file('core', 'gsh_Modes', 'class', 'gsh');
include_file('core', 'gsh_Toggle', 'class', 'gsh');
include_file('core', 'gsh_OnOff', 'class', 'gsh');
include_file('core', 'gsh_OpenClose', 'class', 'gsh');
include_file('core', 'gsh_SensorState', 'class', 'gsh');
Expand All @@ -51,22 +52,22 @@ class gsh extends eqLogic {

public static function getSupportedType() {
return array(
'action.devices.types.AC_UNIT' => array('name' => __('Climatiseur', __FILE__), 'traits' => array('FanSpeed', 'TemperatureSetting', 'OnOff')),
'action.devices.types.AIRCOOLER' => array('name' => __("Refroidisseur d'air", __FILE__), 'traits' => array('FanSpeed', 'TemperatureSetting', 'OnOff', 'HumiditySetting')),
'action.devices.types.AC_UNIT' => array('name' => __('Climatiseur', __FILE__), 'traits' => array('FanSpeed', 'TemperatureSetting', 'OnOff','Toggle')),
'action.devices.types.AIRCOOLER' => array('name' => __("Refroidisseur d'air", __FILE__), 'traits' => array('FanSpeed', 'TemperatureSetting', 'OnOff', 'HumiditySetting','Toggle')),
'action.devices.types.AIRFRESHENER' => array('name' => __('Désodorisant', __FILE__), 'traits' => array('Modes', 'Toggles', 'OnOff')),
'action.devices.types.AIRPURIFIER' => array('name' => __('Purificateur d\'air', __FILE__), 'traits' => array('FanSpeed', 'Modes', 'OnOff', 'SensorState', 'Toggles')),
'action.devices.types.AUDIO_VIDEO_RECEIVER' => array('name' => __('Ampli AV', __FILE__), 'traits' => array('OnOff', 'MediaState', 'InputSelector', 'AppSelector', 'TransportControl', 'Volume', 'Modes')),
'action.devices.types.AUDIO_VIDEO_RECEIVER' => array('name' => __('Ampli AV', __FILE__), 'traits' => array('OnOff', 'MediaState', 'InputSelector', 'AppSelector', 'TransportControl', 'Volume', 'Modes','Toggle')),
'action.devices.types.AWNING' => array('name' => __('Banne', __FILE__), 'traits' => array('Modes', 'OpenClose')),
'action.devices.types.BATHTUB ' => array('name' => __('Baignoire', __FILE__), 'traits' => array('OnOff', 'Fill')),
'action.devices.types.BLENDER' => array('name' => __('Mixeur', __FILE__), 'traits' => array('Cook', 'Timer', 'OnOff', 'StartStop')),
'action.devices.types.BLINDS' => array('name' => __('Store', __FILE__), 'traits' => array('Modes', 'OpenClose')),
'action.devices.types.BLENDER' => array('name' => __('Mixeur', __FILE__), 'traits' => array('Cook', 'Timer', 'OnOff', 'StartStop','Toggle')),
'action.devices.types.BLINDS' => array('name' => __('Store', __FILE__), 'traits' => array('Modes', 'OpenClose','Toggle')),
'action.devices.types.BOILER' => array('name' => __('Chaudière', __FILE__), 'traits' => array('Modes', 'TemperatureControl', 'OnOff', 'Toggles')),
'action.devices.types.CAMERA' => array('name' => __('Caméra', __FILE__), 'class' => 'gsh_camera'),
'action.devices.types.CARBON_MONOXIDE_DETECTOR' => array('name' => __('Detecteur de CO', __FILE__), 'traits' => array('SensorState')),
'action.devices.types.CLOSET' => array('name' => __('Placard', __FILE__), 'traits' => array('OpenClose')),
'action.devices.types.COFFEE_MAKER' => array('name' => __('Machine à café', __FILE__), 'traits' => array('Cook', 'OnOff', 'TemperatureControl')),
'action.devices.types.COOKTOP' => array('name' => __('Cuisine', __FILE__), 'traits' => array('Cook', 'Timer', 'OnOff', 'StartStop')),
'action.devices.types.CURTAIN' => array('name' => __('Rideaux', __FILE__), 'traits' => array('OpenClose')),
'action.devices.types.COFFEE_MAKER' => array('name' => __('Machine à café', __FILE__), 'traits' => array('Cook', 'OnOff', 'TemperatureControl','Toggle')),
'action.devices.types.COOKTOP' => array('name' => __('Cuisine', __FILE__), 'traits' => array('Cook', 'Timer', 'OnOff', 'StartStop','Toggle')),
'action.devices.types.CURTAIN' => array('name' => __('Rideaux', __FILE__), 'traits' => array('OpenClose','Toggle')),
'action.devices.types.DEHUMIDIFIER' => array('name' => __('Déshumidificateur', __FILE__), 'traits' => array('FanSpeed', 'HumiditySetting', 'OnOff', 'Modes', 'RunCycle', 'StartStop', 'Toggles')),
'action.devices.types.DEHYDRATOR' => array('name' => __('Déshydrateur', __FILE__), 'traits' => array('Cook', 'Timer', 'OnOff', 'Modes', 'Toggles', 'StartStop')),
'action.devices.types.DISHWASHER' => array('name' => __('Lave-vaiselle', __FILE__), 'traits' => array('OnOff', 'StartStop', 'Modes', 'Toggles', 'RunCycle')),
Expand Down
112 changes: 112 additions & 0 deletions core/class/gsh_Toggle.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

/* This file is part of Jeedom.
*
* Jeedom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Jeedom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
*/

/* * ***************************Includes********************************* */
require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';

class gsh_Toggle {

/* * *************************Attributs****************************** */

private static $_SET_TOGGLE = array('GB_TOGGLE','LIGHT_TOGGLE','TOGGLE');

/* * ***********************Methode static*************************** */

public static function discover($_device,$_eqLogic){
$return = array('traits' => array(),'customData' => array());
$availableToggle = array();
foreach ($_eqLogic->getCmd() as $cmd) {
if (!in_array($cmd->getGeneric_type(), self::$_SET_TOGGLE)) {
continue;
}
$names = explode(',',$_device->getOptions('Toggle::'.$cmd->getId().'::name'));
$names[] = $cmd->getName();
$availableToggle[] = array(
'name' => $cmd->getId(),
'name_values' => array(
array('name_synonym' => array_values(array_filter($names)),'lang' => substr(config::byKey('language'),0,2))
)
);
if (!in_array('action.devices.traits.Toggles', $return['traits'])) {
$return['traits'][] = 'action.devices.traits.Toggles';
}
}
if (in_array('action.devices.traits.Toggles', $return['traits'])) {
if (!isset($return['attributes'])) {
$return['attributes'] = array();
}
$return['attributes']['availableToggles'] = $availableToggle;
$return['attributes']['commandOnlyToggles'] = true;
}
return $return;
}

public static function needGenericType(){
return array(
__('Toggle',__FILE__) => self::$_SET_TOGGLE,
);
}

public static function exec($_device, $_executions, $_infos){
$return = array();
foreach ($_executions as $execution) {
try {
switch ($execution['command']) {
case 'action.devices.commands.SetToggles':
foreach ($execution['params']['updateToggleSettings'] as $key => $value) {
$cmd = cmd::byId($value);
if (!is_object($cmd)) {
continue;
}
$cmd->execCmd();
}
break;
}
} catch (Exception $e) {
log::add('gsh', 'error', $e->getMessage());
$return = array('status' => 'ERROR');
}
}
return $return;
}

public static function query($_device, $_infos){
$return = array();
return $return;
}

public static function getHtmlConfiguration($_eqLogic){
echo '<div class="form-group">';
echo '<label class="col-sm-3 control-label">{{Nom du toggle}}</label>';
echo '<div class="col-sm-3">';
echo '<input class="deviceAttr form-control" data-l1key="options" data-l2key="Toggle::modename"></input>';
echo '</div>';
echo '</div>';
foreach ($_eqLogic->getCmd() as $cmd) {
if (in_array($cmd->getGeneric_type(), self::$_SET_TOGGLE)) {
echo '<div class="form-group">';
echo '<label class="col-sm-3 control-label">{{Nom du toggle pour la commande}} : '.$cmd->getName().'</label>';
echo '<div class="col-sm-3">';
echo '<input class="deviceAttr form-control" data-l1key="options" data-l2key="Toggle::'.$cmd->getId().'::name"></input>';
echo '</div>';
echo '</div>';
}
}
}

}

0 comments on commit fdf2152

Please sign in to comment.