Skip to content

Commit bee73f6

Browse files
committed
Allow settings double-tab and hold actions
Closes #109
1 parent 25c8567 commit bee73f6

File tree

5 files changed

+117
-22
lines changed

5 files changed

+117
-22
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ that allow you to customize the entity according to your needs.
106106

107107
* Display type - Configure how the entity is displayed on the floorplan, see
108108
[Elements](https://www.home-assistant.io/dashboards/picture-elements/#elements)
109-
* Tap Action - Define what to do when the entity is tapped/clicked on, see
110-
[Tap Action](https://www.home-assistant.io/dashboards/actions/#tap-action)
109+
* Tap action - Define what to do when the entity is tapped/clicked on, see
110+
[Tap action](https://www.home-assistant.io/dashboards/actions/#tap-action)
111+
* Double tap action - Define what to do when the entity is double-tapped/clicked
112+
on, see [Double tap Action](https://www.home-assistant.io/dashboards/actions/#double-tap-action)
113+
* Hold Action - Define what to do when the entity is held/long-pressed, see
114+
[Hold action](https://www.home-assistant.io/dashboards/actions/#hold-action)
111115
* Always on - Only for lights, set light as always on removing its icon and it
112116
won't be affected by the matching Home Assistant state
113117
* Is RGB(W) light - Only for lights, set light as an RGB light that will change

doc/entityOptions.png

1.68 KB
Loading

src/com/shmuelzon/HomeAssistantFloorPlan/ApplicationPlugin.properties

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ HomeAssistantFloorPlan.Panel.displayTypeComboBox.ICON.text=Icon
5656
HomeAssistantFloorPlan.Panel.displayTypeComboBox.LABEL.text=Label
5757
HomeAssistantFloorPlan.Panel.displayTypeComboBox.NONE.text=None
5858
HomeAssistantFloorPlan.Panel.tapActionLabel.text=Tap action:
59-
HomeAssistantFloorPlan.Panel.tapActionComboBox.MORE_INFO.text=More info
60-
HomeAssistantFloorPlan.Panel.tapActionComboBox.NONE.text=None
61-
HomeAssistantFloorPlan.Panel.tapActionComboBox.TOGGLE.text=Toggle
59+
HomeAssistantFloorPlan.Panel.doubleTapActionLabel.text=Double tap action:
60+
HomeAssistantFloorPlan.Panel.holdActionLabel.text=Hold action:
61+
HomeAssistantFloorPlan.Panel.actionComboBox.MORE_INFO.text=More info
62+
HomeAssistantFloorPlan.Panel.actionComboBox.NONE.text=None
63+
HomeAssistantFloorPlan.Panel.actionComboBox.TOGGLE.text=Toggle
6264
HomeAssistantFloorPlan.Panel.alwaysOnLabel.text=Always on:
6365
HomeAssistantFloorPlan.Panel.isRgbLabel.text=Is RGB(W) light:
6466

src/com/shmuelzon/HomeAssistantFloorPlan/Controller.java

+44-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public enum Renderer {YAFARAY, SUNFLOW}
4343
public enum Quality {HIGH, LOW}
4444
public enum ImageFormat {PNG, JPEG}
4545
public enum EntityDisplayType {BADGE, ICON, LABEL, NONE}
46-
public enum EntityTapAction {MORE_INFO, NONE, TOGGLE}
46+
public enum EntityAction {MORE_INFO, NONE, TOGGLE}
4747

4848
private static final String TRANSPARENT_IMAGE_NAME = "transparent";
4949

@@ -59,6 +59,8 @@ public enum EntityTapAction {MORE_INFO, NONE, TOGGLE}
5959
private static final String CONTROLLER_USE_EXISTING_RENDERS = "useExistingRenders";
6060
private static final String CONTROLLER_ENTITY_DISPLAY_TYPE = "displayType";
6161
private static final String CONTROLLER_ENTITY_TAP_ACTION = "tapAction";
62+
private static final String CONTROLLER_ENTITY_DOUBLE_TAP_ACTION = "doubleTapAction";
63+
private static final String CONTROLLER_ENTITY_HOLD_ACTION = "holdAction";
6264
private static final String CONTROLLER_ENTITY_ALWAYS_ON = "alwaysOn";
6365
private static final String CONTROLLER_ENTITY_IS_RGB = "isRgb";
6466

@@ -92,16 +94,20 @@ private class Entity {
9294
public String name;
9395
public Point2d position;
9496
public EntityDisplayType displayType;
95-
public EntityTapAction tapAction;
97+
public EntityAction tapAction;
98+
public EntityAction doubleTapAction;
99+
public EntityAction holdAction;
96100
public String title;
97101
public boolean alwaysOn;
98102
public boolean isRgb;
99103

100-
public Entity(String name, Point2d position, EntityDisplayType defaultDisplayType, EntityTapAction defaultTapAction, String title) {
104+
public Entity(String name, Point2d position, EntityDisplayType defaultDisplayType, EntityAction defaultTapAction, String title) {
101105
this.name = name;
102106
this.position = position;
103107
this.displayType = EntityDisplayType.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_DISPLAY_TYPE, defaultDisplayType.name()));
104-
this.tapAction = EntityTapAction.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_TAP_ACTION, defaultTapAction.name()));
108+
this.tapAction = EntityAction.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_TAP_ACTION, defaultTapAction.name()));
109+
this.doubleTapAction = EntityAction.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_DOUBLE_TAP_ACTION, EntityAction.NONE.name()));
110+
this.holdAction = EntityAction.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_HOLD_ACTION, EntityAction.MORE_INFO.name()));
105111
this.title = title;
106112
this.alwaysOn = settings.getBoolean(name + "." + CONTROLLER_ENTITY_ALWAYS_ON, false);
107113
this.isRgb = settings.getBoolean(name + "." + CONTROLLER_ENTITY_IS_RGB, false);
@@ -273,15 +279,33 @@ public void setEntityDisplayType(String entityName, EntityDisplayType displayTyp
273279
settings.set(entityName + "." + CONTROLLER_ENTITY_DISPLAY_TYPE, displayType.name());
274280
}
275281

276-
public EntityTapAction getEntityTapAction(String entityName) {
282+
public EntityAction getEntityTapAction(String entityName) {
277283
return homeAssistantEntities.get(entityName).tapAction;
278284
}
279285

280-
public void setEntityTapAction(String entityName, EntityTapAction tapAction) {
286+
public void setEntityTapAction(String entityName, EntityAction tapAction) {
281287
homeAssistantEntities.get(entityName).tapAction = tapAction;
282288
settings.set(entityName + "." + CONTROLLER_ENTITY_TAP_ACTION, tapAction.name());
283289
}
284290

291+
public EntityAction getEntityDoubleTapAction(String entityName) {
292+
return homeAssistantEntities.get(entityName).doubleTapAction;
293+
}
294+
295+
public void setEntityDoubleTapAction(String entityName, EntityAction doubleTapAction) {
296+
homeAssistantEntities.get(entityName).doubleTapAction = doubleTapAction;
297+
settings.set(entityName + "." + CONTROLLER_ENTITY_DOUBLE_TAP_ACTION, doubleTapAction.name());
298+
}
299+
300+
public EntityAction getEntityHoldAction(String entityName) {
301+
return homeAssistantEntities.get(entityName).holdAction;
302+
}
303+
304+
public void setEntityHoldAction(String entityName, EntityAction holdAction) {
305+
homeAssistantEntities.get(entityName).holdAction = holdAction;
306+
settings.set(entityName + "." + CONTROLLER_ENTITY_HOLD_ACTION, holdAction.name());
307+
}
308+
285309
public boolean getEntityAlwaysOn(String entityName) {
286310
return homeAssistantEntities.get(entityName).alwaysOn;
287311
}
@@ -311,6 +335,8 @@ public void resetEntitySettings(String entityName) {
311335
boolean oldIsRgb = homeAssistantEntities.get(entityName).isRgb;
312336
settings.set(entityName + "." + CONTROLLER_ENTITY_DISPLAY_TYPE, null);
313337
settings.set(entityName + "." + CONTROLLER_ENTITY_TAP_ACTION, null);
338+
settings.set(entityName + "." + CONTROLLER_ENTITY_DOUBLE_TAP_ACTION, null);
339+
settings.set(entityName + "." + CONTROLLER_ENTITY_HOLD_ACTION, null);
314340
settings.set(entityName + "." + CONTROLLER_ENTITY_ALWAYS_ON, null);
315341
settings.set(entityName + "." + CONTROLLER_ENTITY_IS_RGB, null);
316342
int oldNumberOfTotaleRenders = getNumberOfTotalRenders();
@@ -801,10 +827,10 @@ private String generateEntityYaml(Entity entity) {
801827
put(EntityDisplayType.ICON, "state-icon");
802828
put(EntityDisplayType.LABEL, "state-label");
803829
}};
804-
final Map<EntityTapAction, String> entityTapActionToYamlString = new HashMap<EntityTapAction, String>() {{
805-
put(EntityTapAction.MORE_INFO, "more-info");
806-
put(EntityTapAction.NONE, "none");
807-
put(EntityTapAction.TOGGLE, "toggle");
830+
final Map<EntityAction, String> entityTapActionToYamlString = new HashMap<EntityAction, String>() {{
831+
put(EntityAction.MORE_INFO, "more-info");
832+
put(EntityAction.NONE, "none");
833+
put(EntityAction.TOGGLE, "toggle");
808834
}};
809835

810836
if (entity.displayType == EntityDisplayType.NONE || entity.alwaysOn)
@@ -821,10 +847,15 @@ private String generateEntityYaml(Entity entity) {
821847
" text-align: center\n" +
822848
" background-color: rgba(255, 255, 255, 0.3)\n" +
823849
" tap_action:\n" +
850+
" action: %s\n" +
851+
" double_tap_action:\n" +
852+
" action: %s\n" +
853+
" hold_action:\n" +
824854
" action: %s\n",
825855
entityDisplayTypeToYamlString.get(entity.displayType), entity.name, entity.title,
826856
100.0 * (entity.position.y / renderHeight), 100.0 * (entity.position.x / renderWidth),
827-
entityTapActionToYamlString.get(entity.tapAction));
857+
entityTapActionToYamlString.get(entity.tapAction), entityTapActionToYamlString.get(entity.doubleTapAction),
858+
entityTapActionToYamlString.get(entity.holdAction));
828859

829860
return yaml;
830861
}
@@ -855,7 +886,7 @@ private void generateLightEntities(Map<String, Entity> homeAssistantEntities) {
855886
lightsCenter.scale(1.0 / lightsList.size());
856887

857888
String name = lightsList.get(0).getName();
858-
homeAssistantEntities.put(name, new Entity(name, lightsCenter, EntityDisplayType.ICON, EntityTapAction.TOGGLE,
889+
homeAssistantEntities.put(name, new Entity(name, lightsCenter, EntityDisplayType.ICON, EntityAction.TOGGLE,
859890
lightsList.get(0).getDescription()));
860891
}
861892
}
@@ -884,7 +915,7 @@ private void generateSensorEntities(Map<String, Entity> homeAssistantEntities) {
884915

885916
homeAssistantEntities.put(name, new Entity(name, location,
886917
name.startsWith("sensor.") ? EntityDisplayType.LABEL : EntityDisplayType.ICON,
887-
isHomeAssistantEntityActionable(piece.getName()) ? EntityTapAction.TOGGLE : EntityTapAction.MORE_INFO,
918+
isHomeAssistantEntityActionable(piece.getName()) ? EntityAction.TOGGLE : EntityAction.MORE_INFO,
888919
piece.getDescription()));
889920
}
890921
}

src/com/shmuelzon/HomeAssistantFloorPlan/EntityOptionsPanel.java

+62-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ private enum ActionType {CLOSE, RESET_TO_DEFAULTS}
3636
private JLabel displayTypeLabel;
3737
private JComboBox<Controller.EntityDisplayType> displayTypeComboBox;
3838
private JLabel tapActionLabel;
39-
private JComboBox<Controller.EntityTapAction> tapActionComboBox;
39+
private JComboBox<Controller.EntityAction> tapActionComboBox;
40+
private JLabel doubleTapActionLabel;
41+
private JComboBox<Controller.EntityAction> doubleTapActionComboBox;
42+
private JLabel holdActionLabel;
43+
private JComboBox<Controller.EntityAction> holdActionComboBox;
4044
private JLabel alwaysOnLabel;
4145
private JCheckBox alwaysOnCheckbox;
4246
private JLabel isRgbLabel;
@@ -95,18 +99,52 @@ public void actionPerformed(ActionEvent ev) {
9599

96100
tapActionLabel = new JLabel();
97101
tapActionLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.tapActionLabel.text"));
98-
tapActionComboBox = new JComboBox<Controller.EntityTapAction>(Controller.EntityTapAction.values());
102+
tapActionComboBox = new JComboBox<Controller.EntityAction>(Controller.EntityAction.values());
99103
tapActionComboBox.setSelectedItem(controller.getEntityTapAction(entityName));
100104
tapActionComboBox.setRenderer(new DefaultListCellRenderer() {
101105
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
102106
Component rendererComponent = super.getListCellRendererComponent(jList, o, i, b, b1);
103-
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.tapActionComboBox.%s.text", ((Controller.EntityTapAction)o).name())));
107+
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.actionComboBox.%s.text", ((Controller.EntityAction)o).name())));
104108
return rendererComponent;
105109
}
106110
});
107111
tapActionComboBox.addActionListener(new ActionListener() {
108112
public void actionPerformed(ActionEvent ev) {
109-
controller.setEntityTapAction(entityName, (Controller.EntityTapAction)tapActionComboBox.getSelectedItem());
113+
controller.setEntityTapAction(entityName, (Controller.EntityAction)tapActionComboBox.getSelectedItem());
114+
}
115+
});
116+
117+
doubleTapActionLabel = new JLabel();
118+
doubleTapActionLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.doubleTapActionLabel.text"));
119+
doubleTapActionComboBox = new JComboBox<Controller.EntityAction>(Controller.EntityAction.values());
120+
doubleTapActionComboBox.setSelectedItem(controller.getEntityDoubleTapAction(entityName));
121+
doubleTapActionComboBox.setRenderer(new DefaultListCellRenderer() {
122+
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
123+
Component rendererComponent = super.getListCellRendererComponent(jList, o, i, b, b1);
124+
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.actionComboBox.%s.text", ((Controller.EntityAction)o).name())));
125+
return rendererComponent;
126+
}
127+
});
128+
doubleTapActionComboBox.addActionListener(new ActionListener() {
129+
public void actionPerformed(ActionEvent ev) {
130+
controller.setEntityDoubleTapAction(entityName, (Controller.EntityAction)doubleTapActionComboBox.getSelectedItem());
131+
}
132+
});
133+
134+
holdActionLabel = new JLabel();
135+
holdActionLabel.setText(resource.getString("HomeAssistantFloorPlan.Panel.holdActionLabel.text"));
136+
holdActionComboBox = new JComboBox<Controller.EntityAction>(Controller.EntityAction.values());
137+
holdActionComboBox.setSelectedItem(controller.getEntityHoldAction(entityName));
138+
holdActionComboBox.setRenderer(new DefaultListCellRenderer() {
139+
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
140+
Component rendererComponent = super.getListCellRendererComponent(jList, o, i, b, b1);
141+
setText(resource.getString(String.format("HomeAssistantFloorPlan.Panel.actionComboBox.%s.text", ((Controller.EntityAction)o).name())));
142+
return rendererComponent;
143+
}
144+
});
145+
holdActionComboBox.addActionListener(new ActionListener() {
146+
public void actionPerformed(ActionEvent ev) {
147+
controller.setEntityHoldAction(entityName, (Controller.EntityAction)holdActionComboBox.getSelectedItem());
110148
}
111149
});
112150

@@ -163,6 +201,26 @@ private void layoutComponents(boolean isLight) {
163201
GridBagConstraints.HORIZONTAL, insets, 0, 0));
164202
currentGridYIndex++;
165203

204+
/* Double tap action */
205+
add(doubleTapActionLabel, new GridBagConstraints(
206+
0, currentGridYIndex, 1, 1, 0, 0, GridBagConstraints.CENTER,
207+
GridBagConstraints.HORIZONTAL, insets, 0, 0));
208+
doubleTapActionLabel.setHorizontalAlignment(labelAlignment);
209+
add(doubleTapActionComboBox, new GridBagConstraints(
210+
1, currentGridYIndex, 1, 1, 0, 0, GridBagConstraints.LINE_START,
211+
GridBagConstraints.HORIZONTAL, insets, 0, 0));
212+
currentGridYIndex++;
213+
214+
/* Hold action */
215+
add(holdActionLabel, new GridBagConstraints(
216+
0, currentGridYIndex, 1, 1, 0, 0, GridBagConstraints.CENTER,
217+
GridBagConstraints.HORIZONTAL, insets, 0, 0));
218+
holdActionLabel.setHorizontalAlignment(labelAlignment);
219+
add(holdActionComboBox, new GridBagConstraints(
220+
1, currentGridYIndex, 1, 1, 0, 0, GridBagConstraints.LINE_START,
221+
GridBagConstraints.HORIZONTAL, insets, 0, 0));
222+
currentGridYIndex++;
223+
166224
if (!isLight)
167225
return;
168226

0 commit comments

Comments
 (0)