mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[mqtt.homeassistant] support command_template for fan components (#14233)
* [mqtt.homeassistant] support command_template for fan components * [mqtt.homeassistant] fix field declaration for consistency Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
parent
6d5b8a8cf5
commit
f3ca3255a7
@ -40,6 +40,8 @@ public class Fan extends AbstractComponent<Fan.ChannelConfiguration> {
|
|||||||
|
|
||||||
@SerializedName("state_topic")
|
@SerializedName("state_topic")
|
||||||
protected @Nullable String stateTopic;
|
protected @Nullable String stateTopic;
|
||||||
|
@SerializedName("command_template")
|
||||||
|
protected @Nullable String commandTemplate;
|
||||||
@SerializedName("command_topic")
|
@SerializedName("command_topic")
|
||||||
protected String commandTopic = "";
|
protected String commandTopic = "";
|
||||||
@SerializedName("payload_on")
|
@SerializedName("payload_on")
|
||||||
@ -56,7 +58,7 @@ public class Fan extends AbstractComponent<Fan.ChannelConfiguration> {
|
|||||||
componentConfiguration.getUpdateListener())
|
componentConfiguration.getUpdateListener())
|
||||||
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())
|
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())
|
||||||
.commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
|
.commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
|
||||||
channelConfiguration.getQos())
|
channelConfiguration.getQos(), channelConfiguration.commandTemplate)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,40 @@ public class FanTests extends AbstractComponentTests {
|
|||||||
assertPublished("zigbee2mqtt/fan/set/state", "ON_");
|
assertPublished("zigbee2mqtt/fan/set/state", "ON_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("null")
|
||||||
|
@Test
|
||||||
|
public void testCommandTemplate() throws InterruptedException {
|
||||||
|
var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
|
||||||
|
{
|
||||||
|
"availability": [
|
||||||
|
{
|
||||||
|
"topic": "zigbee2mqtt/bridge/state"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"device": {
|
||||||
|
"identifiers": [
|
||||||
|
"zigbee2mqtt_0x0000000000000000"
|
||||||
|
],
|
||||||
|
"manufacturer": "Fans inc",
|
||||||
|
"model": "Fan",
|
||||||
|
"name": "FanBlower",
|
||||||
|
"sw_version": "Zigbee2MQTT 1.18.2"
|
||||||
|
},
|
||||||
|
"name": "fan",
|
||||||
|
"payload_off": "OFF_",
|
||||||
|
"payload_on": "ON_",
|
||||||
|
"state_topic": "zigbee2mqtt/fan/state",
|
||||||
|
"command_topic": "zigbee2mqtt/fan/set/state",
|
||||||
|
"command_template": "set to {{ value }}"
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
|
||||||
|
assertThat(component.channels.size(), is(1));
|
||||||
|
|
||||||
|
component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
|
||||||
|
assertPublished("zigbee2mqtt/fan/set/state", "set to OFF_");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> getConfigTopics() {
|
protected Set<String> getConfigTopics() {
|
||||||
return Set.of(CONFIG_TOPIC);
|
return Set.of(CONFIG_TOPIC);
|
||||||
|
Loading…
Reference in New Issue
Block a user