diff --git a/build.gradle.kts b/build.gradle.kts index 08910ec7..f710a70a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,10 +4,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.4.30" - id("org.jetbrains.dokka") version "0.10.1" + id("org.jetbrains.dokka") version "1.6.10" `maven-publish` - id("io.gitlab.arturbosch.detekt") version "1.9.1" - id("org.jlleitschuh.gradle.ktlint") version "9.3.0" + id("io.gitlab.arturbosch.detekt") version "1.19.0" + id("org.jlleitschuh.gradle.ktlint") version "10.2.1" id("de.jansauer.printcoverage") version "2.0.0" jacoco id("com.github.dawnwords.jacoco.badge") version "0.2.0" @@ -20,20 +20,18 @@ java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { mavenLocal() google() - jcenter() - maven { url = uri("https://kotlin.bintray.com/ktor") } - maven { url = uri("https://kotlin.bintray.com/kotlinx") } - jcenter() { url = uri("https://dl.bintray.com/kotlin/dokka") } + mavenCentral() } val ktorVersion: String by project val koinVersion: String by project val mockkVersion: String by project val jupiterVersion: String by project -val assertVersion: String by project +val assertKVersion: String by project val dataBobVersion: String by project val jsonAssertVersion: String by project val kotlinLoggingVersion: String by project +val slf4jVersion: String by project dependencies { implementation(kotlin("stdlib-jdk8")) @@ -42,19 +40,18 @@ dependencies { implementation("io.ktor:ktor-client-cio:$ktorVersion") implementation("io.ktor:ktor-client-json-jvm:$ktorVersion") implementation("io.ktor:ktor-client-gson:$ktorVersion") - implementation("org.koin:koin-core:$koinVersion") - implementation("org.slf4j:slf4j-simple:1.7.30") + implementation("io.insert-koin:koin-core:$koinVersion") + implementation("org.slf4j:slf4j-simple:$slf4jVersion") implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion") - testImplementation("org.koin:koin-test:$koinVersion") { + testImplementation("io.insert-koin:koin-test:$koinVersion") { exclude(group = "org.mockito") exclude(group = "junit") } testImplementation("io.mockk:mockk:$mockkVersion") implementation("org.junit.jupiter:junit-jupiter-api:$jupiterVersion") - testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertVersion") + testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertKVersion") testImplementation("org.skyscreamer:jsonassert:$jsonAssertVersion") - testImplementation("io.github.daviddenton:databob.kotlin:$dataBobVersion") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") } @@ -66,15 +63,14 @@ tasks.withType { } tasks { - val dokka by getting(DokkaTask::class) + val dokkaHtml by getting(DokkaTask::class) - dokka { - outputFormat = "html" - outputDirectory = "$rootDir/docs" + dokkaHtml { + outputDirectory.set(rootDir.resolve("docs")) } } -defaultTasks("dokka") +defaultTasks("dokkaHtml") val sourcesJar by tasks.registering(Jar::class) { classifier = "sources" @@ -120,7 +116,7 @@ detekt { } ktlint { - version.set("0.22.0") + version.set("0.44.0") ignoreFailures.set(false) } diff --git a/config/detekt-config.yml b/config/detekt-config.yml index f152ae22..6c1c3a40 100644 --- a/config/detekt-config.yml +++ b/config/detekt-config.yml @@ -5,6 +5,9 @@ console-reports: - 'ComplexityReport' - 'NotificationReport' +build: + maxIssues: 10 # break the build if more than ten weighted issues are found + # disabled rule-sets comments: active: false diff --git a/gradle.properties b/gradle.properties index 5ecb7183..238a670c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ ktorVersion=1.4.0 koinVersion=2.1.6 kotlinLoggingVersion=1.12.0 -mockkVersion=1.10.0 -jupiterVersion=5.6.2 -assertVersion=0.20 -dataBobVersion=1.9.0 +mockkVersion=1.12.2 +jupiterVersion=5.8.2 +assertKVersion=0.25 jsonAssertVersion=1.5.0 +slf4jVersion=1.7.36 kotlin.code.style=official kotlin_version=1.3.50 diff --git a/src/main/kotlin/khome/core/boot/servicestore/ServiceStore.kt b/src/main/kotlin/khome/core/boot/servicestore/ServiceStore.kt index 9c9d406a..2e54e964 100644 --- a/src/main/kotlin/khome/core/boot/servicestore/ServiceStore.kt +++ b/src/main/kotlin/khome/core/boot/servicestore/ServiceStore.kt @@ -11,7 +11,8 @@ interface ServiceStoreInterface { fun clear() } -internal class ServiceStore : Iterable>>, +internal class ServiceStore : + Iterable>>, ServiceStoreInterface { override val list = ConcurrentHashMap>() override operator fun iterator() = list.iterator() diff --git a/src/main/kotlin/khome/core/boot/servicestore/ServiceStoreInitializer.kt b/src/main/kotlin/khome/core/boot/servicestore/ServiceStoreInitializer.kt index 1fc74e49..bb42fd49 100644 --- a/src/main/kotlin/khome/core/boot/servicestore/ServiceStoreInitializer.kt +++ b/src/main/kotlin/khome/core/boot/servicestore/ServiceStoreInitializer.kt @@ -4,7 +4,7 @@ import khome.KhomeSession import khome.communicating.CALLER_ID import mu.KotlinLogging -internal class ServiceStoreInitializerImpl ( +internal class ServiceStoreInitializerImpl( private val khomeSession: KhomeSession, private val serviceStore: ServiceStoreInterface ) : ServiceStoreInitializer { diff --git a/src/main/kotlin/khome/core/boot/statehandling/EntityStateInitializer.kt b/src/main/kotlin/khome/core/boot/statehandling/EntityStateInitializer.kt index d88cd030..58f260d5 100644 --- a/src/main/kotlin/khome/core/boot/statehandling/EntityStateInitializer.kt +++ b/src/main/kotlin/khome/core/boot/statehandling/EntityStateInitializer.kt @@ -6,9 +6,9 @@ import khome.KhomeSession import khome.communicating.CALLER_ID import khome.core.koin.KhomeComponent import khome.entities.ActuatorStateUpdater -import khome.values.EntityId import khome.entities.EntityRegistrationValidation import khome.entities.SensorStateUpdater +import khome.values.EntityId import kotlinx.coroutines.ObsoleteCoroutinesApi import mu.KotlinLogging diff --git a/src/main/kotlin/khome/core/exceptions/EventStreamException.kt b/src/main/kotlin/khome/core/exceptions/EventStreamException.kt index 7e852069..9060038c 100644 --- a/src/main/kotlin/khome/core/exceptions/EventStreamException.kt +++ b/src/main/kotlin/khome/core/exceptions/EventStreamException.kt @@ -1,3 +1,3 @@ package khome.core.exceptions -class EventStreamException(override val message: String) : RuntimeException() \ No newline at end of file +class EventStreamException(override val message: String) : RuntimeException() diff --git a/src/main/kotlin/khome/core/exceptions/InvalidAttributeValueTypeException.kt b/src/main/kotlin/khome/core/exceptions/InvalidAttributeValueTypeException.kt index ce5e9cf3..448cc7a1 100644 --- a/src/main/kotlin/khome/core/exceptions/InvalidAttributeValueTypeException.kt +++ b/src/main/kotlin/khome/core/exceptions/InvalidAttributeValueTypeException.kt @@ -1,3 +1,3 @@ package khome.core.exceptions -class InvalidAttributeValueTypeException(override val message: String) : RuntimeException() \ No newline at end of file +class InvalidAttributeValueTypeException(override val message: String) : RuntimeException() diff --git a/src/main/kotlin/khome/core/exceptions/InvalidStateValueTypeException.kt b/src/main/kotlin/khome/core/exceptions/InvalidStateValueTypeException.kt index a5180379..347f9304 100644 --- a/src/main/kotlin/khome/core/exceptions/InvalidStateValueTypeException.kt +++ b/src/main/kotlin/khome/core/exceptions/InvalidStateValueTypeException.kt @@ -1,3 +1,3 @@ package khome.core.exceptions -class InvalidStateValueTypeException(override val message: String) : RuntimeException() \ No newline at end of file +class InvalidStateValueTypeException(override val message: String) : RuntimeException() diff --git a/src/main/kotlin/khome/entities/EntityRegistrationValidation.kt b/src/main/kotlin/khome/entities/EntityRegistrationValidation.kt index beb55be3..b268a863 100644 --- a/src/main/kotlin/khome/entities/EntityRegistrationValidation.kt +++ b/src/main/kotlin/khome/entities/EntityRegistrationValidation.kt @@ -59,7 +59,7 @@ internal class EntityRegistrationValidation( ################ ERROR ################# - """.trimIndent() + """.trimIndent() } throw EntityRegistrationValidationException("Entity registration validation failed!") diff --git a/src/main/kotlin/khome/extending/entities/BaseFactories.kt b/src/main/kotlin/khome/extending/entities/BaseFactories.kt index 0b8dea69..8bf66606 100644 --- a/src/main/kotlin/khome/extending/entities/BaseFactories.kt +++ b/src/main/kotlin/khome/extending/entities/BaseFactories.kt @@ -3,10 +3,10 @@ package khome.extending.entities import khome.KhomeApplication import khome.communicating.ServiceCommandResolver import khome.entities.Attributes -import khome.values.EntityId import khome.entities.State import khome.entities.devices.Actuator import khome.entities.devices.Sensor +import khome.values.EntityId /** * Base factories diff --git a/src/main/kotlin/khome/extending/entities/actuators/Cover.kt b/src/main/kotlin/khome/extending/entities/actuators/Cover.kt index 9fa0bf96..e34d2f6b 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/Cover.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/Cover.kt @@ -30,24 +30,27 @@ inline fun , reified A : Attributes> KhomeApplication.Cover @Suppress("FunctionName") fun KhomeApplication.PositionableCover(objectId: ObjectId): PositionableCover = - Cover(objectId, ServiceCommandResolver { state -> - when (state.value) { - PositionableCoverValue.OPEN -> state.currentPosition?.let { position -> - DefaultResolvedServiceCommand( - service = "set_cover_position".service, - serviceData = PositionableCoverServiceData(position) + Cover( + objectId, + ServiceCommandResolver { state -> + when (state.value) { + PositionableCoverValue.OPEN -> state.currentPosition?.let { position -> + DefaultResolvedServiceCommand( + service = "set_cover_position".service, + serviceData = PositionableCoverServiceData(position) + ) + } ?: DefaultResolvedServiceCommand( + service = "open_cover".service, + serviceData = EntityIdOnlyServiceData() ) - } ?: DefaultResolvedServiceCommand( - service = "open_cover".service, - serviceData = EntityIdOnlyServiceData() - ) - - PositionableCoverValue.CLOSED -> DefaultResolvedServiceCommand( - service = "close_cover".service, - serviceData = EntityIdOnlyServiceData() - ) + + PositionableCoverValue.CLOSED -> DefaultResolvedServiceCommand( + service = "close_cover".service, + serviceData = EntityIdOnlyServiceData() + ) + } } - }) + ) data class PositionableCoverState( override val value: PositionableCoverValue, diff --git a/src/main/kotlin/khome/extending/entities/actuators/Switch.kt b/src/main/kotlin/khome/extending/entities/actuators/Switch.kt index b92044e4..db608220 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/Switch.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/Switch.kt @@ -3,11 +3,11 @@ package khome.extending.entities.actuators import khome.KhomeApplication import khome.communicating.ServiceCommandResolver import khome.entities.Attributes -import khome.values.EntityId import khome.entities.devices.Actuator import khome.extending.entities.Actuator import khome.extending.entities.SwitchableState import khome.extending.entities.mapSwitchable +import khome.values.EntityId import khome.values.FriendlyName import khome.values.ObjectId import khome.values.PowerConsumption @@ -20,9 +20,12 @@ typealias PowerSwitch = Switch @Suppress("FunctionName") inline fun KhomeApplication.Switch(objectId: ObjectId): Switch = - Actuator(EntityId.fromPair("switch".domain to objectId), ServiceCommandResolver { switchableState -> - mapSwitchable(switchableState.value) - }) + Actuator( + EntityId.fromPair("switch".domain to objectId), + ServiceCommandResolver { switchableState -> + mapSwitchable(switchableState.value) + } + ) @Suppress("FunctionName") fun KhomeApplication.PowerMeasuringSwitch(objectId: ObjectId): PowerSwitch = Switch(objectId) diff --git a/src/main/kotlin/khome/extending/entities/actuators/climate/thermostate/Thermostat.kt b/src/main/kotlin/khome/extending/entities/actuators/climate/thermostate/Thermostat.kt index 231fe212..b82c0947 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/climate/thermostate/Thermostat.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/climate/thermostate/Thermostat.kt @@ -27,33 +27,36 @@ typealias Thermostat = Actuator @Suppress("FunctionName") fun KhomeApplication.Thermostat(objectId: ObjectId): Thermostat { - return ClimateControl(objectId, ServiceCommandResolver { desiredState -> - when (desiredState.value) { - ThermostatStateValue.OFF -> { - DefaultResolvedServiceCommand( - service = "turn_off".service, - serviceData = EntityIdOnlyServiceData() - ) - } - - ThermostatStateValue.HEAT -> { - desiredState.temperature?.let { temperature -> + return ClimateControl( + objectId, + ServiceCommandResolver { desiredState -> + when (desiredState.value) { + ThermostatStateValue.OFF -> { DefaultResolvedServiceCommand( - service = "set_temperature".service, - serviceData = ThermostatServiceData(temperature, hvacMode = "heat".hvacMode) + service = "turn_off".service, + serviceData = EntityIdOnlyServiceData() ) - } ?: (if (desiredState.presetMode.isNone) null else desiredState.presetMode)?.let { preset -> - DefaultResolvedServiceCommand( - service = "set_preset_mode".service, - serviceData = ThermostatServiceData(presetMode = preset) + } + + ThermostatStateValue.HEAT -> { + desiredState.temperature?.let { temperature -> + DefaultResolvedServiceCommand( + service = "set_temperature".service, + serviceData = ThermostatServiceData(temperature, hvacMode = "heat".hvacMode) + ) + } ?: (if (desiredState.presetMode.isNone) null else desiredState.presetMode)?.let { preset -> + DefaultResolvedServiceCommand( + service = "set_preset_mode".service, + serviceData = ThermostatServiceData(presetMode = preset) + ) + } ?: DefaultResolvedServiceCommand( + service = "turn_on".service, + serviceData = EntityIdOnlyServiceData() ) - } ?: DefaultResolvedServiceCommand( - service = "turn_on".service, - serviceData = EntityIdOnlyServiceData() - ) + } } } - }) + ) } data class ThermostatState( diff --git a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputBoolean.kt b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputBoolean.kt index 474bf340..9073e38c 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputBoolean.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputBoolean.kt @@ -3,11 +3,11 @@ package khome.extending.entities.actuators.inputs import khome.KhomeApplication import khome.communicating.ServiceCommandResolver import khome.entities.Attributes -import khome.values.EntityId import khome.entities.devices.Actuator import khome.extending.entities.Actuator import khome.extending.entities.SwitchableState import khome.extending.entities.mapSwitchable +import khome.values.EntityId import khome.values.FriendlyName import khome.values.Icon import khome.values.ObjectId @@ -19,9 +19,12 @@ typealias InputBoolean = Actuator @Suppress("FunctionName") fun KhomeApplication.InputBoolean(objectId: ObjectId): InputBoolean = - Actuator(EntityId.fromPair("input_boolean".domain to objectId), ServiceCommandResolver { desiredState -> - mapSwitchable(desiredState.value) - }) + Actuator( + EntityId.fromPair("input_boolean".domain to objectId), + ServiceCommandResolver { desiredState -> + mapSwitchable(desiredState.value) + } + ) data class InputBooleanAttributes( val editable: Boolean, diff --git a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDate.kt b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDate.kt index bfcce125..cb2e7f14 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDate.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDate.kt @@ -21,12 +21,15 @@ typealias InputDate = Actuator @Suppress("FunctionName") fun KhomeApplication.InputDate(objectId: ObjectId): InputDate = - Actuator(EntityId.fromPair("input_datetime".domain to objectId), ServiceCommandResolver { desiredState -> - DefaultResolvedServiceCommand( - service = "set_datetime".service, - serviceData = InputDateServiceData(desiredState.value) - ) - }) + Actuator( + EntityId.fromPair("input_datetime".domain to objectId), + ServiceCommandResolver { desiredState -> + DefaultResolvedServiceCommand( + service = "set_datetime".service, + serviceData = InputDateServiceData(desiredState.value) + ) + } + ) data class InputDateState(override val value: LocalDate) : State diff --git a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDateTime.kt b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDateTime.kt index 04b2bace..7d5526c2 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDateTime.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputDateTime.kt @@ -21,14 +21,17 @@ typealias InputDateTime = Actuator @Suppress("FunctionName") fun KhomeApplication.InputDateTime(objectId: ObjectId): InputDateTime = - Actuator(EntityId.fromPair("input_datetime".domain to objectId), ServiceCommandResolver { desiredState -> - DefaultResolvedServiceCommand( - service = "set_datetime".service, - serviceData = InputDateTimeServiceData( - desiredState.value + Actuator( + EntityId.fromPair("input_datetime".domain to objectId), + ServiceCommandResolver { desiredState -> + DefaultResolvedServiceCommand( + service = "set_datetime".service, + serviceData = InputDateTimeServiceData( + desiredState.value + ) ) - ) - }) + } + ) data class InputDateTimeState(override val value: LocalDateTime) : State diff --git a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputNumber.kt b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputNumber.kt index 37578e31..5542b341 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputNumber.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputNumber.kt @@ -24,14 +24,17 @@ typealias InputNumber = Actuator @Suppress("FunctionName") fun KhomeApplication.InputNumber(objectId: ObjectId): InputNumber = - Actuator(EntityId.fromPair("input_number".domain to objectId), ServiceCommandResolver { desiredState -> - DefaultResolvedServiceCommand( - service = "set_value".service, - serviceData = SettableStateValueServiceData( - desiredState.value + Actuator( + EntityId.fromPair("input_number".domain to objectId), + ServiceCommandResolver { desiredState -> + DefaultResolvedServiceCommand( + service = "set_value".service, + serviceData = SettableStateValueServiceData( + desiredState.value + ) ) - ) - }) + } + ) data class InputNumberState(override val value: Double) : State diff --git a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputSelect.kt b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputSelect.kt index 8d886e82..f8b1c94e 100644 --- a/src/main/kotlin/khome/extending/entities/actuators/inputs/InputSelect.kt +++ b/src/main/kotlin/khome/extending/entities/actuators/inputs/InputSelect.kt @@ -21,14 +21,17 @@ typealias InputSelect = Actuator @Suppress("FunctionName") fun KhomeApplication.InputSelect(objectId: ObjectId): InputSelect = - Actuator(EntityId.fromPair("input_select".domain to objectId), ServiceCommandResolver { desiredState -> - DefaultResolvedServiceCommand( - service = "select_option".service, - serviceData = InputSelectServiceData( - desiredState.value + Actuator( + EntityId.fromPair("input_select".domain to objectId), + ServiceCommandResolver { desiredState -> + DefaultResolvedServiceCommand( + service = "select_option".service, + serviceData = InputSelectServiceData( + desiredState.value + ) ) - ) - }) + } + ) data class InputSelectAttributes( val options: List