Class HAssKClient
-
- All Implemented Interfaces:
public class HAssKClient
A very simple HomeAssistant REST API client with minimal functionality.
All requests are multithreaded by the underlying HTTP client. All calls must be invoked within the "context" of a client instance for an
entityId
. See the docs for the actions on how to invoke them.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
HAssKClient.Entity
Basic "thing".
public final class
HAssKClient.Light
A light-type entity.
This may be a single light or a group, acting as a single item.
public final class
HAssKClient.Scene
A pre-determined group of entities at certain states.
public final class
HAssKClient.Switch
A switch-type entity.
public final class
HAssKClient.Sensor
A sensor entity. NOTE Sensors are "read-only" and will not generally respond to commands.
public class
HAssKClient.MediaPlayer
public final class
HAssKClient.SpotifyPlayer
A Spotify player has an additional "who's playing" attribute.
-
Constructor Summary
Constructors Constructor Description HAssKClient(String token, String haServer, Integer haPort)
-
Method Summary
Modifier and Type Method Description final String
getServerUri()
the location for the API on HA final String
callService(String entityId, String serviceType, String serviceCommand, Map<String, Object> extraData)
Set up generic service call that uses the entity ID as the payload. final EntityState
getState(String entityId)
Request the state of a thing. final HttpRequest.Builder
startRequest(URI uri)
Set up the basic request, including auth. final String
sendIt(HttpRequest request, String entity, String command)
Off we go... final List<EntityState>
turn(HAssKClient.Entity $self, Boolean on)
Generic turn on/off with(haClient) { light("foo") turn on group("bar") turn off }
final List<EntityState>
set(HAssKClient.Light $self, Integer level)
Set a light level for a light/group. final EntityState
state(HAssKClient.Entity $self)
Retrieves the state of the entity. final HAssKClient.Light
light(String name)
Create an entity in the "light" domain (do not prefix with "light. final HAssKClient.Light
group(String name)
Create a group in the "light" domain (do not prefix with "light. final HAssKClient.Scene
scene(String name)
Create an entity in the "scene" domain (do not prefix with "scene. final HAssKClient.Switch
switch(String name)
Create an entity in the "switch" domain (do not prefix with "switch. final HAssKClient.MediaPlayer
media(String name)
Create an entity in the "media_player" domain ( do not prefix with "media_player. final HAssKClient.Sensor
sensor(String name)
Create an entity in the "sensor" domain (do not prefix with "sensor. final List<EntityState>
states(String domain)
Uses the state JSON API to get a list of entities and their states. final List<EntityState>
pause(HAssKClient.MediaPlayer $self)
final List<EntityState>
play(HAssKClient.MediaPlayer $self)
final List<EntityState>
play(HAssKClient.SpotifyPlayer $self, String player)
final List<EntityState>
stop(HAssKClient.MediaPlayer $self)
final List<EntityState>
next(HAssKClient.MediaPlayer $self)
final List<EntityState>
previous(HAssKClient.MediaPlayer $self)
final List<EntityState>
volumeUp(HAssKClient.MediaPlayer $self)
final List<EntityState>
volumeDown(HAssKClient.MediaPlayer $self)
final List<EntityState>
unaryPlus(HAssKClient.MediaPlayer $self)
final List<EntityState>
unaryMinus(HAssKClient.MediaPlayer $self)
-
-
Method Detail
-
getServerUri
final String getServerUri()
the location for the API on HA
-
callService
final String callService(String entityId, String serviceType, String serviceCommand, Map<String, Object> extraData)
Set up generic service call that uses the entity ID as the payload.
- Parameters:
entityId
- the idserviceType
- which serviceserviceCommand
- the command
-
getState
final EntityState getState(String entityId)
Request the state of a thing.
- Parameters:
entityId
- the id
-
startRequest
final HttpRequest.Builder startRequest(URI uri)
Set up the basic request, including auth.
-
sendIt
final String sendIt(HttpRequest request, String entity, String command)
Off we go... (call startRequest to kick things off)
-
turn
final List<EntityState> turn(HAssKClient.Entity $self, Boolean on)
Generic turn on/off
with(haClient) { light("foo") turn on group("bar") turn off }
-
set
final List<EntityState> set(HAssKClient.Light $self, Integer level)
Set a light level for a light/group.
- Parameters:
level
- 0-100with(haClient) { light("foo") set 50 group("bar") set 0 }
-
state
final EntityState state(HAssKClient.Entity $self)
Retrieves the state of the entity.
-
light
final HAssKClient.Light light(String name)
Create an entity in the "light" domain (do not prefix with "light.")
- Parameters:
name
- the name
-
group
final HAssKClient.Light group(String name)
Create a group in the "light" domain (do not prefix with "light.")
- Parameters:
name
- the name
-
scene
final HAssKClient.Scene scene(String name)
Create an entity in the "scene" domain (do not prefix with "scene.")
- Parameters:
name
- the name
-
switch
final HAssKClient.Switch switch(String name)
Create an entity in the "switch" domain (do not prefix with "switch.")
- Parameters:
name
- the name
-
media
final HAssKClient.MediaPlayer media(String name)
Create an entity in the "media_player" domain ( do not prefix with "media_player.")
Specialized players are also initialized here (e.g. Spotify)
-
sensor
final HAssKClient.Sensor sensor(String name)
Create an entity in the "sensor" domain (do not prefix with "sensor.")
- Parameters:
name
- the name
-
states
final List<EntityState> states(String domain)
Uses the state JSON API to get a list of entities and their states. It is filtered by the optional domain.
-
pause
final List<EntityState> pause(HAssKClient.MediaPlayer $self)
-
play
final List<EntityState> play(HAssKClient.MediaPlayer $self)
-
play
final List<EntityState> play(HAssKClient.SpotifyPlayer $self, String player)
-
stop
final List<EntityState> stop(HAssKClient.MediaPlayer $self)
-
next
final List<EntityState> next(HAssKClient.MediaPlayer $self)
-
previous
final List<EntityState> previous(HAssKClient.MediaPlayer $self)
-
volumeUp
final List<EntityState> volumeUp(HAssKClient.MediaPlayer $self)
-
volumeDown
final List<EntityState> volumeDown(HAssKClient.MediaPlayer $self)
-
unaryPlus
final List<EntityState> unaryPlus(HAssKClient.MediaPlayer $self)
-
unaryMinus
final List<EntityState> unaryMinus(HAssKClient.MediaPlayer $self)
-
-
-
-