clean-code-javascript icon indicating copy to clipboard operation
clean-code-javascript copied to clipboard

SceneManager.kt

Open myltik1702 opened this issue 2 months ago • 0 comments

package com.example.smarthome.manager

import androidx.lifecycle.MutableLiveData import com.example.smarthome.model.AutomationScene

class SceneManager {

val scenes: MutableLiveData<List<AutomationScene>> = MutableLiveData()

private val storedScenes: MutableList<AutomationScene> = mutableListOf()

fun createScene(scene: AutomationScene): Boolean {
    if (storedScenes.any { it.id == scene.id }) {
        return false // Сценарий уже существует
    }
    storedScenes.add(scene)
    scenes.value = storedScenes
    return true
}

fun executeScene(sceneId: String): Boolean {
    val scene = storedScenes.find { it.id == sceneId } ?: return false
    // Здесь логика выполнения действий сценария
    println("Выполняется сценарий: ${scene.name}")
    return true
}

fun fetchScenes() {
    // Запрос к API или базе данных
    // Для примера: тестовые данные
    val testScenes = listOf(
        AutomationScene(
            "1",
            "Вечерняя подсветка",
            TriggerCondition("time", "20:00"),
            listOf(
                DeviceAction("1", "on", mapOf("brightness" to "50"))
            )
        )
    )
    storedScenes.clear()
    storedScenes.addAll(testScenes)
    scenes.value = storedScenes
}

}

myltik1702 avatar Nov 26 '25 06:11 myltik1702