Skip to content

Fix icons placement edge-cases #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/com/shmuelzon/HomeAssistantFloorPlan/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum EntityAction {MORE_INFO, NONE, TOGGLE}
private boolean useExistingRenders;

private class Entity {
public String id;
public String name;
public Point2d position;
public EntityDisplayType displayType;
Expand All @@ -101,7 +102,8 @@ private class Entity {
public boolean alwaysOn;
public boolean isRgb;

public Entity(String name, Point2d position, EntityDisplayType defaultDisplayType, EntityAction defaultTapAction, String title) {
public Entity(String id, String name, Point2d position, EntityDisplayType defaultDisplayType, EntityAction defaultTapAction, String title) {
this.id = id;
this.name = name;
this.position = position;
this.displayType = EntityDisplayType.valueOf(settings.get(name + "." + CONTROLLER_ENTITY_DISPLAY_TYPE, defaultDisplayType.name()));
Expand Down Expand Up @@ -885,8 +887,9 @@ private void generateLightEntities(Map<String, Entity> homeAssistantEntities) {
lightsCenter.add(getFurniture2dLocation(light));
lightsCenter.scale(1.0 / lightsList.size());

String name = lightsList.get(0).getName();
homeAssistantEntities.put(name, new Entity(name, lightsCenter, EntityDisplayType.ICON, EntityAction.TOGGLE,
HomeLight light = lightsList.get(0);
String name = light.getName();
homeAssistantEntities.put(name, new Entity(light.getId(), name, lightsCenter, EntityDisplayType.ICON, EntityAction.TOGGLE,
lightsList.get(0).getDescription()));
}
}
Expand All @@ -913,7 +916,7 @@ private void generateSensorEntities(Map<String, Entity> homeAssistantEntities) {
Point2d location = getFurniture2dLocation(piece);
String name = piece.getName();

homeAssistantEntities.put(name, new Entity(name, location,
homeAssistantEntities.put(name, new Entity(piece.getId(), name, location,
name.startsWith("sensor.") ? EntityDisplayType.LABEL : EntityDisplayType.ICON,
isHomeAssistantEntityActionable(piece.getName()) ? EntityAction.TOGGLE : EntityAction.MORE_INFO,
piece.getDescription()));
Expand Down Expand Up @@ -990,6 +993,12 @@ private void separateStateIcons(Set<Entity> entities) {

for (Entity entity : entities) {
Vector2d direction = new Vector2d(entity.position.x - centerPostition.x, entity.position.y - centerPostition.y);

if (direction.length() == 0) {
double[] randomRepeatableDirection = { entity.id.hashCode(), entity.name.hashCode() };
direction.set(randomRepeatableDirection);
}

direction.normalize();
direction.scale(STEP_SIZE);
entity.position.add(direction);
Expand Down
Loading