Skip to content

Commit

Permalink
Work on lightmanager models
Browse files Browse the repository at this point in the history
  • Loading branch information
sknull committed Mar 29, 2024
1 parent d63f5cc commit 60eba7d
Show file tree
Hide file tree
Showing 18 changed files with 31,194 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty


class ActuatorProperties(
var ntype: Int? = null,
var ntype: NType? = null,
var index: Int? = null,
var system: Int? = null,
@JsonProperty("bemerkung") val comment: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Device(
val mode433: Int? = null,
val mode868: Int? = null,
val nochannelcheck: Boolean? = null,
val nodst: Boolean? = null,
val passphrase: String? = null,
val smallbandwidth: Boolean? = null,
val ssid: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.io.File
import java.io.InputStream
import java.util.SortedMap

class LmAirProject(
val settings: Settings? = null,
val marker: Map<String, Marker>? = null,
val devices: Map<String, Device>? = null,
val scenes: List<Scene> = listOf(),
val actuators: List<Actuator> = listOf()
) {

@JsonIgnore val scenesMap: Map<Int, Scene> = determineScenes()
@JsonIgnore val actuatorsMap: Map<Int, Actuator> = determineActuators()

private fun determineScenes(
scenes: List<Scene> = this.scenes,
scenesMap: SortedMap<Int, Scene> = sortedMapOf()
): Map<Int, Scene> {
scenes.forEach { s ->
scenesMap[s.properties?.index!!] = s
determineScenes(s.children, scenesMap)
}
return scenesMap
}

private fun determineActuators(
actuators: List<Actuator> = this.actuators,
actuatorsMap: SortedMap<Int, Actuator> = sortedMapOf()
): Map<Int, Actuator> {
actuators.forEach { actuator ->
actuatorsMap[actuator.properties?.index!!] = actuator
scenes.forEach { scene ->
if (scene.containsActuator(actuator.properties.index!!)) {
actuator.usedByScenes.add(scene)
}
}
determineActuators(actuator.children, actuatorsMap)
}
return actuatorsMap
}

companion object {
private val mapper = jacksonObjectMapper()

fun unmarshall(file: File): LmAirProject = mapper.readValue(file, LmAirProject::class.java)

fun unmarshall(ins: InputStream): LmAirProject = mapper.readValue(ins, LmAirProject::class.java)

fun unmarshall(s: String): LmAirProject = mapper.readValue(s, LmAirProject::class.java)

fun unmarshall(bytes: ByteArray): LmAirProject = mapper.readValue(bytes, LmAirProject::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonValue

enum class NType(
@JsonValue val ntype: Int
) {

irlan(1),
scene(9),
marker(8),
pause(10),
child(13)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ class Scene(
}
return false
}

fun getActuatorProperties(actuators: MutableList<SceneProperties> = mutableListOf()): List<SceneProperties> {
properties?.let { p -> if (p.ntype == NType.irlan || p.ntype == NType.pause) {
actuators.add(p)
}
}
children.forEach { c ->
c.getActuatorProperties(actuators)
}
return actuators
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SceneProperties(
val jbcode: Int? = null,
val senderid: Long? = null,
val sendertype: Int? = null,
val ntype: Int? = null,
val ntype: NType? = null,
val index: Int? = null,
@JsonProperty("bemerkung") val comment: String? = null,
@JsonProperty("dauer") val duration: Long? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Settings(
val extname8: String? = null,
val filename: String? = null,
val lastactor: Int? = null,
val learnseqs: Int? = null,
val marksameactor: Boolean? = null,
val master: String? = null,
val nukibridges: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import org.junit.jupiter.api.Test
import java.io.File

class LmAirProjectTest {

@Test
fun testLoadModel() {
val config = LmAirProject.unmarshall(File(ClassLoader.getSystemResource("lmair/lmair-config.json").toURI()))
println(config)
}
}
Loading

0 comments on commit 60eba7d

Please sign in to comment.