MMM-Carousel
MMM-Carousel copied to clipboard
[FEATURE REQUEST] Allow to ignore specific instances of a module when there are more (includes solution)
For a standard installation the weather module is included twice, these two instances have the same names weather
. Currently it is not possible to add just the one (i.e. the weekly forecast) to the carousel but keep the current weather static.
Description of solution By adding an identifier to the module configuration of the module instances that should be excluded it is possible to exclude specific instances.
Implementation of solution
By adding a searchName
variable that is determined by the existence of a carouselModuleId
with a fallback to module.name (making the change fully backwards compatible) it is possible to separate multiple instances of the same module (in the same position or globally)
Lines that need to be changed: https://github.com/shbatm/MMM-Carousel/blob/master/MMM-Carousel.js#L220-L227
setUpTransitionTimers: function (positionIndex) {
var modules, timer = this.config.transitionInterval;
modules = MM.getModules().exceptModule(this).filter(function (module) {
var searchName = module.config.carouselModuleId || module.name
if (positionIndex === null) {
return this.config.ignoreModules.indexOf(searchName) === -1;
}
return ((this.config[positionIndex].ignoreModules.indexOf(searchName) === -1) && (module.data.position === positionIndex));
}, this);
Usage:
{
module: "weather",
position: "top_right",
config: {
carouselModuleId: "weather1",
weatherProvider: "openweathermap",
type: "current",
}
},
{
module: "weather",
position: "top_right",
header: "Weather Forecast",
config: {
weatherProvider: "openweathermap",
type: "forecast",
}
},
{
module: 'MMM-Carousel',
config: {
transitionInterval: 4000,
mode: 'positional',
top_right: {enabled: true, ignoreModules: ['weather2']}
}
},
Implementation time 2 minutes.
carouselId
is used already in slides https://github.com/shbatm/MMM-Carousel#example---advanced-slides-carousel, that should be reused here as well. The Readme also needs to be updated to make that more clear of an option (this was originally build on the fork of the original so not much of the Readme was updated).
The module identifier should also be used as a search option.
The reason why I did not choose the carouselId was because it seemed like it was referencing a slide id
and not a module identifier. What is missing was a way to identify modules of the same type for use in the ignore modules.
I considered the module identifier, however that is not set, that is calculated based on the position of the module in the array (I think?), which can change when I add/remove/switch modules which for larger systems would be lots of refactoring.
The carouselId gets added to the module config just like you were proposing (actually it goes in the module definition at the same indent level as the config section), it can be generalized to be the unique ID for both positional and slide modes.
Note to self, the above solution only works by changing line 129 to listen on DOM_OBJECTS_CREATED