J’ai fait un test en partant de alexaapi version beta :
dans la class :
public static function templateWidget(){
$return = array('info' => array('string' => array()));
$return['info']['string']['alarm'] = array(
'replace' => array("#hide_name#" => "hidden","#marge_gauche#" => "55px", "#marge_haut#" => "15px"),
'template' => 'alarm',
'test' => array(
array(
'operation' => "#value# == ''",
'state_light' => "<img src='plugins/alexaapi/core/img/Alarm-Clock-Icon-Off.png' title ='" . __('Playing', __FILE__) . "'>",
'state_dark' => "<img src='plugins/alexaapi/core/img/Alarm-Clock-Icon-Off_dark.png' title ='" . __('En charge', __FILE__) . "'>"
),
array(
'operation' => "#value# != ''",
'state_light' => "<img src='plugins/alexaapi/core/img/Alarm-Clock-Icon-On.png' title ='" . __('En Pause', __FILE__) . "'>",
'state_dark' => "<img src='plugins/alexaapi/core/img/Alarm-Clock-Icon-On_dark.png' title ='" . __('En Pause', __FILE__) . "'>"
)
)
);
return $return;
}
Puis le widget, j’ai laissé des commentaires d’explications :
<div class="cmd cmd-widget #history#" data-type="info" data-subtype="numeric" data-template="tmplmultistate" data-cmd_id="#id#" data-cmd_uid="#uid#" data-version="#version#" data-eqLogic_id="#eqLogic_id#" style="display: block;margin-left: #marge_gauche#;margin-top: #marge_haut#;">
<div class="title #hide_name#">
<div class="cmdName">#name_display#</div>
</div>
<div class="content-sm">
<span class="iconCmd"></span>
</div>
<div class="content-xs" >
<span class="cmdName #hide_name#">#name_display# </span><br><p><strong class="state #hide_state#"></strong></p>
</div>
<div class="value">
<span class="timeCmd#uid# timeCmd label label-default value"></span>
</div>
<script>
//jeedom.cmd.update['#id#'] = function(_options){ // ancienne méthode
jeedom.cmd.addUpdateFunction('#id#', function(_options) { // // nouvelle méthode
//var cmd = $('.cmd[data-cmd_id=#id#]'); // jQuery
var cmd = document.querySelector('.cmd[data-cmd_uid="#uid#"]'); // JS
var now = new Date();
var inforecuperee=_options.display_value;
/* Modification des variables pour que _options.display_value reste brut */
if (inforecuperee == "none")
//_options.display_value="";
inforecuperee="";
else {
// 2019-12-02 19:45:00
//_options.display_value=inforecuperee.substr(11, 2)+":"+inforecuperee.substr(14, 2)+"<br>"
inforecuperee = _options.display_value.substr(11, 2)+":"+_options.display_value.substr(14, 2)+"<br>"
//if ((now.getFullYear()==inforecuperee.substr(0, 4)) && (now.getMonth() + 1 == inforecuperee.substr(5, 2))&& (now.getDate() == inforecuperee.substr(8, 2)))
//_options.display_value=_options.display_value+"Aujourd'hui";
if ((now.getFullYear()==_options.display_value.substr(0, 4)) && (now.getMonth() + 1 == _options.display_value.substr(5, 2))&& (now.getDate() == _options.display_value.substr(8, 2)))
inforecuperee=inforecuperee+"Aujourd'hui";
//else if ((now.getFullYear()==inforecuperee.substr(0, 4)) && (now.getMonth() + 1 == inforecuperee.substr(5, 2))&& (now.getDate() +1 == inforecuperee.substr(8, 2)))
//_options.display_value=_options.display_value+"Demain";
else if ((now.getFullYear()==_options.display_value.substr(0, 4)) && (now.getMonth() + 1 == _options.display_value.substr(5, 2))&& (now.getDate() +1 == _options.display_value.substr(8, 2)))
inforecuperee=inforecuperee+"Demain";
//else
//_options.display_value=_options.display_value+inforecuperee.substr(8, 2)+"-"+inforecuperee.substr(5, 2)+"-"+inforecuperee.substr(0, 4);
else
inforecuperee=inforecuperee+_options.display_value.substr(8, 2)+"-"+_options.display_value.substr(5, 2)+"-"+_options.display_value.substr(0, 4);
}
//cmd.attr('title','Date de valeur : '+_options.valueDate+'<br/>Date de collecte : '+_options.collectDate); // jQuery
cmd.setAttribute('title', '{{Date de valeur}}: ' + _options.valueDate + '<br>{{Date de collecte}}: ' + _options.collectDate) // JS
//cmd.find('.state').empty().append(_options.display_value); // jQuery
cmd.querySelector('.state').innerHTML = inforecuperee // JS
if('#_time_widget_#' == '1'){
//jeedom.cmd.displayDuration(_options.valueDate, cmd.find('.timeCmd')); // jQuery
jeedom.cmd.displayDuration(_options.valueDate, cmd.querySelector('.timeCmd'), '#time#'); // JS
}else{
//cmd.find('.timeCmd').parent().remove();
}
var state = '';
//cmd.attr('title','Date de valeur : '+_options.valueDate+'<br/>Date de collecte : '+_options.collectDate+'<br/>Valeur : '+_options.display_value+'#unite#'); // jQuery
cmd.setAttribute('title', '{{Date de valeur}}: ' + _options.valueDate + '<br>{{Date de collecte}}: ' + _options.collectDate) // JS
#test#
//cmd.find('.iconCmd').empty().append(state);
cmd.querySelector('.iconCmd').innerHTML = state
//var style = '';
if(!isNaN('#_desktop_width_#')){
//style = 'width:#_desktop_width_#px !important;'
cmd.querySelector('.iconCmd img').setAttribute('style', 'width:#_desktop_width_#px !important;') // JS
}
//cmd.find('.iconCmd img').attr('style',style); // jQuery déplacer en JS dans la condition ci-dessus
//cmd.off('changeThemeEventCmd').on('changeThemeEventCmd',function (event, theme) { //
document.body.addEventListener('changeThemeEvent', function() {
//console.log(theme);
console.log(jeedom.widgets.getThemeImg('Theme Light','Theme Dark'));
var state = '';
#change_theme#
if(state != ''){
//cmd.find('.iconCmd').empty().append(state); // jQuery
cmd.querySelector('.iconCmd').innerHTML = state // JS
}
//var style = '';
if(!isNaN('#_desktop_width_#')){
//style = '#_desktop_width_#px !important;'
cmd.querySelector('.iconCmd img').setAttribute('width', '#_desktop_width_#px !important;') // JS
}
//cmd.find('.iconCmd img').attr('style',style); // jQuery déplacer en JS dans la condition ci-dessus
});
//}
}) // nouvelle méthode
//jeedom.cmd.update['#id#']({display_value:'#state#',valueDate:'#valueDate#',collectDate:'#collectDate#',alertLevel:'#alertLevel#'});
jeedom.cmd.refreshValue([{ cmd_id: '#id#', value: '#value#', display_value: '#state#', valueDate: '#valueDate#', collectDate: '#collectDate#', alertLevel: '#alertLevel#', unit: '#unite#' }]) // Nouvelle méthode
/* // plus besoin
$('body').on('changeThemeEvent', function (event, theme) {
$('.cmd[data-cmd_id=#id#]').trigger('changeThemeEventCmd',theme);
});
*/
</script>
<!-- Hide parameters #_mobile_width_# -->
</div>