]> git.basschouten.com Git - openhab-addons.git/blob
58351a2eee2e7b2360623c12a51f76c1a871e82f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.mqtt.homeassistant.internal.component;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.mqtt.generic.values.ImageValue;
18 import org.openhab.binding.mqtt.generic.values.TextValue;
19 import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType;
20 import org.openhab.binding.mqtt.homeassistant.internal.config.dto.AbstractChannelConfiguration;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * A MQTT camera, following the https://www.home-assistant.io/components/camera.mqtt/ specification.
26  *
27  * At the moment this only notifies the user that this feature is not yet supported.
28  *
29  * @author David Graeff - Initial contribution
30  */
31 @NonNullByDefault
32 public class Camera extends AbstractComponent<Camera.ChannelConfiguration> {
33     public static final String CAMERA_CHANNEL_ID = "camera";
34     public static final String JSON_ATTRIBUTES_CHANNEL_ID = "json-attributes";
35
36     /**
37      * Configuration class for MQTT component
38      */
39     static class ChannelConfiguration extends AbstractChannelConfiguration {
40         ChannelConfiguration() {
41             super("MQTT Camera");
42         }
43
44         protected String topic = "";
45
46         @SerializedName("json_attributes_template")
47         protected @Nullable String jsonAttributesTemplate;
48         @SerializedName("json_attributes_topic")
49         protected @Nullable String jsonAttributesTopic;
50     }
51
52     public Camera(ComponentFactory.ComponentConfiguration componentConfiguration, boolean newStyleChannels) {
53         super(componentConfiguration, ChannelConfiguration.class, newStyleChannels);
54
55         ImageValue value = new ImageValue();
56
57         buildChannel(CAMERA_CHANNEL_ID, ComponentChannelType.IMAGE, value, getName(),
58                 componentConfiguration.getUpdateListener()).stateTopic(channelConfiguration.topic).build();
59
60         if (channelConfiguration.jsonAttributesTemplate != null) {
61             buildChannel(JSON_ATTRIBUTES_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(), "JSON Attributes",
62                     componentConfiguration.getUpdateListener())
63                     .stateTopic(channelConfiguration.jsonAttributesTopic, channelConfiguration.jsonAttributesTemplate)
64                     .build();
65         }
66
67         finalizeChannels();
68     }
69 }