Skip to content

bigboxer23/switchbotapi-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeQL Build Status codecov

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •  

Languages