Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SceneManager.kt #714

Copy link
Copy link

Description

@myltik1702
Issue body actions

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
}

}

Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.