bigboxer23 / switchbotapi-java

This project provides a java wrapper over the SwitchBot API v1.1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwitchBotAPI-java

This project provides a java wrapper over the SwitchBot API v1.1 (https://github.com/OpenWonderLabs/SwitchBotAPI)

It presently implements the device apis, but may be updated in the future to support scenes and webhooks as well.

Example Usages

  1. Listing devices
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret);
List<Device> devices = instance.getDeviceApi().getDevices();
  1. Getting battery status of a device:
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret);
List<Device> devices = instance.getDeviceApi().getDevices();
Device status = instance.getDeviceApi().getDeviceStatus(devices.get(0).getDeviceId());
System.out.println("" + status.getBattery());
  1. Send command to opening a curtain
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret);
instance.getDeviceApi().getDevices().stream()
        .filter(device -> IDeviceTypes.CURTAIN.equals(device.getDeviceType()))
        .filter(Device::isMaster)
        .findAny()
        .ifPresent(curtain -> {
            try {
                instance.getDeviceApi()
                        .sendDeviceControlCommands(
                                curtain.getDeviceId(), IDeviceCommands.CURTAIN_CLOSE);
            } catch (IOException theE) {
                theE.printStackTrace();
            }
            });
  1. Send command to turn on a plug mini
SwitchBotApi instance = SwitchBotApi.getInstance(token, secret);
instance.getDeviceApi().getDevices().stream()
        .filter(device -> IDeviceTypes.PLUG_MINI.equals(device.getDeviceType()))
        .findAny()
        .ifPresent(plug -> {
            try {
                instance.getDeviceApi()
                        .sendDeviceControlCommands(
                                plug.getDeviceId(), IDeviceCommands.PLUG_MINI_ON);
            } catch (IOException theE) {
                theE.printStackTrace();
            }
            });

About

This project provides a java wrapper over the SwitchBot API v1.1

License:Apache License 2.0


Languages

Language:Java 100.0%