From 13d8319064ef4ff0bcdc5e468dc925b9eea95cac Mon Sep 17 00:00:00 2001 From: Stephan Knull Date: Sun, 31 Mar 2024 16:58:38 +0200 Subject: [PATCH] Cleanup --- klanglicht-module-base/pom.xml | 8 + .../shelly/client/ShellyClientTest.kt | 17 +- .../{ => model}/dmx/DmxInterfaceTest.kt | 2 +- .../klanglicht/{ => model}/dmx/SimpleTest.kt | 2 +- .../model/preferences/PreferencesTest.kt | 16 +- .../.klanglicht/preferences/preferences.json | 154 ++++++++++++++++++ .../.klanglicht/preferences/preferences.yml | 99 +++++++++++ .../klanglicht/rest/ResourceController.kt | 7 +- .../controller/HybridStageRestController.kt | 13 +- .../HybridStageService.kt} | 13 +- .../controller/LightmanagerRestController.kt | 8 +- .../controller/LightmanagerWebController.kt | 10 +- .../lightmanager/model/html/LMHtmlScene.kt | 4 +- .../service/LightmanagerService.kt | 8 +- .../shelly/controller/ShellyRestController.kt | 22 +-- .../shelly/controller/ShellyWebController.kt | 11 +- .../rest/shelly/service/ShellyService.kt | 7 +- .../twinkly/controller/XledArrayController.kt | 6 +- .../controller/XledDeviceController.kt | 7 +- .../YamahaReceiverRestController.kt | 22 +-- .../YamahaAvantageReceiverRestController.kt | 24 +-- 21 files changed, 356 insertions(+), 104 deletions(-) rename klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/{ => model}/dmx/DmxInterfaceTest.kt (99%) rename klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/{ => model}/dmx/SimpleTest.kt (98%) create mode 100644 klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.json create mode 100644 klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.yml rename klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/{handler/HybridStageHandler.kt => service/HybridStageService.kt} (94%) diff --git a/klanglicht-module-base/pom.xml b/klanglicht-module-base/pom.xml index b6346ee..deeadf1 100644 --- a/klanglicht-module-base/pom.xml +++ b/klanglicht-module-base/pom.xml @@ -39,5 +39,13 @@ jsoup 1.16.1 + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.16.1 + + diff --git a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/hardware/shelly/client/ShellyClientTest.kt b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/hardware/shelly/client/ShellyClientTest.kt index 920bbb2..987e0a9 100644 --- a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/hardware/shelly/client/ShellyClientTest.kt +++ b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/hardware/shelly/client/ShellyClientTest.kt @@ -7,7 +7,20 @@ import org.junit.jupiter.api.Test class ShellyClientTest { @Test - fun testPower() { - ShellyClient.setPower(ipAddress = "192.168.178.38", command = "relay/0", turnOn = false) + fun testPowerOn() { + ShellyClient.setPower( + ipAddress = "192.168.178.38", + command = "relay/0", + turnOn = true + ) + } + + @Test + fun testPowerOff() { + ShellyClient.setPower( + ipAddress = "192.168.178.38", + command = "relay/0", + turnOn = false + ) } } diff --git a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/DmxInterfaceTest.kt b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/DmxInterfaceTest.kt similarity index 99% rename from klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/DmxInterfaceTest.kt rename to klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/DmxInterfaceTest.kt index 3d7eae4..4e50000 100644 --- a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/DmxInterfaceTest.kt +++ b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/DmxInterfaceTest.kt @@ -1,4 +1,4 @@ -package de.visualdigits.kotlin.klanglicht.dmx +package de.visualdigits.kotlin.klanglicht.model.dmx import de.visualdigits.kotlin.klanglicht.hardware.color.RGBColor import de.visualdigits.kotlin.klanglicht.hardware.dmx.parameter.IntParameter diff --git a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/SimpleTest.kt b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/SimpleTest.kt similarity index 98% rename from klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/SimpleTest.kt rename to klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/SimpleTest.kt index d2c08eb..2b7b0a5 100644 --- a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/dmx/SimpleTest.kt +++ b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/dmx/SimpleTest.kt @@ -1,4 +1,4 @@ -package de.visualdigits.kotlin.klanglicht.dmx +package de.visualdigits.kotlin.klanglicht.model.dmx import de.visualdigits.kotlin.klanglicht.hardware.color.RGBWColor import de.visualdigits.kotlin.klanglicht.hardware.dmx.parameter.IntParameter diff --git a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/preferences/PreferencesTest.kt b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/preferences/PreferencesTest.kt index 297a956..e4bf807 100644 --- a/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/preferences/PreferencesTest.kt +++ b/klanglicht-module-base/src/test/kotlin/de/visualdigits/kotlin/klanglicht/model/preferences/PreferencesTest.kt @@ -1,6 +1,8 @@ package de.visualdigits.kotlin.klanglicht.hardware.preferences +import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder import de.visualdigits.kotlin.klanglicht.hardware.hybrid.HybridScene import org.junit.jupiter.api.Assertions.assertNotNull @@ -13,19 +15,11 @@ class PreferencesTest { fun testReadModel() { val preferences = Preferences.load( klanglichtDirectory = File(ClassLoader.getSystemResource(".klanglicht").toURI()), - preferencesFileName = "preferences_livingroom.json" +// preferencesFileName = "preferences_livingroom.json" ) - assertNotNull(Preferences.preferences) + val mapper = ObjectMapper(YAMLFactory()) - val ids = preferences.getStageIds().joinToString(",") - val currentScene = preferences.initialHybridScene() - val nextScene = HybridScene(ids, "ff0000", "1.0", "true", preferences = preferences) - currentScene.update(nextScene) - val cloned = currentScene.clone() - - val mapper = jacksonMapperBuilder().enable(SerializationFeature.INDENT_OUTPUT).build() - - println() + println(mapper.writeValueAsString(preferences)) } } diff --git a/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.json b/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.json new file mode 100644 index 0000000..70d8d45 --- /dev/null +++ b/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.json @@ -0,0 +1,154 @@ +{ + "name": "wohnzimmer", + "theme": "StarWars", + "fadeDurationDefault": 2000, + + "services": [ + { + "name": "lmair", + "manufacturer": "JB-Media", + "model": "Light-Manager Air", + "url": "http://192.168.178.28" + }, + { + "name": "receiver", + "manufacturer": "Yamaha", + "model": "RX-V6A", + "url": "http://192.168.178.46" + } + ], + + "shelly": [ + { + "name": "Starwars", + "model": "shelly-rgbw", + "ipAddress": "192.168.178.54", + "command": "color/0", + "gain": 0.2 + }, + { + "name": "Rgbw", + "model": "shelly-rgbw", + "ipAddress": "192.168.178.48", + "command": "color/0", + "gain": 0.1 + }, + { + "name": "Bar", + "model": "shelly-rgbw", + "ipAddress": "192.168.178.55", + "command": "color/0", + "gain": 0.1 + }, + { + "name": "Flur", + "model": "shelly-1", + "ipAddress": "192.168.178.38", + "command": "relay/0", + "gain": 0 + }, + { + "name": "Schlafzimmer", + "model": "shelly-1", + "ipAddress": "192.168.178.40", + "command": "relay/0", + "gain": 0 + }, + { + "name": "Wohnzimmer_Esstisch", + "model": "shelly-2.5", + "ipAddress": "192.168.178.37", + "command": "relay/0", + "gain": 0 + }, + { + "name": "Wohnzimmer_Deckenlampe", + "model": "shelly-2.5", + "ipAddress": "192.168.178.37", + "command": "relay/1", + "gain": 0 + }, + { + "name": "Kristall", + "model": "plug-s", + "ipAddress": "192.168.178.51", + "command": "relay/0", + "gain": 0 + }, + { + "name": "Regal", + "model": "shelly-plug-s", + "ipAddress": "192.168.178.39", + "command": "relay/0", + "gain": 0 + } + ], + + "dmx": { + "port": "COM5", + "interfaceType": "Serial", + "frameTime": 40, + "enableRepeater": false, + "devices": [ + { + "manufacturer": "Cameo", + "model": "Flat PAR Can RGB 10 IR", + "mode": "6-Channel Mode", + "baseChannel": 1, + "gain": 1.0 + }, + { + "manufacturer": "Cameo", + "model": "Flat PAR Can RGBW", + "mode": "8-Channel Mode", + "baseChannel": 21, + "gain": 1.0 + }, + { + "manufacturer": "Cameo", + "model": "Flat PAR Can RGB 10 IR", + "mode": "6-Channel Mode", + "baseChannel": 15, + "gain": 1.0 + }, + { + "manufacturer": "Cameo", + "model": "Flat PAR Can RGB 10 IR", + "mode": "6-Channel Mode", + "baseChannel": 29, + "gain": 1.0 + } + ] + }, + + "stage": [ + { + "type": "shelly", + "id": "Starwars" + }, + { + "type": "shelly", + "id": "Rgbw" + }, + { + "type": "dmx", + "id": "15" + }, + { + "type": "dmx", + "id": "29" + }, + { + "type": "dmx", + "id": "21" + }, + { + "type": "dmx", + "id": "1" + }, + { + "type": "shelly", + "id": "Bar" + } + ] +} diff --git a/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.yml b/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.yml new file mode 100644 index 0000000..4f2b161 --- /dev/null +++ b/klanglicht-module-base/src/test/resources/.klanglicht/preferences/preferences.yml @@ -0,0 +1,99 @@ +name: wohnzimmer +theme: StarWars +fadeDurationDefault: 2000 +services: + - name: lmair + manufacturer: JB-Media + model: Light-Manager Air + url: http://192.168.178.28 + - name: receiver + manufacturer: Yamaha + model: RX-V6A + url: http://192.168.178.46 +shelly: + - name: Starwars + model: shelly-rgbw + ipAddress: 192.168.178.54 + command: color/0 + gain: 0.2 + - name: Rgbw + model: shelly-rgbw + ipAddress: 192.168.178.48 + command: color/0 + gain: 0.1 + - name: Bar + model: shelly-rgbw + ipAddress: 192.168.178.55 + command: color/0 + gain: 0.1 + - name: Flur + model: shelly-1 + ipAddress: 192.168.178.38 + command: relay/0 + gain: 0 + - name: Schlafzimmer + model: shelly-1 + ipAddress: 192.168.178.40 + command: relay/0 + gain: 0 + - name: Wohnzimmer_Esstisch + model: shelly-2.5 + ipAddress: 192.168.178.37 + command: relay/0 + gain: 0 + - name: Wohnzimmer_Deckenlampe + model: shelly-2.5 + ipAddress: 192.168.178.37 + command: relay/1 + gain: 0 + - name: Kristall + model: plug-s + ipAddress: 192.168.178.51 + command: relay/0 + gain: 0 + - name: Regal + model: shelly-plug-s + ipAddress: 192.168.178.39 + command: relay/0 + gain: 0 +dmx: + port: COM5 + interfaceType: Serial + frameTime: 40 + enableRepeater: false + devices: + - manufacturer: Cameo + model: Flat PAR Can RGB 10 IR + mode: 6-Channel Mode + baseChannel: 1 + gain: 1 + - manufacturer: Cameo + model: Flat PAR Can RGBW + mode: 8-Channel Mode + baseChannel: 21 + gain: 1 + - manufacturer: Cameo + model: Flat PAR Can RGB 10 IR + mode: 6-Channel Mode + baseChannel: 15 + gain: 1 + - manufacturer: Cameo + model: Flat PAR Can RGB 10 IR + mode: 6-Channel Mode + baseChannel: 29 + gain: 1 +stage: + - type: shelly + id: Starwars + - type: shelly + id: Rgbw + - type: dmx + id: '15' + - type: dmx + id: '29' + - type: dmx + id: '21' + - type: dmx + id: '1' + - type: shelly + id: Bar diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/ResourceController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/ResourceController.kt index b230e18..b2eb723 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/ResourceController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/ResourceController.kt @@ -26,13 +26,12 @@ import java.net.URLEncoder import java.nio.charset.StandardCharsets @Controller -class ResourceController { +class ResourceController( + val configHolder: ConfigHolder +) { private val log: Logger = LoggerFactory.getLogger(javaClass) - @Autowired - val configHolder: ConfigHolder? = null - @GetMapping("/resources/**") @ResponseBody fun resource(request: HttpServletRequest, response: HttpServletResponse) { diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/controller/HybridStageRestController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/controller/HybridStageRestController.kt index 65d267c..8da8657 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/controller/HybridStageRestController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/controller/HybridStageRestController.kt @@ -1,6 +1,6 @@ package de.visualdigits.kotlin.klanglicht.rest.hybrid.controller -import de.visualdigits.kotlin.klanglicht.rest.hybrid.handler.HybridStageHandler +import de.visualdigits.kotlin.klanglicht.rest.hybrid.service.HybridStageService import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping @@ -10,10 +10,9 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/v1/hybrid/json") -class HybridStageRestController { - - @Autowired - val hybridStageHandler: HybridStageHandler? = null +class HybridStageRestController( + val hybridStageService: HybridStageService? = null +) { @GetMapping("hexColor") fun hexColor( @@ -25,7 +24,7 @@ class HybridStageRestController { @RequestParam(value = "store", required = false, defaultValue = "true") store: Boolean, @RequestParam(value = "storeName", required = false) storeName: String? ) { - hybridStageHandler?.hexColor( + hybridStageService?.hexColor( ids = ids, hexColors = hexColors, gains = gains, @@ -41,7 +40,7 @@ class HybridStageRestController { @RequestParam(value = "id") id: String, @RequestParam(value = "hexColor") hexColor: String ) { - hybridStageHandler?.putColor( + hybridStageService?.putColor( id = id, hexColor = hexColor ) diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/handler/HybridStageHandler.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/service/HybridStageService.kt similarity index 94% rename from klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/handler/HybridStageHandler.kt rename to klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/service/HybridStageService.kt index 23cea55..13fc204 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/handler/HybridStageHandler.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/hybrid/service/HybridStageService.kt @@ -1,4 +1,4 @@ -package de.visualdigits.kotlin.klanglicht.rest.hybrid.handler +package de.visualdigits.kotlin.klanglicht.rest.hybrid.service import de.visualdigits.kotlin.klanglicht.hardware.hybrid.HybridScene import de.visualdigits.kotlin.klanglicht.hardware.shelly.client.ShellyClient @@ -6,16 +6,15 @@ import de.visualdigits.kotlin.klanglicht.rest.configuration.ConfigHolder import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Component +import org.springframework.stereotype.Service -@Component -class HybridStageHandler { +@Service +class HybridStageService( + val configHolder: ConfigHolder +) { private val log: Logger = LoggerFactory.getLogger(javaClass) - @Autowired - val configHolder: ConfigHolder? = null - /** * Set hex colors. * diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerRestController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerRestController.kt index b01261e..a7af2d1 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerRestController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerRestController.kt @@ -12,15 +12,15 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController + /** * REST controller for the light manager air. */ @RestController @RequestMapping("/v1/lightmanager/json") -class LightmanagerRestController { - - @Autowired - var client: LightmanagerService? = null +class LightmanagerRestController( + var client: LightmanagerService +) { @GetMapping("params", produces = [MediaType.APPLICATION_JSON_VALUE]) fun params(): LMParams? = client?.params() diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerWebController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerWebController.kt index 0b21d82..7da5ca1 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerWebController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/controller/LightmanagerWebController.kt @@ -12,13 +12,11 @@ import org.springframework.web.bind.annotation.RequestMapping @Controller @RequestMapping("/v1/lightmanager/web") -class LightmanagerWebController { +class LightmanagerWebController( + var configHolder: ConfigHolder, + var client: LightmanagerService +) { - @Autowired - var configHolder: ConfigHolder? = null - - @Autowired - var client: LightmanagerService? = null @GetMapping("/scenes", produces = ["application/xhtml+xml"]) fun scenes(model: Model): String { diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/model/html/LMHtmlScene.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/model/html/LMHtmlScene.kt index 879ba61..6898afc 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/model/html/LMHtmlScene.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/model/html/LMHtmlScene.kt @@ -13,7 +13,7 @@ class LMHtmlScene( } fun toHtml(configHolder: ConfigHolder, group: String): String { - val lightmanagerUrl = configHolder.preferences?.getService("lmair")?.url + val url = configHolder.preferences?.getService("lmair")?.url val sb = StringBuilder() sb.append("
\n") diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/service/LightmanagerService.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/service/LightmanagerService.kt index c295df4..75c583e 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/service/LightmanagerService.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/lightmanager/service/LightmanagerService.kt @@ -13,16 +13,14 @@ import org.springframework.stereotype.Service @Service class LightmanagerService( var lightmanagerUrl: String? = null, - var client: LightmanagerClient? = null + var client: LightmanagerClient? = null, + val configHolder: ConfigHolder ) { - @Autowired - val configHolder: ConfigHolder? = null - @PostConstruct fun initialize() { if (lightmanagerUrl == null) { - lightmanagerUrl = configHolder!!.preferences?.getService("lmair")?.url + lightmanagerUrl = configHolder.preferences?.getService("lmair")?.url!! } client = lightmanagerUrl?.let { LightmanagerClient(it) } } diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyRestController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyRestController.kt index 04b3531..9f6b783 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyRestController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyRestController.kt @@ -1,6 +1,6 @@ package de.visualdigits.kotlin.klanglicht.rest.shelly.controller -import de.visualdigits.kotlin.klanglicht.rest.hybrid.handler.HybridStageHandler +import de.visualdigits.kotlin.klanglicht.rest.hybrid.service.HybridStageService import de.visualdigits.kotlin.klanglicht.rest.lightmanager.service.LightmanagerService import de.visualdigits.kotlin.klanglicht.rest.shelly.service.ShellyService import org.springframework.beans.factory.annotation.Autowired @@ -14,16 +14,12 @@ import org.springframework.web.bind.annotation.RestController */ @RestController @RequestMapping("/v1/shelly") -class ShellyRestController { +class ShellyRestController( + var shellyService: ShellyService, + var lightmanagerService: LightmanagerService, + val hybridStageService: HybridStageService +) { - @Autowired - var shellyService: ShellyService? = null - - @Autowired - var lightmanagerService: LightmanagerService? = null - - @Autowired - val hybridStageHandler: HybridStageHandler? = null /** * Sets the given scene or index on the connected lightmanager air. @@ -62,7 +58,7 @@ class ShellyRestController { @RequestParam(value = "store", required = false, defaultValue = "true") store: Boolean, @RequestParam(value = "storeName", required = false) storeName: String? ) { - hybridStageHandler?.hexColor( + hybridStageService?.hexColor( ids = ids, hexColors = hexColors, gains = gains, @@ -78,7 +74,7 @@ class ShellyRestController { @RequestParam(value = "ids", required = false, defaultValue = "") ids: String, @RequestParam(value = "transition", required = false) transitionDuration: Long? ) { - hybridStageHandler?.restoreColors(ids = ids, transitionDuration = transitionDuration) + hybridStageService?.restoreColors(ids = ids, transitionDuration = transitionDuration) } @GetMapping("gain") @@ -87,6 +83,6 @@ class ShellyRestController { @RequestParam(value = "gain", required = false, defaultValue = "") gain: Int, @RequestParam(value = "transition", required = false) transitionDuration: Long? ) { - hybridStageHandler?.gain(ids = ids, gain = gain, transitionDuration = transitionDuration) + hybridStageService?.gain(ids = ids, gain = gain, transitionDuration = transitionDuration) } } diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyWebController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyWebController.kt index 0c59cd2..aa1ae57 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyWebController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/controller/ShellyWebController.kt @@ -12,13 +12,10 @@ import org.springframework.web.bind.annotation.RequestMapping @Controller @RequestMapping("/v1/shelly/web") -class ShellyWebController { - - @Autowired - var configHolder: ConfigHolder? = null - - @Autowired - var shellyService: ShellyService? = null +class ShellyWebController( + var configHolder: ConfigHolder, + var shellyService: ShellyService +) { @GetMapping("powers", produces = ["application/xhtml+xml"]) fun currentPowers(model: Model, request: HttpServletRequest?): String { diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/service/ShellyService.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/service/ShellyService.kt index 94bab02..af5f3bc 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/service/ShellyService.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/shelly/service/ShellyService.kt @@ -11,13 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service @Service -class ShellyService { +class ShellyService( + val configHolder: ConfigHolder +) { private val log: Logger = LoggerFactory.getLogger(javaClass) - @Autowired - val configHolder: ConfigHolder? = null - fun power( ids: String, turnOn: Boolean, diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledArrayController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledArrayController.kt index d605f3a..08f73a1 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledArrayController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledArrayController.kt @@ -24,12 +24,12 @@ import java.io.File @RestController() @RequestMapping("/twinkly/api/v1/xledarray") -class XledArrayController { +class XledArrayController( + var configHolder: ConfigHolder +) { private val log = LoggerFactory.getLogger(XledArrayController::class.java) - @Autowired - var configHolder: ConfigHolder? = null private var playable: Playable? = null diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledDeviceController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledDeviceController.kt index c913921..0f734d6 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledDeviceController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/twinkly/controller/XledDeviceController.kt @@ -15,13 +15,12 @@ import org.springframework.web.bind.annotation.RestController @RestController() @RequestMapping("/twinkly/api/v1/xleddevice") -class XledDeviceController { +class XledDeviceController( + private var configHolder: ConfigHolder +) { private val log = LoggerFactory.getLogger(XledDeviceController::class.java) - @Autowired - private var configHolder: ConfigHolder? = null - @PutMapping("/{device}/power/on") fun powerOn( @PathVariable device: String diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamaha/controller/YamahaReceiverRestController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamaha/controller/YamahaReceiverRestController.kt index 75945e2..2d777ac 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamaha/controller/YamahaReceiverRestController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamaha/controller/YamahaReceiverRestController.kt @@ -2,6 +2,7 @@ package de.visualdigits.kotlin.klanglicht.rest.yamaha.controller import de.visualdigits.kotlin.klanglicht.hardware.yamaha.client.YamahaReceiverClient import de.visualdigits.kotlin.klanglicht.rest.configuration.ConfigHolder +import jakarta.annotation.PostConstruct import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -13,25 +14,24 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/v1/yamaha/xml") -class YamahaReceiverRestController { +class YamahaReceiverRestController( + val configHolder: ConfigHolder +) { private val log: Logger = LoggerFactory.getLogger(javaClass) - @Autowired - val configHolder: ConfigHolder? = null - var client: YamahaReceiverClient? = null + @PostConstruct + fun initialize() { + if (client == null) { + client = configHolder.preferences?.getService("receiver")?.url?.let { YamahaReceiverClient(it) } + } + } + @PutMapping("/surroundProgram") fun surroundProgram(@RequestParam("program") program: String) { - ensureClient() log.info("Setting surround sound program to '$program'") client?.controlSurroundProgram(program) } - - private fun ensureClient() { - if (client == null) { - client = configHolder!!.preferences?.getService("receiver")?.url?.let { YamahaReceiverClient(it) } - } - } } diff --git a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamahaavantage/controller/YamahaAvantageReceiverRestController.kt b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamahaavantage/controller/YamahaAvantageReceiverRestController.kt index 4f51552..5851a60 100644 --- a/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamahaavantage/controller/YamahaAvantageReceiverRestController.kt +++ b/klanglicht-rest/src/main/kotlin/de/visualdigits/kotlin/klanglicht/rest/yamahaavantage/controller/YamahaAvantageReceiverRestController.kt @@ -2,6 +2,7 @@ package de.visualdigits.kotlin.klanglicht.rest.yamahaavantage.controller import de.visualdigits.kotlin.klanglicht.hardware.yamahaadvantage.client.YamahaAvantageReceiverClient import de.visualdigits.kotlin.klanglicht.rest.configuration.ConfigHolder +import jakarta.annotation.PostConstruct import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -12,27 +13,26 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/v1/yamaha/avantage/json") -class YamahaAvantageReceiverRestController { +class YamahaAvantageReceiverRestController( + val configHolder: ConfigHolder +) { private val log: Logger = LoggerFactory.getLogger(javaClass) - @Autowired - val configHolder: ConfigHolder? = null - var client: YamahaAvantageReceiverClient? = null - @PutMapping("/surroundProgram") - fun controlSurroundProgram(@RequestParam("program") program: String) { - ensureClient() - log.info("Setting surround sound program to '$program'") - client!!.setSurroundProgram(program) - } - - private fun ensureClient() { + @PostConstruct + fun initialize() { if (client == null) { client = YamahaAvantageReceiverClient( configHolder!!.preferences?.getService("receiver")?.url!! ) } } + + @PutMapping("/surroundProgram") + fun controlSurroundProgram(@RequestParam("program") program: String) { + log.info("Setting surround sound program to '$program'") + client!!.setSurroundProgram(program) + } }