-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from ReneeVandervelde/empty-rooms
Handle null brightness on light states.
- Loading branch information
Showing
5 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
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
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
40 changes: 40 additions & 0 deletions
40
lights/src/main/kotlin/inkapplications/shade/lights/HueLightStateTransformer.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,40 @@ | ||
package inkapplications.shade.lights | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.ToJson | ||
import inkapplications.shade.constructs.percent | ||
|
||
/** | ||
* Convert internal hue representation to public object. | ||
*/ | ||
internal object HueLightStateTransformer { | ||
@FromJson | ||
fun fromHue(state: HueLightState) = LightState( | ||
on = state.on, | ||
brightness = state.brightness ?: state.on.let { if (it) 100.percent else 0.percent }, | ||
hue = state.hue, | ||
saturation = state.saturation, | ||
effect = state.effect, | ||
cieColorCoordinates = state.cieColorCoordinates, | ||
colorTemperature = state.colorTemperature, | ||
alert = state.alert, | ||
colorMode = state.colorMode, | ||
mode = state.mode, | ||
reachable = state.reachable | ||
) | ||
|
||
@ToJson | ||
fun toHue(state: LightState) = HueLightState( | ||
on = state.on, | ||
brightness = state.brightness, | ||
hue = state.hue, | ||
saturation = state.saturation, | ||
effect = state.effect, | ||
cieColorCoordinates = state.cieColorCoordinates, | ||
colorTemperature = state.colorTemperature, | ||
alert = state.alert, | ||
colorMode = state.colorMode, | ||
mode = state.mode, | ||
reachable = state.reachable | ||
) | ||
} |
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
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