2 * Copyright (c) 2010-2022 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 java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import com.google.gson.annotations.SerializedName;
23 * Represents panel position
25 * @author Martin Raepple - Initial contribution
28 public class PositionDatum {
36 private int orientation;
37 @SerializedName("shapeType")
38 private int shapeType;
40 private static Map<Integer, Integer> panelSizes = new HashMap<Integer, Integer>();
42 public PositionDatum() {
43 // initialize constant sidelengths for panels. See https://forum.nanoleaf.me/docs chapter 3.3
44 if (panelSizes.isEmpty()) {
45 panelSizes.put(0, 150); // Triangle
46 panelSizes.put(1, 0); // Rhythm N/A
47 panelSizes.put(2, 100); // Square
48 panelSizes.put(3, 100); // Control Square Master
49 panelSizes.put(4, 100); // Control Square Passive
50 panelSizes.put(7, 67); // Hexagon
51 panelSizes.put(8, 134); // Triangle Shapes
52 panelSizes.put(9, 67); // Mini Triangle Shapes
53 panelSizes.put(12, 0); // Shapes Controller (N/A)
57 public int getPanelId() {
61 public void setPanelId(int panelId) {
62 this.panelId = panelId;
65 public int getPosX() {
66 if (getPanelSize() != 0 && posX % getPanelSize() == 99) { // hack: check the inaccuracy of 1
67 posX = (posX / getPanelSize() + 1) * getPanelSize();
72 public void setPosX(int x) {
76 public int getPosY() {
77 // we need to fix the positions: see
78 // https://forum.nanoleaf.me/forum/aurora-open-api/squares-send-unprecise-layout-positions
79 // unfortunately this cannot be done in the setter as gson does not access setters
81 if (getPanelSize() != 0 && posY % getPanelSize() == 99) { // hack: check the inaccuracy of 1
82 posY = (posY / getPanelSize() + 1) * getPanelSize();
87 public void setPosY(int y) {
91 public int getOrientation() {
95 public void setOrientation(int o) {
99 public int getShapeType() {
103 public void setShapeType(int shapeType) {
104 this.shapeType = shapeType;
107 public Integer getPanelSize() {
108 return panelSizes.getOrDefault(shapeType, 0);