Skip to content

Commit

Permalink
Merge pull request #61 from efirestone/firestone/no-impl-cast
Browse files Browse the repository at this point in the history
Add Sensor method to HomeAssistantApiClient protocol
  • Loading branch information
efirestone authored Jun 26, 2023
2 parents bacf6c8 + 61c4cd2 commit 4fa69c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.codellyrandom.hassle

import com.codellyrandom.hassle.entities.Attributes
import com.codellyrandom.hassle.entities.State
import com.codellyrandom.hassle.entities.devices.Sensor
import com.codellyrandom.hassle.errorHandling.ErrorResponseData
import com.codellyrandom.hassle.events.EventHandlerFunction
import com.codellyrandom.hassle.observability.Switchable
import com.codellyrandom.hassle.values.EntityId
import com.codellyrandom.hassle.values.EventType
import kotlin.reflect.KClass

Expand Down Expand Up @@ -57,4 +61,11 @@ interface HomeAssistantApiClient {
* @param errorResponseHandler the handler to be attached.
*/
fun setErrorResponseHandler(errorResponseHandler: (ErrorResponseData) -> Unit)

// A non-reified interface that external callers can use to create their own custom sensor implementations.
fun <S : State<*>, A : Attributes> Sensor(
id: EntityId,
stateType: KClass<S>,
attributesType: KClass<A>
): Sensor<S, A>
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal class HomeAssistantApiClientImpl(
*
* @return [Sensor]
*/
fun <S : State<*>, A : Attributes> Sensor(
override fun <S : State<*>, A : Attributes> Sensor(
id: EntityId,
stateType: KClass<S>,
attributesType: KClass<A>
Expand Down Expand Up @@ -143,7 +143,7 @@ internal class HomeAssistantApiClientImpl(
attributesType: KClass<A>,
serviceCommandResolver: ServiceCommandResolver<S>
): Actuator<S, A> =
Actuator<S, A>(
Actuator(
id,
this,
mapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@ import com.codellyrandom.hassle.entities.State
import com.codellyrandom.hassle.entities.devices.Actuator
import com.codellyrandom.hassle.entities.devices.Sensor
import com.codellyrandom.hassle.values.EntityId
import kotlin.reflect.KClass

/**
* Base factories
*/

internal inline fun <reified S : State<*>, reified A : Attributes> HomeAssistantApiClient.Sensor(id: EntityId): Sensor<S, A> =
(this as HomeAssistantApiClientImpl).Sensor(id, S::class, A::class)

// A non-reified interface that external callers can use to create their own custom sensor implementations.
fun <S : State<*>, A : Attributes> HomeAssistantApiClient.Sensor(
id: EntityId,
stateType: KClass<S>,
attributesType: KClass<A>
): Sensor<S, A> =
(this as HomeAssistantApiClientImpl).Sensor(id, stateType, attributesType)
Sensor(id, S::class, A::class)

internal inline fun <reified S : State<*>, reified A : Attributes> HomeAssistantApiClient.Actuator(
id: EntityId,
Expand Down

0 comments on commit 4fa69c5

Please sign in to comment.