Skip to content

Commit

Permalink
Removed special treatment for odd-even color wheels and replaced by c…
Browse files Browse the repository at this point in the history
…onfiguration flags within scenes group.
  • Loading branch information
sknull committed Apr 2, 2024
1 parent 1ffe922 commit 9e89774
Show file tree
Hide file tree
Showing 5 changed files with 2,257 additions and 2,472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class LightmanagerClient(
return actors
}

@Suppress("unchecked_cast")
fun scenes(lmAirProject: LmAirProject? = null): LMScenes {
val document = Jsoup.parse(html()!!)
val setupName = document.select("div[id=mytitle]").first()?.text()
Expand All @@ -108,8 +107,8 @@ class LightmanagerClient(
scenes: LMScenes
) {
if (lmAirProject != null) {
scenes.scenes.forEach {
it.value.forEach { scene ->
scenes.scenes.values.forEach { g ->
g.scenes.forEach { scene ->
lmAirProject.scenesMap[scene.name]?.let { s ->
val actuatorProperties = s.getActuatorProperties()
scene.actions = actuatorProperties.mapNotNull { ap ->
Expand All @@ -128,9 +127,7 @@ class LightmanagerClient(
.split("&")
.filter { p -> p.isNotEmpty() }
.map { p -> p.split("=") }
.filter { p -> p.size == 2 }
.map { p -> Pair(p[0], p[1]) }
.toMap()
.filter { p -> p.size == 2 }.associate { p -> Pair(p[0], p[1]) }
when (u.path) {
"/v1/yamaha/avantage/json/surroundProgram" ->
LMActionLmYamahaAvantage(
Expand Down Expand Up @@ -161,11 +158,7 @@ class LightmanagerClient(
} else {
42
}
if (param != null) {
LMActionLmAir(sceneIndex = param)
} else {
null
}
LMActionLmAir(sceneIndex = param)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.visualdigits.kotlin.klanglicht.hardware.lightmanager.model.lm

class LMSceneGroup(
val name: String = "",
val hasColorWheel: Boolean = false,
val colorWheelOddEven: Boolean = false,
val scenes: MutableList<LMScene> = mutableListOf()
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LMScenes(
val name: String? = null
) {

val scenes: LinkedHashMap<String, MutableList<LMScene>> = LinkedHashMap()
val scenes: LinkedHashMap<String, LMSceneGroup> = LinkedHashMap()

val scenesMap: LinkedHashMap<String, LMScene> = LinkedHashMap()

Expand All @@ -24,13 +24,13 @@ class LMScenes(

fun unmarshall(file: File): LMScenes {
val lmScenes = mapper.readValue(file, LMScenes::class.java)
lmScenes.scenes.values.forEach { l -> l.forEach { s -> lmScenes.scenesMap[s.name!!] = s } }
lmScenes.scenes.values.forEach { g -> g.scenes.forEach { s -> lmScenes.scenesMap[s.name!!] = s } }
return lmScenes
}
}

override fun toString(): String {
return "$name\n" + scenes.toMap().map { e -> " ${e.key}\n ${e.value.joinToString("\n ")}" }.joinToString("\n")
return "$name\n" + scenes.toMap().map { e -> " ${e.key}\n ${e.value.scenes.joinToString("\n ")}" }.joinToString("\n")
}

fun add(scene: LMScene) {
Expand All @@ -52,12 +52,12 @@ class LMScenes(
group
?.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
?.let { name ->
var s = scenes[name]
if (s == null) {
s = mutableListOf()
scenes[name] = s
var g = scenes[name]
if (g == null) {
g = LMSceneGroup(name)
scenes[name] = g
}
s.add(scene)
g.scenes.add(scene)
}
}
}
Expand Down
Loading

0 comments on commit 9e89774

Please sign in to comment.