forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added boilerplate for all other supported devices
* added channels and commands for the Bot * cleanup / generalisation of api proxy and response
- Loading branch information
Showing
28 changed files
with
1,222 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ding.switchbot/src/main/java/org/openhab/binding/switchbot/internal/config/BotConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openhab.binding.switchbot.internal.config; | ||
|
||
public class BotConfig { | ||
private int refreshInterval; | ||
private String deviceId; | ||
|
||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(String deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
public void setRefreshInterval(int refreshInterval) { | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BotConfig [refreshInterval=" + refreshInterval + ", deviceId=" + deviceId + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...itchbot/src/main/java/org/openhab/binding/switchbot/internal/config/HumidifierConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openhab.binding.switchbot.internal.config; | ||
|
||
public class HumidifierConfig { | ||
private String deviceId; | ||
private int refreshInterval; | ||
|
||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(String deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
public void setRefreshInterval(int refreshInterval) { | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HumidifierConfig [deviceId=" + deviceId + ", refreshInterval=" + refreshInterval + "]"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ng.switchbot/src/main/java/org/openhab/binding/switchbot/internal/config/MeterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openhab.binding.switchbot.internal.config; | ||
|
||
public class MeterConfig { | ||
private String deviceId; | ||
private int refreshInterval; | ||
|
||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(String deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
public void setRefreshInterval(int refreshInterval) { | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MeterConfig [deviceId=" + deviceId + ", refreshInterval=" + refreshInterval + "]"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ing.switchbot/src/main/java/org/openhab/binding/switchbot/internal/config/PlugConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openhab.binding.switchbot.internal.config; | ||
|
||
public class PlugConfig { | ||
private String deviceId; | ||
private int refreshInterval; | ||
|
||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(String deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
public void setRefreshInterval(int refreshInterval) { | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MeterConfig [deviceId=" + deviceId + ", refreshInterval=" + refreshInterval + "]"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...switchbot/src/main/java/org/openhab/binding/switchbot/internal/config/SmartfanConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.openhab.binding.switchbot.internal.config; | ||
|
||
public class SmartfanConfig { | ||
private String deviceId; | ||
private int refreshInterval; | ||
|
||
public String getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(String deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
public void setRefreshInterval(int refreshInterval) { | ||
this.refreshInterval = refreshInterval; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MeterConfig [deviceId=" + deviceId + ", refreshInterval=" + refreshInterval + "]"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...g.switchbot/src/main/java/org/openhab/binding/switchbot/internal/discovery/BotDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.openhab.binding.switchbot.internal.discovery; | ||
|
||
/** | ||
* Represents a discovered Bot device. | ||
* | ||
* @author Arjan Lamers - Initial contribution | ||
*/ | ||
public class BotDevice extends SwitchbotDevice { | ||
|
||
public BotDevice(String name, String deviceId) { | ||
super(name, deviceId, DeviceType.BOT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ng.switchbot/src/main/java/org/openhab/binding/switchbot/internal/handler/BotHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.switchbot.internal.handler; | ||
|
||
import static org.openhab.binding.switchbot.internal.SwitchbotBindingConstants.CHANNEL_POWER; | ||
|
||
import org.openhab.binding.switchbot.internal.config.BotConfig; | ||
import org.openhab.core.library.types.OnOffType; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingStatus; | ||
import org.openhab.core.thing.ThingStatusDetail; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link BotHandler} is responsible for handling commands, which are | ||
* sent to one of the channels. It maps the OpenHAB world to the Switchbot world. | ||
* | ||
* @author Arjan Lamers - Initial contribution | ||
*/ | ||
public class BotHandler extends SwitchbotHandler { | ||
|
||
private Logger logger = LoggerFactory.getLogger(BotHandler.class); | ||
|
||
public BotHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
updateStatus(ThingStatus.UNKNOWN); | ||
logger.debug("Will boot up Switchbot Bot binding"); | ||
|
||
BotConfig config = getThing().getConfiguration().as(BotConfig.class); | ||
|
||
logger.debug("Bot Config: {}", config); | ||
|
||
refreshTime = config.getRefreshInterval(); | ||
if (refreshTime < 30) { | ||
logger.warn( | ||
"Refresh time [{}] is not valid. Refresh time must be at least 30 seconds. Setting to minimum of 30 sec", | ||
refreshTime); | ||
config.setRefreshInterval(30); | ||
} | ||
|
||
apiProxy = new SwitchbotApiProxy(config.getDeviceId(), authorizationOpenToken); | ||
startAutomaticRefresh(); | ||
} | ||
|
||
@Override | ||
protected void updateState(SwitchbotApiStatusModel state) { | ||
if (state != null) { | ||
updateStatus(ThingStatus.ONLINE); | ||
publishChannels(state); | ||
} else { | ||
logger.warn("Bot {} not cloud-enabled, check app settings", apiProxy.getDeviceId()); | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, | ||
"Bot not cloud-enabled, check app settings"); | ||
} | ||
} | ||
|
||
private void publishChannels(SwitchbotApiStatusModel state) { | ||
if (state == null) { | ||
updateState(CHANNEL_POWER, OnOffType.OFF); | ||
return; | ||
} | ||
|
||
boolean power = state.getBody().getPower() == null ? false : state.getBody().getPower().equalsIgnoreCase("on"); | ||
updateState(CHANNEL_POWER, power ? OnOffType.ON : OnOffType.OFF); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.