Skip to content

Commit

Permalink
Move all device models into the core module. That one needs anyway to…
Browse files Browse the repository at this point in the history
… know about these for hybrid approaches. And over time inconsistencies regarding where stuff lives came in.
  • Loading branch information
sknull committed Dec 29, 2023
1 parent c60ec85 commit 24dcc2b
Show file tree
Hide file tree
Showing 112 changed files with 622 additions and 420 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package de.visualdigits.kotlin.klanglicht.model.preferences

import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterfaceType
package de.visualdigits.kotlin.klanglicht.model.dmx


data class Dmx(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.model.preferences
package de.visualdigits.kotlin.klanglicht.model.dmx

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import de.visualdigits.kotlin.klanglicht.model.fixture.Fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package de.visualdigits.kotlin.klanglicht.rest.hybrid.model
package de.visualdigits.kotlin.klanglicht.model.hybrid

import de.visualdigits.kotlin.klanglicht.model.color.RGBColor
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridDevice
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridDeviceType
import de.visualdigits.kotlin.klanglicht.model.parameter.Fadeable
import de.visualdigits.kotlin.klanglicht.model.parameter.IntParameter
import de.visualdigits.kotlin.klanglicht.model.parameter.ParameterSet
import de.visualdigits.kotlin.klanglicht.model.parameter.Scene
import de.visualdigits.kotlin.klanglicht.model.preferences.Preferences
import de.visualdigits.kotlin.klanglicht.rest.shelly.client.ShellyClient
import de.visualdigits.kotlin.klanglicht.model.shelly.ShellyColor
import de.visualdigits.kotlin.klanglicht.model.shelly.client.ShellyClient
import kotlin.math.min
import kotlin.math.roundToInt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonIgnore

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json


class Device(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json


class Marker(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.json.JsonMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json


class Scene(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.json
package de.visualdigits.kotlin.klanglicht.model.lightmanager.json


class Settings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.xml
package de.visualdigits.kotlin.klanglicht.model.lightmanager.xml

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.xml
package de.visualdigits.kotlin.klanglicht.model.lightmanager.xml

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.xml
package de.visualdigits.kotlin.klanglicht.model.lightmanager.xml

import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.xml
package de.visualdigits.kotlin.klanglicht.model.lightmanager.xml

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.lightmanager.model.xml
package de.visualdigits.kotlin.klanglicht.model.lightmanager.xml

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package de.visualdigits.kotlin.klanglicht.model.preferences

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import de.visualdigits.kotlin.klanglicht.model.dmx.Dmx
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterface
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterfaceDummy
import de.visualdigits.kotlin.klanglicht.model.fixture.Channel
import de.visualdigits.kotlin.klanglicht.model.fixture.Fixtures
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridDevice
import de.visualdigits.kotlin.klanglicht.model.shelly.ShellyDevice
import java.io.File
import java.nio.file.Paths

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.model.preferences
package de.visualdigits.kotlin.klanglicht.model.shelly


class ColorState(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.visualdigits.kotlin.klanglicht.model.shelly

import de.visualdigits.kotlin.klanglicht.model.color.RGBColor
import de.visualdigits.kotlin.klanglicht.model.hybrid.HybridScene
import de.visualdigits.kotlin.klanglicht.model.parameter.Fadeable
import de.visualdigits.kotlin.klanglicht.model.preferences.Preferences
import de.visualdigits.kotlin.klanglicht.model.shelly.client.ShellyClient

class ShellyColor(
val ipAddress: String,
val color: RGBColor,
val gain: Float
) : Fadeable<ShellyColor> {

fun write() {
ShellyClient.setColor(ipAddress, color, gain)
}

fun fade(
other: ShellyColor,
fadeDuration: Long,
preferences: Preferences
) {
val dmxFrameTime = preferences.dmx.frameTime // millis
val step = 1.0 / fadeDuration.toDouble() * dmxFrameTime.toDouble()
var factor = 0.0

while (factor < 1.0) {
fade(other, factor).write()
factor += step
Thread.sleep(dmxFrameTime)
}
other.write()
}

override fun fade(other: Any, factor: Double): ShellyColor {
return if (other is ShellyColor) {
ShellyColor(ipAddress, color.fade(other.color, factor), gain)
} else {
throw IllegalArgumentException("Cannot not fade another type")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.visualdigits.kotlin.klanglicht.model.shelly

import de.visualdigits.kotlin.klanglicht.model.color.RGBColor
import de.visualdigits.kotlin.klanglicht.model.shelly.client.ShellyClient
import de.visualdigits.kotlin.klanglicht.model.shelly.status.Light
import de.visualdigits.kotlin.klanglicht.model.shelly.status.Status


data class ShellyDevice(
val name: String = "",
val model: String = "",
val command: String = "",
val ipAddress: String = "",
val gain: Float = 0.0f
) {

override fun toString(): String {
return "Shelly $name [$ipAddress] $model"
}

fun setPower(
command: String,
turnOn: Boolean,
transitionDuration: Long
): String {
return ShellyClient.setPower(
ipAddress = ipAddress,
command = command,
turnOn = turnOn,
transitionDuration = transitionDuration
)
}

fun setGain(
gain: Int,
transitionDuration: Long
): String {
return ShellyClient.setGain(
ipAddress = ipAddress,
gain = gain,
transitionDuration = transitionDuration
)
}

fun getStatus(): Status {
return ShellyClient.getStatus(ipAddress)
}

fun setColor(
rgbColor: RGBColor,
gain: Float = 1.0f,
transitionDuration: Long = 0,
turnOn: Boolean = true,
): Light {
return ShellyClient.setColor(
ipAddress = ipAddress,
rgbColor = rgbColor,
gain = gain,
transitionDuration = transitionDuration,
turnOn = turnOn
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.client
package de.visualdigits.kotlin.klanglicht.model.shelly.client

import de.visualdigits.kotlin.klanglicht.model.color.RGBColor
import de.visualdigits.kotlin.klanglicht.rest.shelly.model.status.Light
import de.visualdigits.kotlin.klanglicht.rest.shelly.model.status.Status
import de.visualdigits.kotlin.klanglicht.model.shelly.status.Light
import de.visualdigits.kotlin.klanglicht.model.shelly.status.Status
import java.net.URL

object ShellyClient {
Expand Down Expand Up @@ -35,18 +35,19 @@ object ShellyClient {
ipAddress: String,
rgbColor: RGBColor,
gain: Float,
transitionDuration: Long = 0,
transitionDuration: Long = 1, // zero is interpreted as empty which leads to the default of 2000 millis
turnOn: Boolean = true,
): Light {
val json = URL(
"http://$ipAddress/color/0?" +
val url = "http://$ipAddress/color/0?" +
"turn=${if (turnOn) "on" else "off"}&" +
"red=${rgbColor.red}&" +
"green=${rgbColor.green}&" +
"blue=${rgbColor.blue}&" +
"white=0&" +
"gain=${(100 * gain).toInt()}&" +
"transition=" + transitionDuration + "&"
val json = URL(
url
).readText()
return Light.load(json)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.visualdigits.kotlin.klanglicht.model.shelly.status


class ActionStats(
val skipped: Int? = null
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status


class Cloud(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.visualdigits.kotlin.klanglicht.model.shelly.status

class ExternalTemperature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.visualdigits.kotlin.klanglicht.model.shelly.status

class Humidity
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper


class Light(
Expand All @@ -26,15 +28,14 @@ class Light(
@JsonProperty("overpower") val overPower: Boolean? = null
) {
companion object {
val MAPPER: JsonMapper = JsonMapper
.builder()
.disable(SerializationFeature.INDENT_OUTPUT)

private val mapper = jacksonMapperBuilder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build()

fun load(json: String?): Light {
return try {
MAPPER.readValue<Light>(json, Light::class.java)
mapper.readValue(json, Light::class.java)
} catch (e: JsonProcessingException) {
throw IllegalStateException("Could not read JSON string", e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty
import java.time.OffsetDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.visualdigits.kotlin.klanglicht.model.shelly.status


class Mqtt(
val connected: Boolean? = null
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package de.visualdigits.kotlin.klanglicht.model.shelly.status

class Sensor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonProcessingException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status

import com.fasterxml.jackson.annotation.JsonProperty

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.visualdigits.kotlin.klanglicht.rest.shelly.model.status
package de.visualdigits.kotlin.klanglicht.model.shelly.status


class WifiState(
Expand Down
Loading

0 comments on commit 24dcc2b

Please sign in to comment.