-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from ReneeVandervelde/scenes
Add list-scene endpoints
- Loading branch information
Showing
10 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
cli/src/main/kotlin/inkapplications/shade/cli/scenes/ListScenesCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package inkapplications.shade.cli.scenes | ||
|
||
import inkapplications.shade.cli.AuthorizedShadeCommand | ||
|
||
object ListScenesCommand: AuthorizedShadeCommand( | ||
help = "Get all of the scenes configured on the Hue bridge", | ||
) { | ||
override suspend fun runCommand(): Int { | ||
val scenes = shade.scenes.listScenes() | ||
|
||
logger.debug("Got Scenes: $scenes") | ||
scenes.forEach(::echoScene) | ||
|
||
return 0 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
cli/src/main/kotlin/inkapplications/shade/cli/scenes/SceneOutput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package inkapplications.shade.cli.scenes | ||
|
||
import com.github.ajalt.clikt.output.TermUi | ||
import inkapplications.shade.scenes.structures.Scene | ||
import inkapplications.spondee.scalar.toWholePercentage | ||
import inkapplications.spondee.structure.format | ||
|
||
fun echoScene(scene: Scene) { | ||
TermUi.echo("${scene.id}:") | ||
TermUi.echo(" Name: ${scene.metadata.name}") | ||
TermUi.echo(" Group: ${scene.group}") | ||
TermUi.echo(" Speed: ${scene.speed.toWholePercentage().format()}") | ||
TermUi.echo(" Auto Dynamic: ${scene.autoDynamic}") | ||
TermUi.echo(" Actions:") | ||
scene.actions.forEach { action -> | ||
TermUi.echo(" - ${action.target}:") | ||
TermUi.echo(" Power: ${action.action.powerValue}") | ||
TermUi.echo(" Brightness: ${action.action.dimmingValue?.brightness?.toWholePercentage()?.format()}") | ||
TermUi.echo(" Color: ${action.action.colorValue?.color?.toSRGB()?.toHex()}") | ||
TermUi.echo(" Color Temperature: ${action.action.colorTemperatureValue?.temperature?.toKelvin()?.format()}") | ||
TermUi.echo(" Effect: ${action.action.effect}") | ||
TermUi.echo(" Duration: ${action.action.dynamicsDuration}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
scenes/src/commonMain/kotlin/inkapplications/shade/scenes/SceneControls.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package inkapplications.shade.scenes | ||
|
||
import inkapplications.shade.scenes.structures.Scene | ||
|
||
/** | ||
* Actions to get and configure Scenes on the Hue system. | ||
*/ | ||
interface SceneControls { | ||
/** | ||
* Get a list of all scenes configured on the Hue Bridge. | ||
* | ||
* @return a list of all configured scenes on the Hue bridge. | ||
*/ | ||
suspend fun listScenes(): List<Scene> | ||
} |
13 changes: 13 additions & 0 deletions
13
scenes/src/commonMain/kotlin/inkapplications/shade/scenes/ShadeScenes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package inkapplications.shade.scenes | ||
|
||
import inkapplications.shade.internals.HueHttpClient | ||
import inkapplications.shade.internals.getData | ||
import inkapplications.shade.scenes.structures.Scene | ||
|
||
internal class ShadeScenes( | ||
private val hueClient: HueHttpClient, | ||
): SceneControls { | ||
override suspend fun listScenes(): List<Scene> { | ||
return hueClient.getData("resource", "scene") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
scenes/src/commonMain/kotlin/inkapplications/shade/scenes/ShadeScenesModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package inkapplications.shade.scenes | ||
|
||
import inkapplications.shade.internals.InternalsModule | ||
|
||
/** | ||
* Provides Access to scene services. | ||
*/ | ||
class ShadeScenesModule( | ||
internalsModule: InternalsModule, | ||
) { | ||
val scenes: SceneControls = ShadeScenes(internalsModule.hueHttpClient) | ||
} |