2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nanoleaf.internal.model;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
19 import com.google.gson.annotations.SerializedName;
22 * Represents panel position
24 * @author Martin Raepple - Initial contribution
27 public class PositionDatum {
35 private int orientation;
36 @SerializedName("shapeType")
37 private int shapeType;
39 public PositionDatum() {
42 public PositionDatum(int panelId, int posX, int posY, int orientation, int shapeType) {
43 this.panelId = panelId;
46 this.orientation = orientation;
47 this.shapeType = shapeType;
50 public int getPanelId() {
54 public void setPanelId(int panelId) {
55 this.panelId = panelId;
58 public int getPosX() {
59 if (getPanelSize() != 0 && posX % getPanelSize() == 99) { // hack: check the inaccuracy of 1
60 posX = (posX / getPanelSize() + 1) * getPanelSize();
65 public void setPosX(int x) {
69 public int getPosY() {
70 // we need to fix the positions: see
71 // https://forum.nanoleaf.me/forum/aurora-open-api/squares-send-unprecise-layout-positions
72 // unfortunately this cannot be done in the setter as gson does not access setters
74 if (getPanelSize() != 0 && posY % getPanelSize() == 99) { // hack: check the inaccuracy of 1
75 posY = (posY / getPanelSize() + 1) * getPanelSize();
80 public void setPosY(int y) {
84 public int getOrientation() {
88 public void setOrientation(int o) {
92 public int getShapeType() {
96 public void setShapeType(int shapeType) {
97 this.shapeType = shapeType;
100 public Integer getPanelSize() {
101 return (int) ShapeType.valueOf(shapeType).getSideLength();
105 public boolean equals(@Nullable Object o) {
110 if (o == null || getClass() != o.getClass()) {
114 PositionDatum pd = (PositionDatum) o;
115 return (posX == pd.getPosX()) && (posY == pd.getPosY()) && (orientation == pd.getOrientation())
116 && (shapeType == pd.getShapeType()) && (panelId == pd.getPanelId());
120 public int hashCode() {
121 final int prime = 31;
123 result = prime * result + posX;
124 result = prime * result + posY;
125 result = prime * result + orientation;
126 result = prime * result + shapeType;
127 result = prime * result + panelId;