Skip to content

Commit f0841e8

Browse files
committed
Format wheel types with optional suffixes
1 parent d81441c commit f0841e8

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

lib/teslamate/mqtt/pubsub/home_assistant.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,17 @@ defmodule TeslaMate.Mqtt.PubSub.HomeAssistant do
185185
defp format_model(model), do: model
186186

187187
defp format_wheel_type(wheel_type) do
188-
case Regex.named_captures(~r/^(?<name>[A-Za-z]+)(?<size>\d+)$/, wheel_type) do
189-
%{"name" => name, "size" => size} -> "#{split_camel_case(name)} #{size}\""
190-
nil -> split_camel_case(wheel_type)
188+
case Regex.named_captures(
189+
~r/^(?<name>[A-Za-z]+)(?<size>\d+)(?<suffix>[A-Za-z]*)$/,
190+
wheel_type
191+
) do
192+
%{"name" => name, "size" => size, "suffix" => suffix} ->
193+
[split_camel_case(name), "#{size}\"", split_camel_case(suffix)]
194+
|> Enum.reject(&(&1 == ""))
195+
|> Enum.join(" ")
196+
197+
nil ->
198+
split_camel_case(wheel_type)
191199
end
192200
end
193201

test/teslamate/mqtt/pubsub/home_assistant_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ defmodule TeslaMate.Mqtt.PubSub.HomeAssistantTest do
135135
assert decoded["device"]["model"] == "Model 3 Long Range (Induction Wheels)"
136136
end
137137

138+
test "formats wheel types with optional suffixes" do
139+
wheel_types = [
140+
{"AeroTurbine19", ~s|Aero Turbine 19" Wheels|},
141+
{"Pinwheel18", ~s|Pinwheel 18" Wheels|},
142+
{"Slipstream19Carbon", ~s|Slipstream 19" Carbon Wheels|}
143+
]
144+
145+
for {wheel_type, expected} <- wheel_types do
146+
device = HomeAssistant.device(%{@summary | wheel_type: wheel_type}, car_id: 0)
147+
assert device.model == "Model 3 (#{expected})"
148+
end
149+
end
150+
138151
test "device name falls back to car.name when display_name is nil", %{test: name} do
139152
publisher_name = start_publisher(name)
140153

0 commit comments

Comments
 (0)