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) {
69 SceneOutputValueReadingJob other = (SceneOutputValueReadingJob) obj;
70 String str = other.device.getDSID().getValue() + "-" + other.sceneID;
71 return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str);
77 public int hashCode() {
78 return new String(this.device.getDSID().getValue() + this.sceneID).hashCode();
82 public DSID getDSID() {
83 return device.getDSID();
87 public DSID getMeterDSID() {
88 return this.meterDSID;
92 public long getInitalisationTime() {
93 return this.initalisationTime;
97 public void setInitalisationTime(long time) {
98 this.initalisationTime = time;
102 public String toString() {
103 return "SceneOutputValueReadingJob [sceneID: " + sceneID + ", deviceDSID : " + device.getDSID().getValue()
104 + ", meterDSID=" + meterDSID + ", initalisationTime=" + initalisationTime + "]";
108 public String getID() {
109 return getID(device, sceneID);
113 * Returns the id for a {@link SceneOutputValueReadingJob} with the given {@link Device} and sceneID.
115 * @param device to update
116 * @param sceneID to update
119 public static String getID(Device device, Short sceneID) {
120 return DeviceOutputValueSensorJob.class.getSimpleName() + "-" + device.getDSID().getValue() + "-" + sceneID;