Skip to content

SceneManager.kt #714

Description

@myltik1702

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
}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions