Skip to content

Commit f9113f6

Browse files
authored
Fix CarPlay garage icon (home-assistant#3560)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent d795dcc commit f9113f6

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

Sources/CarPlay/Templates/Entities/CarPlayEntityListItem.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ final class CarPlayEntityListItem: CarPlayListItemProvider {
1111
var template: CPListItem
1212
weak var interfaceController: CPInterfaceController?
1313

14+
/// Whether the entity has a dynamic icon that changes based on state
15+
private var entityHasDynamicIcon: Bool {
16+
guard let entityDomain = Domain(entityId: entity.entityId) else { return false }
17+
return [.cover, .inputBoolean, .light, .switch].contains(entityDomain)
18+
}
19+
1420
init(
1521
serverId: String,
1622
entity: HAEntity,
@@ -34,14 +40,16 @@ final class CarPlayEntityListItem: CarPlayListItemProvider {
3440
if let magicItem, let magicItemInfo {
3541
displayText = magicItem.name(info: magicItemInfo)
3642

37-
var iconColor: UIColor?
38-
if let iconColorString = magicItem.customization?.iconColor {
39-
iconColor = UIColor(hex: iconColorString)
43+
if !entityHasDynamicIcon {
44+
var iconColor: UIColor?
45+
if let iconColorString = magicItem.customization?.iconColor {
46+
iconColor = UIColor(hex: iconColorString)
47+
}
48+
image = magicItem.icon(info: magicItemInfo).carPlayIcon(color: iconColor)
4049
}
41-
image = magicItem.icon(info: magicItemInfo).carPlayIcon(color: iconColor)
4250
}
4351
template.setText(displayText)
44-
template.setDetailText(entity.localizedState)
52+
template.setDetailText(entity.localizedState.leadingCapitalized)
4553
template.setImage(image)
4654
}
4755
}

Sources/Shared/Common/Extensions/String+HA.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public extension String {
1818
}
1919
return first.uppercased() + dropFirst()
2020
}
21+
22+
var leadingCapitalized: String {
23+
guard let first else {
24+
return self
25+
}
26+
return first.uppercased() + dropFirst()
27+
}
2128
}
2229

2330
public extension String? {

Sources/Shared/HAEntity+CarPlay.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,19 @@ public extension HAEntity {
122122
}
123123

124124
private func getCoverIcon() -> MaterialDesignIcons {
125-
let state = state
126-
127125
guard let state = Domain.State(rawValue: state) else { return MaterialDesignIcons.bookmarkIcon }
128126

129127
switch deviceClass {
130128
case .garage:
131129
switch state {
132-
case .opening: return MaterialDesignIcons.arrowUpBoxIcon
133-
case .closing: return MaterialDesignIcons.arrowDownBoxIcon
134-
case .closed: return MaterialDesignIcons.garageIcon
135-
default: return MaterialDesignIcons.garageOpenIcon
130+
case .opening:
131+
return MaterialDesignIcons.arrowUpBoxIcon
132+
case .closing:
133+
return MaterialDesignIcons.arrowDownBoxIcon
134+
case .closed:
135+
return MaterialDesignIcons.garageIcon
136+
default:
137+
return MaterialDesignIcons.garageOpenIcon
136138
}
137139
case .gate:
138140
switch state {

0 commit comments

Comments
 (0)