2 * Copyright (c) 2010-2024 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.mqtt.homeassistant.internal.component;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mqtt.generic.values.TextValue;
17 import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannel;
18 import org.openhab.binding.mqtt.homeassistant.internal.ComponentChannelType;
19 import org.openhab.core.library.types.HSBType;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.library.types.PercentType;
22 import org.openhab.core.types.Command;
25 * A base class for common elements between JSON schema and template schema lights.
27 * @author Cody Cutrer - Initial contribution
30 abstract class AbstractRawSchemaLight extends Light {
31 protected static final String RAW_CHANNEL_ID = "raw";
33 protected ComponentChannel rawChannel;
35 public AbstractRawSchemaLight(ComponentFactory.ComponentConfiguration builder, boolean newStyleChannels) {
36 super(builder, newStyleChannels);
37 hiddenChannels.add(rawChannel = buildChannel(RAW_CHANNEL_ID, ComponentChannelType.STRING, new TextValue(),
38 "Raw state", this).stateTopic(channelConfiguration.stateTopic)
39 .commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
40 channelConfiguration.getQos())
44 protected boolean handleCommand(Command command) {
46 if (colorValue.getChannelState() instanceof HSBType) {
47 newState = (HSBType) colorValue.getChannelState();
49 newState = HSBType.WHITE;
52 if (command.equals(PercentType.ZERO) || command.equals(OnOffType.OFF)) {
53 newState = HSBType.BLACK;
54 } else if (command.equals(OnOffType.ON)) {
55 if (newState.getBrightness().equals(PercentType.ZERO)) {
56 newState = new HSBType(newState.getHue(), newState.getSaturation(), PercentType.HUNDRED);
58 } else if (command instanceof HSBType hsb) {
60 } else if (command instanceof PercentType brightness) {
61 newState = new HSBType(newState.getHue(), newState.getSaturation(), brightness);
66 publishState(newState);
70 protected abstract void publishState(HSBType state);