Fix fan speed for non int fan speeds. (#1060)

This commit is contained in:
Justin Bassett 2020-10-16 07:37:26 -04:00 committed by GitHub
parent 28152b6f6c
commit 44d8af97e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,7 @@ class FanControl {
val speeds = entity.attributes["speed_list"].toString()
.removeSurrounding("[", "]")
.split(", ")
val currentSpeed: Int? = entity.attributes["speed"].toString().toIntOrNull()
val currentSpeed = entity.attributes["speed"].toString()
val control = Control.StatefulBuilder(
entity.entityId,
@ -42,7 +42,7 @@ class FanControl {
control.setTitle(entity.attributes["friendly_name"].toString())
control.setDeviceType(DeviceTypes.TYPE_FAN)
control.setStatus(Control.STATUS_OK)
if (currentSpeed != null) {
if (currentSpeed.isNotBlank()) {
control.setControlTemplate(
ToggleRangeTemplate(
entity.entityId,
@ -52,7 +52,7 @@ class FanControl {
entity.entityId,
0f,
speeds.size.toFloat() - 1,
speeds.indexOf(currentSpeed.toString()).toFloat(),
speeds.indexOf(currentSpeed).toFloat(),
1f,
""
)