-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32192c2
commit 43c64db
Showing
5 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/it/casaricci/hass/plugin/MockHassRemoteRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package it.casaricci.hass.plugin | ||
|
||
import com.intellij.json.JsonFileType | ||
import com.intellij.json.psi.JsonFile | ||
import com.intellij.json.psi.JsonProperty | ||
import com.intellij.json.psi.JsonStringLiteral | ||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFileFactory | ||
import com.intellij.util.ResourceUtil | ||
import it.casaricci.hass.plugin.services.HassRemoteRepository | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import java.io.FileInputStream | ||
|
||
class MockHassRemoteRepository(project: Project, jsonStatesPath: String?, jsonServicePath: String?) : | ||
HassRemoteRepository(project, CoroutineScope(Dispatchers.IO)) { | ||
|
||
private var states: Collection<JsonStringLiteral>? = null | ||
private var services: Collection<JsonProperty>? = null | ||
|
||
init { | ||
if (jsonStatesPath != null) { | ||
val jsonStatesData = ResourceUtil.loadText(FileInputStream(jsonStatesPath)) | ||
val jsonStatesFile = PsiFileFactory.getInstance(project) | ||
.createFileFromText("ha_states.json", JsonFileType.INSTANCE, jsonStatesData) as JsonFile | ||
|
||
states = getStates(jsonStatesFile) | ||
} | ||
|
||
if (jsonServicePath != null) { | ||
val jsonServicesData = ResourceUtil.loadText(FileInputStream(jsonServicePath)) | ||
val jsonServicesFile = PsiFileFactory.getInstance(project) | ||
.createFileFromText("ha_services.json", JsonFileType.INSTANCE, jsonServicesData) as JsonFile | ||
|
||
services = getServices(jsonServicesFile) | ||
} | ||
} | ||
|
||
override fun getStates(module: Module, vararg excludeDomains: String): Collection<JsonStringLiteral>? { | ||
return states | ||
} | ||
|
||
override fun getServices(module: Module): Collection<JsonProperty>? { | ||
return services | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/test/resources/completion/entity/configuration-local.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# used for completion with local data only (i.e. no states or services cache) | ||
script: | ||
script_test1: | ||
sequence: | ||
- action: <caret> |
9 changes: 9 additions & 0 deletions
9
src/test/resources/completion/entity/configuration-remote.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# used for completion with remote data only (i.e. with states cache) | ||
script: | ||
script_test2: | ||
sequence: | ||
- action: scene.turn_on | ||
target: | ||
entity_id: <caret> | ||
|
||
# TODO add some other supported local entities (e.g. input_text, automation, ...) |
This file was deleted.
Oops, something went wrong.