/** * Copyright (c) 2010-2016 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package org.openhab.binding.souliss.internal.network.typicals; import java.net.DatagramSocket; import org.openhab.binding.souliss.internal.network.udp.SoulissCommGate; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.types.State; /** * Typical T11 SWITCH * * @author Tonino Fazio * @since 1.7.0 */ public class SoulissT11 extends SoulissGenericTypical { /** * Typical T11 * * @param _datagramsocket * @param sSoulissNodeIPAddress * @param sSoulissNodeIPAddressOnLAN * @param iIDNodo * @param iSlot * @param sOHType */ // Parameters sSoulissNode, iSlot, Type and State are stored in the class public SoulissT11(DatagramSocket _datagramsocket, String sSoulissNodeIPAddressOnLAN, int iIDNodo, int iSlot, String sOHType) { super(); this.setSlot(iSlot); this.setSoulissNodeID(iIDNodo); this.setType(Constants.Souliss_T11); // Note is the name of OH Type this.setNote(sOHType); } /** * Send a command as hexadecimal, e.g.: Souliss_T1n_OnCmd = 0x02; short * Souliss_T1n_OffCmd = 0x04; * * @param command */ public void commandSEND(short command) { SoulissCommGate.sendFORCEFrame(SoulissNetworkParameter.datagramsocket, SoulissNetworkParameter.IPAddressOnLAN, this.getSoulissNodeID(), this.getSlot(), command); } @Override /** * Returns a type used by openHAB to show the actual state of the souliss' typical * * @return org.openhab.core.types.State */ public State getOHState() { String sOHState = StateTraslator.statesSoulissToOH(this.getNote(), this.getType(), (short) this.getState()); if (sOHState != null) { if (this.getNote().equals("ContactItem")) { return OpenClosedType.valueOf(sOHState); } else { return OnOffType.valueOf(sOHState); } } return null; } }