Skip to content

Commit

Permalink
added latest models & updated status model (no channels for most devi…
Browse files Browse the repository at this point in the history
…ces yet though)
  • Loading branch information
alamers committed Sep 20, 2021
1 parent 2b4f4b6 commit 2e712c7
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class SwitchbotBindingConstants {
public static final ThingTypeUID THING_TYPE_METER = new ThingTypeUID(BINDING_ID, "meter");
public static final ThingTypeUID THING_TYPE_HUMIDIFIER = new ThingTypeUID(BINDING_ID, "humidifier");
public static final ThingTypeUID THING_TYPE_SMARTFAN = new ThingTypeUID(BINDING_ID, "smartfan");
public static final ThingTypeUID THING_TYPE_MOTION_SENSOR = new ThingTypeUID(BINDING_ID, "motionsensor");
public static final ThingTypeUID THING_TYPE_CONTACT_SENSOR = new ThingTypeUID(BINDING_ID, "contactsensor");
public static final ThingTypeUID THING_TYPE_COLOR_BULB = new ThingTypeUID(BINDING_ID, "colorbulb");

public static final String COMMAND = "command";
public static final String COMMAND_TURN_ON = "turnOn";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.switchbot.internal.discovery.SwitchbotAccountDiscoveryService;
import org.openhab.binding.switchbot.internal.handler.BotHandler;
import org.openhab.binding.switchbot.internal.handler.ColorBulbHandler;
import org.openhab.binding.switchbot.internal.handler.ContactSensorHandler;
import org.openhab.binding.switchbot.internal.handler.CurtainHandler;
import org.openhab.binding.switchbot.internal.handler.HubHandler;
import org.openhab.binding.switchbot.internal.handler.HumidifierHandler;
import org.openhab.binding.switchbot.internal.handler.MeterHandler;
import org.openhab.binding.switchbot.internal.handler.MotionSensorHandler;
import org.openhab.binding.switchbot.internal.handler.PlugHandler;
import org.openhab.binding.switchbot.internal.handler.SmartfanHandler;
import org.openhab.binding.switchbot.internal.handler.SwitchbotAccountHandler;
Expand Down Expand Up @@ -57,12 +60,14 @@ public class SwitchbotHandlerFactory extends BaseThingHandlerFactory {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPE_UIDS = Collections
.unmodifiableSet(Stream
.of(BRIDGE_TYPE_SWITCHBOT_ACCOUNT, THING_TYPE_CURTAIN, THING_TYPE_HUB, THING_TYPE_BOT,
THING_TYPE_PLUG, THING_TYPE_METER, THING_TYPE_HUMIDIFIER, THING_TYPE_SMARTFAN)
THING_TYPE_PLUG, THING_TYPE_METER, THING_TYPE_HUMIDIFIER, THING_TYPE_SMARTFAN,
THING_TYPE_CONTACT_SENSOR, THING_TYPE_MOTION_SENSOR, THING_TYPE_COLOR_BULB)
.collect(Collectors.toSet()));

public static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPE_UIDS = Collections
.unmodifiableSet(Stream.of(THING_TYPE_CURTAIN, THING_TYPE_HUB, THING_TYPE_BOT, THING_TYPE_PLUG,
THING_TYPE_METER, THING_TYPE_HUMIDIFIER, THING_TYPE_SMARTFAN).collect(Collectors.toSet()));
THING_TYPE_METER, THING_TYPE_HUMIDIFIER, THING_TYPE_SMARTFAN, THING_TYPE_CONTACT_SENSOR,
THING_TYPE_MOTION_SENSOR, THING_TYPE_COLOR_BULB).collect(Collectors.toSet()));

private Map<ThingUID, ServiceRegistration<DiscoveryService>> discoveryServiceRegistrations = new HashMap<>();

Expand Down Expand Up @@ -90,6 +95,12 @@ protected ThingHandler createHandler(Thing thing) {
return new HumidifierHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_SMARTFAN)) {
return new SmartfanHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_CONTACT_SENSOR)) {
return new ContactSensorHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_MOTION_SENSOR)) {
return new MotionSensorHandler(thing);
} else if (thingTypeUID.equals(THING_TYPE_COLOR_BULB)) {
return new ColorBulbHandler(thing);
} else if (thingTypeUID.equals(BRIDGE_TYPE_SWITCHBOT_ACCOUNT)) {
SwitchbotAccountHandler handler = new SwitchbotAccountHandler((Bridge) thing);
registerAccountDiscoveryService(handler);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.openhab.binding.switchbot.internal.config;

public class ColorBulbConfig {
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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.openhab.binding.switchbot.internal.config;

public class ContactSensorConfig {
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 + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.openhab.binding.switchbot.internal.config;

public class MotionSensorConfig {
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 + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public enum DeviceType {
METER(THING_TYPE_METER),
HUMIDIFIER(THING_TYPE_HUMIDIFIER),
SMARTFAN(THING_TYPE_SMARTFAN),
HUB(THING_TYPE_HUB);
HUB(THING_TYPE_HUB),
CONTACT_SENSOR(THING_TYPE_CONTACT_SENSOR),
MOTION_SENSOR(THING_TYPE_MOTION_SENSOR),
COLOR_BULB(THING_TYPE_COLOR_BULB);

private ThingTypeUID thingType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public void initialize() {
logger.debug("Bot Config: {}", config);

refreshTime = config.getRefreshInterval();
if (refreshTime < 30) {
if (refreshTime < 1) {
logger.warn(
"Refresh time [{}] is not valid. Refresh time must be at least 30 seconds. Setting to minimum of 30 sec",
"Refresh time [{}] is not valid. Refresh time must be at least 1 seconds. Setting to minimum of 30 sec",
refreshTime);
config.setRefreshInterval(30);
config.setRefreshInterval(1);
}

apiProxy = new SwitchbotApiProxy(config.getDeviceId(), authorizationOpenToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 org.openhab.binding.switchbot.internal.config.MeterConfig;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link ColorBulbHandler} 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 ColorBulbHandler extends SwitchbotHandler {

private Logger logger = LoggerFactory.getLogger(ColorBulbHandler.class);

public ColorBulbHandler(Thing thing) {
super(thing);
}

@Override
public void initialize() {
updateStatus(ThingStatus.UNKNOWN);
logger.debug("Will boot up Switchbot Color Bulb binding");

MeterConfig config = getThing().getConfiguration().as(MeterConfig.class);

logger.debug("Color Bulb Config: {}", config);

refreshTime = config.getRefreshInterval();
if (refreshTime < 1) {
logger.warn(
"Refresh time [{}] is not valid. Refresh time must be at least 1 seconds. Setting to minimum of 30 sec",
refreshTime);
config.setRefreshInterval(1);
}

apiProxy = new SwitchbotApiProxy(config.getDeviceId(), authorizationOpenToken);
startAutomaticRefresh();
}

@Override
protected void updateState(SwitchbotApiStatusModel status) {
// TODO Auto-generated method stub
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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 org.openhab.binding.switchbot.internal.config.MeterConfig;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link ContactSensorHandler} 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 ContactSensorHandler extends SwitchbotHandler {

private Logger logger = LoggerFactory.getLogger(ContactSensorHandler.class);

public ContactSensorHandler(Thing thing) {
super(thing);
}

@Override
public void initialize() {
updateStatus(ThingStatus.UNKNOWN);
logger.debug("Will boot up Switchbot Contact Sensor binding");

MeterConfig config = getThing().getConfiguration().as(MeterConfig.class);

logger.debug("Curtain Config: {}", config);

refreshTime = config.getRefreshInterval();
if (refreshTime < 1) {
logger.warn(
"Refresh time [{}] is not valid. Refresh time must be at least 1 second. Setting to minimum of 30 sec",
refreshTime);
config.setRefreshInterval(1);
}

apiProxy = new SwitchbotApiProxy(config.getDeviceId(), authorizationOpenToken);
startAutomaticRefresh();
}

@Override
protected void updateState(SwitchbotApiStatusModel status) {
// TODO Auto-generated method stub
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void initialize() {
logger.debug("Curtain Config: {}", config);

refreshTime = config.getRefreshInterval();
if (refreshTime < 30) {
if (refreshTime < 1) {
logger.warn(
"Refresh time [{}] is not valid. Refresh time must be at least 30 seconds. Setting to minimum of 30 sec",
"Refresh time [{}] is not valid. Refresh time must be at least 1 second. Setting to minimum of 30 sec",
refreshTime);
config.setRefreshInterval(30);
config.setRefreshInterval(1);
}

apiProxy = new SwitchbotApiProxy(getCommunicationDeviceId(config), authorizationOpenToken);
Expand Down
Loading

0 comments on commit 2e712c7

Please sign in to comment.