Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
dokka(project(":homekit"))
dokka(project(":internals"))
dokka(project(":lights"))
dokka(project(":lightlevel"))
dokka(project(":resources"))
dokka(project(":rooms"))
dokka(project(":scenes"))
Expand Down
19 changes: 9 additions & 10 deletions button/api/button.api
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public final class inkapplications/shade/button/structures/Button {
public final fun copy-qm0Ps9A (Ljava/lang/String;Linkapplications/shade/structures/ResourceReference;Linkapplications/shade/button/structures/ButtonMetadata;Linkapplications/shade/button/structures/ButtonState;Ljava/lang/String;)Linkapplications/shade/button/structures/Button;
public static synthetic fun copy-qm0Ps9A$default (Linkapplications/shade/button/structures/Button;Ljava/lang/String;Linkapplications/shade/structures/ResourceReference;Linkapplications/shade/button/structures/ButtonMetadata;Linkapplications/shade/button/structures/ButtonState;Ljava/lang/String;ILjava/lang/Object;)Linkapplications/shade/button/structures/Button;
public fun equals (Ljava/lang/Object;)Z
public final fun getButton ()Linkapplications/shade/button/structures/ButtonState;
public final fun getId-XbiYvy0 ()Ljava/lang/String;
public final fun getMetadata ()Linkapplications/shade/button/structures/ButtonMetadata;
public final fun getOwner ()Linkapplications/shade/structures/ResourceReference;
public final fun getState ()Linkapplications/shade/button/structures/ButtonState;
public final fun getType-1y3a6N0 ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -167,18 +167,17 @@ public final class inkapplications/shade/button/structures/ButtonReport$Companio

public final class inkapplications/shade/button/structures/ButtonState {
public static final field Companion Linkapplications/shade/button/structures/ButtonState$Companion;
public fun <init> ()V
public fun <init> (Linkapplications/shade/button/structures/ButtonReport;Ljava/lang/Integer;Ljava/util/List;)V
public synthetic fun <init> (Linkapplications/shade/button/structures/ButtonReport;Ljava/lang/Integer;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Linkapplications/shade/button/structures/ButtonReport;Lkotlin/time/Duration;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Linkapplications/shade/button/structures/ButtonReport;Lkotlin/time/Duration;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Linkapplications/shade/button/structures/ButtonReport;
public final fun component2 ()Ljava/lang/Integer;
public final fun component2-FghU774 ()Lkotlin/time/Duration;
public final fun component3 ()Ljava/util/List;
public final fun copy (Linkapplications/shade/button/structures/ButtonReport;Ljava/lang/Integer;Ljava/util/List;)Linkapplications/shade/button/structures/ButtonState;
public static synthetic fun copy$default (Linkapplications/shade/button/structures/ButtonState;Linkapplications/shade/button/structures/ButtonReport;Ljava/lang/Integer;Ljava/util/List;ILjava/lang/Object;)Linkapplications/shade/button/structures/ButtonState;
public final fun copy-Kx4hsE0 (Linkapplications/shade/button/structures/ButtonReport;Lkotlin/time/Duration;Ljava/util/List;)Linkapplications/shade/button/structures/ButtonState;
public static synthetic fun copy-Kx4hsE0$default (Linkapplications/shade/button/structures/ButtonState;Linkapplications/shade/button/structures/ButtonReport;Lkotlin/time/Duration;Ljava/util/List;ILjava/lang/Object;)Linkapplications/shade/button/structures/ButtonState;
public fun equals (Ljava/lang/Object;)Z
public final fun getButtonReport ()Linkapplications/shade/button/structures/ButtonReport;
public final fun getEventValues ()Ljava/util/List;
public final fun getRepeatInterval ()Ljava/lang/Integer;
public final fun getEvents ()Ljava/util/List;
public final fun getRepeatInterval-FghU774 ()Lkotlin/time/Duration;
public final fun getReport ()Linkapplications/shade/button/structures/ButtonReport;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package inkapplications.shade.button.structures
import inkapplications.shade.structures.ResourceId
import inkapplications.shade.structures.ResourceReference
import inkapplications.shade.structures.ResourceType
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
Expand Down Expand Up @@ -31,7 +30,7 @@ data class Button(
/**
* Button state and configuration.
*/
val button: ButtonState,
val state: ButtonState,

/**
* Type of the supported resources.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package inkapplications.shade.button.structures

import inkapplications.shade.serialization.MillisecondDurationSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.time.Duration

/**
* State of the button with last event and configuration.
Expand All @@ -12,17 +14,18 @@ data class ButtonState(
* Report of the last button event with timestamp.
*/
@SerialName("button_report")
val buttonReport: ButtonReport? = null,
val report: ButtonReport? = null,

/**
* Duration between repeat events when holding the button in milliseconds.
*/
@SerialName("repeat_interval")
val repeatInterval: Int? = null,
@Serializable(with = MillisecondDurationSerializer::class)
val repeatInterval: Duration? = null,

/**
* List of all button events that this device supports.
*/
@SerialName("event_values")
val eventValues: List<ButtonEvent>? = null,
val events: List<ButtonEvent> = emptyList(),
)
12 changes: 12 additions & 0 deletions cli/src/main/kotlin/inkapplications/shade/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package inkapplications.shade.cli

import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import inkapplications.shade.cli.buttons.*
import inkapplications.shade.cli.connection.AuthorizeCommand
import inkapplications.shade.cli.connection.DiscoverCommand
import inkapplications.shade.cli.devices.*
import inkapplications.shade.cli.events.EventsCommand
import inkapplications.shade.cli.groupedlights.GetGroupedLightCommand
import inkapplications.shade.cli.groupedlights.ListGroupedLightsCommand
import inkapplications.shade.cli.groupedlights.UpdateGroupedLightCommand
import inkapplications.shade.cli.homekit.*
import inkapplications.shade.cli.lightlevels.*
import inkapplications.shade.cli.lights.GetLightCommand
import inkapplications.shade.cli.lights.ListLightsCommand
import inkapplications.shade.cli.lights.UpdateLightCommand
Expand All @@ -31,23 +34,32 @@ class Main: NoOpCliktCommand() {
DeleteZoneCommand,
DiscoverCommand,
EventsCommand,
GetButtonCommand,
GetDeviceCommand,
GetGroupedLightCommand,
GetHomekitCommand,
GetLightCommand,
GetLightLevelCommand,
GetRoomCommand,
GetSceneCommand,
GetZoneCommand,
IdentifyDeviceCommand,
ListButtonsCommand,
ListDevicesCommand,
ListGroupedLightsCommand,
ListHomekitCommand,
ListLightsCommand,
ListLightLevelsCommand,
ListResourcesCommand,
ListRoomsCommand,
ListScenesCommand,
ListZonesCommand,
UpdateButtonCommand,
UpdateDeviceCommand,
UpdateGroupedLightCommand,
UpdateHomekitCommand,
UpdateLightCommand,
UpdateLightLevelCommand,
UpdateRoomCommand,
UpdateSceneCommand,
UpdateZoneCommand,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package inkapplications.shade.cli.buttons

import com.github.ajalt.clikt.core.CliktCommand
import inkapplications.shade.button.structures.Button

fun CliktCommand.echoButton(button: Button) {
echo("${button.id.value}:")
echo(" Owner: ${button.owner}")
echo(" Control ID: ${button.metadata.controlId}")
val report = button.state.report
if (report != null) {
echo(" Last Event: ${report.event}")
echo(" Updated: ${report.updated}")
}
val repeatInterval = button.state.repeatInterval
if (repeatInterval != null) {
echo(" Repeat Interval: ${repeatInterval}ms")
}
echo(" Events:")
button.state.events.forEach { event ->
echo(" - $event")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package inkapplications.shade.cli.buttons

import com.github.ajalt.clikt.parameters.arguments.argument
import inkapplications.shade.cli.AuthorizedShadeCommand
import inkapplications.shade.cli.resourceId

object GetButtonCommand: AuthorizedShadeCommand(
help = "Get data for a specific button"
) {
private val buttonId by argument().resourceId()

override suspend fun runCommand(): Int {
val button = shade.buttons.getButton(buttonId)

logger.debug("Got Button: $button")
echoButton(button)

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package inkapplications.shade.cli.buttons

import inkapplications.shade.cli.AuthorizedShadeCommand

object ListButtonsCommand: AuthorizedShadeCommand(
help = "Get all of the buttons configured on the Hue bridge"
) {
override suspend fun runCommand(): Int {
val buttons = shade.buttons.listButtons()

logger.debug("Got Buttons: $buttons")
buttons.forEach(::echoButton)

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package inkapplications.shade.cli.buttons

import com.github.ajalt.clikt.parameters.arguments.argument
import inkapplications.shade.button.parameters.ButtonUpdateParameters
import inkapplications.shade.cli.AuthorizedShadeCommand
import inkapplications.shade.cli.resourceId
import inkapplications.shade.structures.ResourceType

object UpdateButtonCommand: AuthorizedShadeCommand(
help = "Update an existing button on the Hue bridge"
) {
private val buttonId by argument(
help = "The ID of the button resource to be updated"
).resourceId()

override suspend fun runCommand(): Int {
val response = shade.buttons.updateButton(
id = buttonId,
parameters = ButtonUpdateParameters(
type = ResourceType.Button,
),
)

logger.debug("Got response $response")

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package inkapplications.shade.cli.homekit

import com.github.ajalt.clikt.parameters.arguments.argument
import inkapplications.shade.cli.AuthorizedShadeCommand
import inkapplications.shade.cli.resourceId

object GetHomekitCommand: AuthorizedShadeCommand(
help = "Get data for a specific homekit resource"
) {
private val homekitId by argument().resourceId()

override suspend fun runCommand(): Int {
val homekit = shade.homekit.getHomekit(homekitId)

logger.debug("Got Homekit: $homekit")
echoHomekit(homekit)

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package inkapplications.shade.cli.homekit

import com.github.ajalt.clikt.core.CliktCommand
import inkapplications.shade.homekit.structures.Homekit

fun CliktCommand.echoHomekit(homekit: Homekit) {
echo("${homekit.id.value}:")
echo(" Type: ${homekit.type}")
echo(" Status: ${homekit.status}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package inkapplications.shade.cli.homekit

import inkapplications.shade.cli.AuthorizedShadeCommand

object ListHomekitCommand: AuthorizedShadeCommand(
help = "Get all of the homekit resources configured on the Hue bridge"
) {
override suspend fun runCommand(): Int {
val homekitResources = shade.homekit.listHomekit()

logger.debug("Got Homekit: $homekitResources")
homekitResources.forEach(::echoHomekit)

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package inkapplications.shade.cli.homekit

import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.enum
import inkapplications.shade.cli.AuthorizedShadeCommand
import inkapplications.shade.cli.resourceId
import inkapplications.shade.homekit.parameters.HomekitUpdateParameters
import inkapplications.shade.homekit.structures.HomekitAction

object UpdateHomekitCommand: AuthorizedShadeCommand(
help = "Invoke an action on a homekit resource"
) {
private val homekitId by argument(
help = "The ID of the homekit resource to be updated"
).resourceId()

private val action by option(
help = "Invoke an action on the homekit resource"
).enum<Actions>()

override suspend fun runCommand(): Int {
val action = when(action) {
Actions.Reset -> HomekitAction.Reset
else -> null
}

val response = shade.homekit.updateHomekit(
id = homekitId,
parameters = HomekitUpdateParameters(
action = action,
),
)

logger.debug("Got response $response")

return 0
}

private enum class Actions {
Reset
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package inkapplications.shade.cli.lightlevels

import com.github.ajalt.clikt.parameters.arguments.argument
import inkapplications.shade.cli.AuthorizedShadeCommand
import inkapplications.shade.cli.resourceId

object GetLightLevelCommand: AuthorizedShadeCommand(
help = "Get data for a specific light level sensor"
) {
private val lightLevelId by argument().resourceId()

override suspend fun runCommand(): Int {
val lightLevel = shade.lightLevels.getLightLevel(lightLevelId)

logger.debug("Got Light Level: $lightLevel")
echoLightLevel(lightLevel)

return 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package inkapplications.shade.cli.lightlevels

import com.github.ajalt.clikt.core.CliktCommand
import inkapplications.shade.lightlevel.structures.LightLevel

fun CliktCommand.echoLightLevel(lightLevel: LightLevel) {
echo("${lightLevel.id.value}:")
echo(" Owner: ${lightLevel.owner}")
echo(" Enabled: ${lightLevel.enabled}")

val report = lightLevel.light.lightLevelReport
if (report != null) {
echo(" Level: ${report.lightLevel}")
echo(" Changed: ${report.changed}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package inkapplications.shade.cli.lightlevels

import inkapplications.shade.cli.AuthorizedShadeCommand

object ListLightLevelsCommand: AuthorizedShadeCommand(
help = "Get all of the light level sensors configured on the Hue bridge"
) {
override suspend fun runCommand(): Int {
val lightLevels = shade.lightLevels.listLightLevels()

logger.debug("Got Light Levels: $lightLevels")
lightLevels.forEach(::echoLightLevel)

return 0
}
}
Loading