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.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.impl;
15 import org.openhab.binding.digitalstrom.internal.lib.sensorjobexecutor.sensorjob.SensorJob;
16 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.DsAPI;
17 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
18 import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DSID;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link SceneOutputValueReadingJob} is the implementation of a {@link SensorJob}
24 * for reading out a scene configuration of a digitalSTROM-Device and store it into the {@link Device}.
26 * @author Michael Ochel - Initial contribution
27 * @author Matthias Siegele - Initial contribution
29 public class SceneOutputValueReadingJob implements SensorJob {
31 private final Logger logger = LoggerFactory.getLogger(SceneOutputValueReadingJob.class);
33 private final Device device;
34 private short sceneID = 0;
35 private final DSID meterDSID;
36 private long initalisationTime = 0;
39 * Creates a new {@link SceneOutputValueReadingJob} for the given {@link Device} and the given sceneID.
41 * @param device to update
42 * @param sceneID to update
44 public SceneOutputValueReadingJob(Device device, short sceneID) {
46 this.sceneID = sceneID;
47 this.meterDSID = device.getMeterDSID();
48 this.initalisationTime = System.currentTimeMillis();
52 public void execute(DsAPI digitalSTROM, String token) {
53 int[] sceneValue = digitalSTROM.getSceneValue(token, this.device.getDSID(), null, null, this.sceneID);
55 if (sceneValue[0] != -1) {
56 if (device.isBlind()) {
57 device.setSceneOutputValue(this.sceneID, sceneValue[0], sceneValue[1]);
59 device.setSceneOutputValue(this.sceneID, sceneValue[0]);
61 logger.debug("UPDATED sceneOutputValue for dsid: {}, sceneID: {}, value: {}, angle: {}",
62 this.device.getDSID(), sceneID, sceneValue[0], sceneValue[1]);
67 public boolean equals(Object obj) {
68 if (obj instanceof SceneOutputValueReadingJob other) {
69 String str = other.device.getDSID().getValue() + "-" + other.sceneID;
70 return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str);
76 public int hashCode() {
77 return new String(this.device.getDSID().getValue() + this.sceneID).hashCode();
81 public DSID getDSID() {
82 return device.getDSID();
86 public DSID getMeterDSID() {
87 return this.meterDSID;
91 public long getInitalisationTime() {
92 return this.initalisationTime;
96 public void setInitalisationTime(long time) {
97 this.initalisationTime = time;
101 public String toString() {
102 return "SceneOutputValueReadingJob [sceneID: " + sceneID + ", deviceDSID : " + device.getDSID().getValue()
103 + ", meterDSID=" + meterDSID + ", initalisationTime=" + initalisationTime + "]";
107 public String getID() {
108 return getID(device, sceneID);
112 * Returns the id for a {@link SceneOutputValueReadingJob} with the given {@link Device} and sceneID.
114 * @param device to update
115 * @param sceneID to update
118 public static String getID(Device device, Short sceneID) {
119 return DeviceOutputValueSensorJob.class.getSimpleName() + "-" + device.getDSID().getValue() + "-" + sceneID;