dennisschroeder / khome

Khome is a smart home automation library for Home Assistant written in Kotlin.
MIT License
115 stars 7 forks source link

Koin cant find HassApiClient #191

Closed tabilzad closed 3 years ago

tabilzad commented 3 years ago
Exception in thread "main" org.koin.core.error.NoBeanDefFoundException: No definition found for 'khome.communicating.HassApiClient' has been found. Check your module definitions.
    at org.koin.core.scope.Scope.findDefinition(Scope.kt:170)
    at org.koin.core.scope.Scope.resolveInstance(Scope.kt:164)
    at org.koin.core.scope.Scope.get(Scope.kt:128)
    at khome.KhomeApplicationImpl$special$$inlined$inject$default$2.invoke(Scope.kt:327)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at khome.KhomeApplicationImpl.getHassApi(KhomeApplicationImpl.kt:62)
    at khome.KhomeApplicationImpl.callService(KhomeApplicationImpl.kt:139)
    at khome.KHmoeMainKt.main(KHmoeMain.kt:25)
    at khome.KHmoeMainKt.main(KHmoeMain.kt)
fun main() {
    KHOME.notifyMobileApp(Device.from("mmy_phone")) {
        title = "INTRUDER ALARM"
        message = "Garden shed door opened"
    }
    KHOME.runBlocking()
}
dennisschroeder commented 3 years ago

Hey thx for reporting this issue...I will look at it soon.

dennisschroeder commented 3 years ago

You cannot call this method from the main function since it would be called before KHOME is fully ready. Usually you do not want to get a message directly after starting your (khome) application. But if you want to you can do it like this:

fun main() {
    KHOME.onApplicationReady {
        KHOME.notifyMobileApp(Device.from("mmy_phone")) {
            title = "Application ready"
            message = "KHOME is ready to serve you."
        }
    }
    KHOME.runBlocking()
}

Otherwise just use KHOME::notifyMobileApp from any other observable like this:

val KHOME = khomeApplication()

val gardenShedContact = KHOME.ContactSensor("gardenshed".objectId)

fun main() {
    gardenShedContact.onOpened { 
        KHOME.notifyMobileApp(Device.from("my_phone")) {
            title = "INTRUDER ALARM"
            message = "Garden shed door opened"
        }
    }

    KHOME.runBlocking()
}