-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tradfri][WIP] Adds basic support for IKEA smart blinds FYRTUR and KADRILJ #6167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/** | ||
* Copyright (c) 2010-2019 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.tradfri.internal.handler; | ||
|
||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.library.types.OnOffType; | ||
import org.eclipse.smarthome.core.library.types.PercentType; | ||
import org.eclipse.smarthome.core.library.types.StopMoveType; | ||
import org.eclipse.smarthome.core.library.types.UpDownType; | ||
import org.eclipse.smarthome.core.library.types.DecimalType; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.thing.ThingStatus; | ||
import org.eclipse.smarthome.core.types.Command; | ||
import org.eclipse.smarthome.core.types.RefreshType; | ||
import org.openhab.binding.tradfri.internal.model.TradfriBlindData; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.JsonElement; | ||
|
||
/** | ||
* The {@link TradfriBlindHandler} is responsible for handling commands for individual blinds. | ||
* | ||
* @author Manuel Raffel - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class TradfriBlindHandler extends TradfriThingHandler { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(TradfriBlindHandler.class); | ||
|
||
// keeps track of the current state for handling of stop/move | ||
private @Nullable TradfriBlindData state; | ||
|
||
public TradfriBlindHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
public void onUpdate(JsonElement data) { | ||
if (active && !(data.isJsonNull())) { | ||
TradfriBlindData state = new TradfriBlindData(data); | ||
updateStatus(state.getReachabilityStatus() ? ThingStatus.ONLINE : ThingStatus.OFFLINE); | ||
|
||
PercentType position = state.getPosition(); | ||
if (position != null) { | ||
updateState(CHANNEL_POSITION, position); | ||
} | ||
|
||
DecimalType batteryLevel = state.getBatteryLevel(); | ||
if (batteryLevel != null) { | ||
updateState(CHANNEL_BATTERY_LEVEL, batteryLevel); | ||
} | ||
|
||
OnOffType batteryLow = state.getBatteryLow(); | ||
if (batteryLow != null) { | ||
updateState(CHANNEL_BATTERY_LOW, batteryLow); | ||
} | ||
|
||
updateDeviceProperties(state); | ||
|
||
this.state = state; | ||
|
||
logger.debug( | ||
"Updating thing for blindId {} to state {position: {}, firmwareVersion: {}, modelId: {}, vendor: {}}", | ||
state.getDeviceId(), position, state.getFirmwareVersion(), state.getModelId(), | ||
state.getVendor()); | ||
} | ||
} | ||
|
||
private void setPosition(PercentType percent) { | ||
TradfriBlindData data = new TradfriBlindData(); | ||
data.setPosition(percent); | ||
set(data.getJsonString()); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
if (active) { | ||
if (command instanceof RefreshType) { | ||
logger.debug("Refreshing channel {}", channelUID); | ||
coapClient.asyncGet(this); | ||
return; | ||
} | ||
|
||
switch (channelUID.getId()) { | ||
case CHANNEL_POSITION: | ||
handlePositionCommand(command); | ||
break; | ||
default: | ||
logger.error("Unknown channel UID {}", channelUID); | ||
} | ||
} | ||
} | ||
|
||
private void handlePositionCommand(Command command) { | ||
if (command instanceof PercentType) { | ||
setPosition((PercentType) command); | ||
} else if (command instanceof StopMoveType) { | ||
final TradfriBlindData state = this.state; | ||
if (state != null && state.getPosition() != null) { | ||
if(StopMoveType.STOP.equals(command)) { | ||
// setPosition(state.getPosition()); | ||
} else { | ||
// (what) TODO (?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good question. I am not sure if we are able to interrupt an previous command sent to TRADFRI gateway. I hence suggest to ignore these commands and log a info / warning / debug for the user. According to the Zigbee Cluster Library is should be possible to send a "stop" on protocol level. Do you know if there is another property beside the position ("5536") available in the TRADFRI COAP interface? |
||
} | ||
} else { | ||
logger.debug("Cannot handle stop/move as current state is not known."); | ||
} | ||
} else if (command instanceof UpDownType) { | ||
if (UpDownType.UP.equals(command)) { | ||
setPosition(PercentType.ZERO); | ||
} else { | ||
setPosition(PercentType.HUNDRED); | ||
} | ||
} else { | ||
logger.debug("Cannot handle command {} for channel {}", command, CHANNEL_POSITION); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2010-2019 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.tradfri.internal.model; | ||
|
||
import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.library.types.PercentType; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonPrimitive; | ||
|
||
/** | ||
* The {@link TradfriBlindData} class is a Java wrapper for the raw JSON data about the blinds state. | ||
* | ||
* @author Manuel Raffel - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class TradfriBlindData extends TradfriWirelessDeviceData { | ||
public TradfriBlindData() { | ||
super(BLIND); | ||
} | ||
|
||
public TradfriBlindData(JsonElement json) { | ||
super(BLIND, json); | ||
} | ||
|
||
public TradfriBlindData setPosition(PercentType position) { | ||
attributes.add(POSITION, new JsonPrimitive(position.intValue())); | ||
return this; | ||
} | ||
|
||
public @Nullable PercentType getPosition() { | ||
PercentType result = null; | ||
|
||
JsonElement position = attributes.get(POSITION); | ||
if (position != null) { | ||
result = new PercentType(position.getAsInt()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public String getJsonString() { | ||
return root.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ thing-type.tradfri.0820.label = Kabelloser Dimmer | |
thing-type.tradfri.0820.description = Der Kabellose Dimmer liefert Daten wie z.B. die Batterieladung. | ||
thing-type.tradfri.0830.label = Fernbedienung | ||
thing-type.tradfri.0830.description = Die Fernbedienung liefert Daten wie z.B. die Batterieladung. | ||
thing-type.tradfri.0999.label = Rollo | ||
thing-type.tradfri.0999.description = Akkubetriebene Rollo mit einstellbarer Position. Liefert au�erdem Daten wie z.B. die Akkuladung. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Batteriebetriebenes Rollo ... |
||
|
||
# thing types config | ||
thing-type.config.tradfri.device.id.label = ID des Ger�tes | ||
|
@@ -39,3 +41,5 @@ channel-type.tradfri.color_temperature.label = Farbtemperatur | |
channel-type.tradfri.color_temperature.description = Erm�glicht die Steuerung der Farbtemperatur. Von Tageslichtwei� (0) bis Warmwei� (100). | ||
channel-type.tradfri.color.label = Farbe | ||
channel-type.tradfri.color.description = Erm�glicht die Steuerung der Farbe. | ||
channel-type.tradfri.position.label = Position | ||
channel-type.tradfri.position.description = Erm�glicht die Steuerung der Position von Offen (0) bis Geschlossen (100). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line