You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
package com.example.smarthome.manager
import androidx.lifecycle.MutableLiveData
import com.example.smarthome.model.AutomationScene
class SceneManager {
}