Skip to content

Commit b989878

Browse files
committed
Apply suggestions
1 parent bed0bb3 commit b989878

7 files changed

Lines changed: 21 additions & 66 deletions

File tree

common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/FriendlyState.kt

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -75,153 +75,115 @@ private fun Entity.stateResource(): Int? = when (domain) {
7575
"binary_sensor" -> {
7676
// https://github.com/home-assistant/core/blob/dev/homeassistant/components/binary_sensor/strings.json#L113
7777
when (attributes["device_class"]) {
78-
"battery" -> if (state ==
79-
"on"
80-
) {
78+
"battery" -> if (state == "on") {
8179
commonR.string.state_low
8280
} else {
8381
commonR.string.state_normal
8482
}
8583

86-
"battery_charging" -> if (state ==
87-
"on"
88-
) {
84+
"battery_charging" -> if (state == "on") {
8985
commonR.string.state_charging
9086
} else {
9187
commonR.string.state_not_charging
9288
}
9389

94-
"cold" -> if (state ==
95-
"on"
96-
) {
90+
"cold" -> if (state == "on") {
9791
commonR.string.state_cold
9892
} else {
9993
commonR.string.state_off
10094
}
10195

102-
"connectivity" -> if (state ==
103-
"on"
104-
) {
96+
"connectivity" -> if (state == "on") {
10597
commonR.string.state_connected
10698
} else {
10799
commonR.string.state_disconnected
108100
}
109101

110-
"door", "window", "garage_door", "opening" -> if (state ==
111-
"on"
112-
) {
102+
"door", "window", "garage_door", "opening" -> if (state == "on") {
113103
commonR.string.state_open
114104
} else {
115105
commonR.string.state_closed
116106
}
117107

118-
"gas" -> if (state ==
119-
"on"
120-
) {
108+
"gas" -> if (state == "on") {
121109
commonR.string.state_detected
122110
} else {
123111
commonR.string.state_clear
124112
}
125113

126-
"heat" -> if (state ==
127-
"on"
128-
) {
114+
"heat" -> if (state == "on") {
129115
commonR.string.state_hot
130116
} else {
131117
commonR.string.state_off
132118
}
133119

134-
"light" -> if (state ==
135-
"on"
136-
) {
120+
"light" -> if (state == "on") {
137121
commonR.string.state_light_detected
138122
} else {
139123
commonR.string.state_no_light
140124
}
141125

142-
"lock" -> if (state ==
143-
"on"
144-
) {
126+
"lock" -> if (state == "on") {
145127
commonR.string.state_unlocked
146128
} else {
147129
commonR.string.state_locked
148130
}
149131

150-
"moisture" -> if (state ==
151-
"on"
152-
) {
132+
"moisture" -> if (state == "on") {
153133
commonR.string.state_wet
154134
} else {
155135
commonR.string.state_dry
156136
}
157137

158-
"moving" -> if (state ==
159-
"on"
160-
) {
138+
"moving" -> if (state == "on") {
161139
commonR.string.state_moving
162140
} else {
163141
commonR.string.state_not_moving
164142
}
165143

166-
"plug" -> if (state ==
167-
"on"
168-
) {
144+
"plug" -> if (state == "on") {
169145
commonR.string.state_plugged_in
170146
} else {
171147
commonR.string.state_unplugged
172148
}
173149

174-
"presence" -> if (state ==
175-
"on"
176-
) {
150+
"presence" -> if (state == "on") {
177151
commonR.string.state_home
178152
} else {
179153
commonR.string.state_not_home
180154
}
181155

182-
"problem" -> if (state ==
183-
"on"
184-
) {
156+
"problem" -> if (state == "on") {
185157
commonR.string.state_problem
186158
} else {
187159
commonR.string.state_ok
188160
}
189161

190-
"running" -> if (state ==
191-
"on"
192-
) {
162+
"running" -> if (state == "on") {
193163
commonR.string.state_running
194164
} else {
195165
commonR.string.state_not_running
196166
}
197167

198-
"safety" -> if (state ==
199-
"on"
200-
) {
168+
"safety" -> if (state == "on") {
201169
commonR.string.state_unsafe
202170
} else {
203171
commonR.string.state_safe
204172
}
205173

206-
"tamper" -> if (state ==
207-
"on"
208-
) {
174+
"tamper" -> if (state == "on") {
209175
commonR.string.state_tampering_detected
210176
} else {
211177
commonR.string.state_off
212178
}
213179

214-
"update" -> if (state ==
215-
"on"
216-
) {
180+
"update" -> if (state == "on") {
217181
commonR.string.state_update_available
218182
} else {
219183
commonR.string.state_up_to_date
220184
}
221185

222-
else -> if (state ==
223-
"on"
224-
) {
186+
else -> if (state == "on") {
225187
commonR.string.state_on
226188
} else {
227189
commonR.string.state_off

common/src/test/kotlin/io/homeassistant/companion/android/common/data/integration/display/GetEntitiesForDisplayUseCaseTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ class GetEntitiesForDisplayUseCaseTest {
391391

392392
val items = useCase(serverId = serverId, entities = listOf(lightEntity)).awaitLoaded()
393393

394-
// The domain default branch of Entity.getIcon does not touch the context
395394
assertEquals(lightEntity.getIcon(), items.single().icon)
396395
}
397396

wear/src/main/kotlin/io/homeassistant/companion/android/complications/views/ComplicationConfigMainView.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.runtime.getValue
1010
import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.graphics.ColorFilter
12-
import androidx.compose.ui.platform.LocalContext
1312
import androidx.compose.ui.res.stringResource
1413
import androidx.compose.ui.tooling.preview.Preview
1514
import androidx.compose.ui.unit.dp
@@ -103,7 +102,6 @@ fun MainConfigView(
103102
val iconBitmap = getIcon(
104103
entity?.icon,
105104
entity?.domain ?: "light",
106-
LocalContext.current,
107105
)
108106
Button(
109107
modifier = Modifier.fillMaxWidth(),

wear/src/main/kotlin/io/homeassistant/companion/android/home/views/MainView.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fun MainView(
9393
.fillMaxWidth(),
9494
icon = {
9595
Image(
96-
asset = getIcon(cached?.icon, favoriteEntityID.split(".")[0], context),
96+
asset = getIcon(cached?.icon, favoriteEntityID.split(".")[0]),
9797
colorFilter = ColorFilter.tint(wearColorScheme.onSurface),
9898
)
9999
},
@@ -257,7 +257,6 @@ fun MainView(
257257
getIcon(
258258
"",
259259
domain,
260-
context,
261260
).let { Image(asset = it) }
262261
},
263262
label = { Text(domainName) },

wear/src/main/kotlin/io/homeassistant/companion/android/home/views/SetShortcutsTileView.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.ui.Modifier
1010
import androidx.compose.ui.graphics.Color
1111
import androidx.compose.ui.graphics.ColorFilter
12-
import androidx.compose.ui.platform.LocalContext
1312
import androidx.compose.ui.res.stringResource
1413
import androidx.compose.ui.text.style.TextOverflow
1514
import androidx.compose.ui.tooling.preview.Preview
@@ -43,7 +42,6 @@ fun SetShortcutsTileView(shortcutEntities: List<SimplifiedEntity>, onShortcutEnt
4342
val iconBitmap = getIcon(
4443
shortcutEntities[index].icon,
4544
shortcutEntities[index].domain,
46-
LocalContext.current,
4745
)
4846

4947
Button(

wear/src/main/kotlin/io/homeassistant/companion/android/tiles/ShortcutsTile.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class ShortcutsTile : TileService() {
115115
val iconIIcon = getIcon(
116116
entity.icon,
117117
entity.domain,
118-
this@ShortcutsTile,
119118
)
120119
val iconBitmap = IconicsDrawable(this@ShortcutsTile, iconIIcon).apply {
121120
colorInt = Color.WHITE

wear/src/main/kotlin/io/homeassistant/companion/android/util/CommonFunctions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fun stringForDomain(domain: String, context: Context): String? = (
3030
)
3131
)[domain]?.let { context.getString(it) }
3232

33-
fun getIcon(icon: String?, domain: String, context: Context): IIcon {
33+
fun getIcon(icon: String?, domain: String): IIcon {
3434
val simpleEntity = Entity(
3535
"$domain.ha_android_placeholder",
3636
"",

0 commit comments

Comments
 (0)