]> git.basschouten.com Git - openhab-addons.git/blob
786d599a770f88949f5344bcd4d56ad915266b03
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.pilight.internal.handler;
14
15 import static org.openhab.binding.pilight.internal.PilightBindingConstants.CHANNEL_STATE;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.pilight.internal.dto.Action;
20 import org.openhab.binding.pilight.internal.dto.Device;
21 import org.openhab.binding.pilight.internal.dto.Status;
22 import org.openhab.binding.pilight.internal.types.PilightContactType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.Command;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * The {@link PilightContactHandler} is responsible for handling a pilight contact.
31  *
32  * @author Stefan Röllin - Initial contribution
33  * @author Niklas Dörfler - Port pilight binding to openHAB 3 + add device discovery
34  */
35 @NonNullByDefault
36 public class PilightContactHandler extends PilightBaseHandler {
37
38     private final Logger logger = LoggerFactory.getLogger(PilightContactHandler.class);
39
40     public PilightContactHandler(Thing thing) {
41         super(thing);
42     }
43
44     @Override
45     protected void updateFromStatus(Status status) {
46         String state = status.getValues().get("state");
47         if (state != null) {
48             updateState(CHANNEL_STATE, PilightContactType.valueOf(state.toUpperCase()).toOpenClosedType());
49         }
50     }
51
52     @Override
53     void updateFromConfigDevice(Device device) {
54     }
55
56     @Override
57     protected @Nullable Action createUpdateCommand(ChannelUID channelUID, Command command) {
58         logger.warn("A contact is a read only device");
59         return null;
60     }
61 }