Class HAssKClient
-
- All Implemented Interfaces:
public class HAssKClientA 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 interfaceHAssKClient.EntityBasic "thing".
public final classHAssKClient.LightA light-type entity.
This may be a single light or a group, acting as a single item.
public final classHAssKClient.SceneA pre-determined group of entities at certain states.
public final classHAssKClient.SwitchA switch-type entity.
public final classHAssKClient.SensorA sensor entity. NOTE Sensors are "read-only" and will not generally respond to commands.
public final classHAssKClient.SelectSelect a thing - e.g. a menu item.
TODO get select items
public classHAssKClient.MediaPlayerpublic final classHAssKClient.SpotifyPlayerA 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 StringgetServerUri()the location for the API on HA final StringcallService(String entityId, String serviceType, String serviceCommand, Map<String, Object> extraData)Set up generic service call that uses the entity ID as the payload. final EntityStategetState(String entityId)Request the state of a thing. final HttpRequest.BuilderstartRequest(URI uri)Set up the basic request, including auth. final StringsendIt(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 EntityStatestate(HAssKClient.Entity $self)Retrieves the state of the entity. final HAssKClient.Lightlight(String name)Create an entity in the "light" domain (do not prefix with "light. final HAssKClient.Lightgroup(String name)Create a group in the "light" domain (do not prefix with "light. final HAssKClient.Scenescene(String name)Create an entity in the "scene" domain (do not prefix with "scene. final HAssKClient.Switchswitch(String name)Create an entity in the "switch" domain (do not prefix with "switch. final HAssKClient.MediaPlayermedia(String name)Create an entity in the "media_player" domain ( do not prefix with "media_player. final HAssKClient.Sensorsensor(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- Returns:
a Light
-
group
final HAssKClient.Light group(String name)
Create a group in the "light" domain (do not prefix with "light.")
- Parameters:
name- the name- Returns:
a Light that has
isGroup == true
-
scene
final HAssKClient.Scene scene(String name)
Create an entity in the "scene" domain (do not prefix with "scene.")
- Parameters:
name- the name- Returns:
a Scene
-
switch
final HAssKClient.Switch switch(String name)
Create an entity in the "switch" domain (do not prefix with "switch.")
- Parameters:
name- the name- Returns:
a Switch
-
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- Returns:
a Sensor
-
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)
-
-
-
-