Ok so I kinda made it work (just a few seconds ago - so I haven’t gone over all the case scenarios). My aim was to turn on and off the lights with a short click and open MoreInfo with a long press.
The way I did it was to modify floorplan-card.js to load the jquery longclick script and modify floorplan.js to include the modifications to the behaviour.
So floorplan-js, I had to modify the loading of scripts using promises since trying to load the jquery-longclick.js WITH jQuery would throw an error. I did this by adding a ‘then’ deferred function to load the longclick script after the first 3 main scripts are loaded.
loadScripts() {
this.isScriptsLoading = true;
const promises = [];
promises.push(this.loadScript(`/local/floorplan/lib/floorplan.js?v=${this.version}`, true));
promises.push(this.loadScript('/local/floorplan/lib/yaml.min.js', true));
promises.push(this.loadScript('/local/floorplan/lib/jquery-3.4.1.min.js', true));
return Promise.all(promises)
.then(() => { this.loadScript('/local/floorplan/lib/jquery.longclick.js', true); })
.then(() => {
this.isScriptsLoading = false;
this.isScriptsLoaded = true;
});
}
I then modified the function initEntityRule(rule, svg, svgElements)
and replace the line
$svgElement.off('click').on('click', this.onEntityClick.bind({ instance: this, svgElementInfo: svgElementInfo, entityId: entityId, rule: ruleInfo.rule }));
with
$svgElement
.mayTriggerLongClicks({ delay: 600 })
.on('longClick', this.onEntityLongClick.bind({ instance: this, entityId: entityId }))
.on('click', this.onEntityClick.bind({ instance: this, svgElementInfo: svgElementInfo, entityId: entityId, rule: ruleInfo.rule }));
The above new code references a new function which I added in the eventHandlers
section of the script just above onEntityClick(e) {
. This is the function:
onEntityLongClick(e) {
e.stopPropagation();
this.instance.openMoreInfo(this.entityId);
}
Flush browser cache and reload. Clicking on an element will call the action defined for that element, while long press will open more-info for the entity attached to that element. Just for reference (i’m using lovelace_gen), this is the yaml I’m using for the lights:
- action:
service: homeassistant.toggle
element: {{ lightname }}
entity: {{ lightname }}
class_template: 'bulb state-${entity.state} brightness-${Math.ceil(entity.attributes.brightness / 51)}'
more_info: false
Disclaimer: I’m a backend architect and developer by profession, but my frontend skills are poor; so I’m 100% certain that there’s a better way of doing this. Feel free to leave constructive criticism.