Skip to content

Commit d702ac3

Browse files
committed
refactor: rename mcu2_online_check to pre_online_check
The behavior of checking whether an apparent online state is a subsystem check or genuine wakeup may affect more vehicle types than just MCU2 upgrades. Rename the field and update comments/logs to be more general: - mcu2_online_check → pre_online_check - Comment now mentions 'some vehicles (especially MCU2-upgraded cars)' - Log messages remove 'MCU2' prefix for generality No behavior changes, pure rename refactor.
1 parent 959394a commit d702ac3

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

lib/teslamate/vehicles/vehicle.ex

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ defmodule TeslaMate.Vehicles.Vehicle do
2525
task: nil,
2626
import?: false,
2727
stream_pid: nil,
28-
# mcu2_online_check tracks whether an apparent online event for MCU2-upgraded cars is a real
29-
# wakeup or a brief subsystem check. These older cars wake briefly (~2-3 min) each hour for
30-
# subsystem checks and report online, but requesting vehicle_data causes a full wakeup (~15 min).
31-
# The distinguishing signal is the streaming API: power=nil means a subsystem check (fake online),
32-
# a numeric power value means a genuine wakeup (real online).
28+
# pre_online_check tracks whether an apparent online event is a real wakeup or a brief
29+
# subsystem check. Some vehicles (especially MCU2-upgraded cars) wake briefly (~2-3 min)
30+
# each hour for subsystem checks and report online, but requesting vehicle_data causes a
31+
# full wakeup (~15 min). The distinguishing signal is the streaming API: power=nil means
32+
# a subsystem check (fake online), a numeric power value means a genuine wakeup (real online).
3333
#
3434
# Values:
35-
# :idle – no MCU2 check in progress (default)
35+
# :idle – no pre-online check in progress (default)
3636
# :probing – stream connected, waiting for first power reading
3737
# :confirmed_fake – stream reported power=nil, treating as fake online
3838
# :confirmed_real – stream reported numeric power, treating as real online
39-
mcu2_online_check: :idle
39+
pre_online_check: :idle
4040
end
4141

4242
@asleep_interval 30
@@ -362,29 +362,29 @@ defmodule TeslaMate.Vehicles.Vehicle do
362362

363363
{:ok, pid} = connect_stream(data)
364364

365-
{:keep_state, %Data{data | stream_pid: pid, mcu2_online_check: :probing},
365+
{:keep_state, %Data{data | stream_pid: pid, pre_online_check: :probing},
366366
[broadcast_fetch(false), schedule_fetch(@asleep_interval, data)]}
367367

368368
{%CarSettings{use_streaming_api: true}, state, %Data{stream_pid: pid}}
369369
when state in [:asleep, :offline] and is_pid(pid) ->
370370
case data do
371-
%Data{mcu2_online_check: :probing} ->
371+
%Data{pre_online_check: :probing} ->
372372
# Under normal circumstances stream always give data within @asleep_interval (30s)
373373
# otherwise detect it here and allow vehicle_data in next fetch
374374
Logger.info("Stream connected, but nothing received, allow real online",
375375
car_id: data.car.id
376376
)
377377

378-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_real},
378+
{:keep_state, %Data{data | pre_online_check: :confirmed_real},
379379
[broadcast_fetch(false), schedule_fetch(0, data)]}
380380

381-
%Data{mcu2_online_check: :idle} ->
381+
%Data{pre_online_check: :idle} ->
382382
Logger.warning(
383-
"Stream connected, but mcu2_online_check is :idle, shouldn't be possible, allow real online",
383+
"Stream connected, but pre_online_check is :idle, shouldn't be possible, allow real online",
384384
car_id: data.car.id
385385
)
386386

387-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_real},
387+
{:keep_state, %Data{data | pre_online_check: :confirmed_real},
388388
[broadcast_fetch(false), schedule_fetch(0, data)]}
389389

390390
%Data{} ->
@@ -409,7 +409,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
409409
{:ok, pid} = connect_stream(data)
410410

411411
{:next_state, {:offline, @asleep_interval},
412-
%Data{data | stream_pid: pid, mcu2_online_check: :probing},
412+
%Data{data | stream_pid: pid, pre_online_check: :probing},
413413
[broadcast_fetch(false), schedule_fetch(@asleep_interval, data)]}
414414

415415
{%CarSettings{use_streaming_api: true}, _state, %Data{}} ->
@@ -436,7 +436,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
436436
%Data{data | last_response: last_response, geofence: geofence}
437437
end
438438

439-
{:keep_state, %Data{data | mcu2_online_check: :idle, stream_pid: nil},
439+
{:keep_state, %Data{data | pre_online_check: :idle, stream_pid: nil},
440440
[
441441
broadcast_fetch(false),
442442
{:next_event, :internal, {:update, {String.to_existing_atom(state), vehicle}}}
@@ -542,20 +542,20 @@ defmodule TeslaMate.Vehicles.Vehicle do
542542
# Transition to :confirmed_fake so the fetch fallback (if stream stalls) won't
543543
# re-trigger a confirmed_real promotion.
544544
case data do
545-
%Data{mcu2_online_check: :probing} ->
546-
Logger.info("MCU2 subsystem check: power is nil, treating as fake online",
545+
%Data{pre_online_check: :probing} ->
546+
Logger.info("Subsystem check detected: power is nil, treating as fake online",
547547
car_id: data.car.id
548548
)
549549

550-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_fake}}
550+
{:keep_state, %Data{data | pre_online_check: :confirmed_fake}}
551551

552-
%Data{mcu2_online_check: :idle} ->
552+
%Data{pre_online_check: :idle} ->
553553
Logger.warning(
554-
"MCU2 subsystem check: power is nil, but mcu2_online_check is :idle, shouldn't be possible, treating as fake online",
554+
"Subsystem check detected: power is nil, but pre_online_check is :idle, shouldn't be possible, treating as fake online",
555555
car_id: data.car.id
556556
)
557557

558-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_fake}}
558+
{:keep_state, %Data{data | pre_online_check: :confirmed_fake}}
559559

560560
%Data{} ->
561561
:keep_state_and_data
@@ -565,23 +565,23 @@ defmodule TeslaMate.Vehicles.Vehicle do
565565
Logger.debug(inspect(stream_data), car_id: data.car.id)
566566

567567
case data do
568-
%Data{mcu2_online_check: check} when check in [:probing, :confirmed_fake] ->
569-
Logger.info("MCU2 real online detected: power is a number", car_id: data.car.id)
568+
%Data{pre_online_check: check} when check in [:probing, :confirmed_fake] ->
569+
Logger.info("Real online detected: power is a number", car_id: data.car.id)
570570

571-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_real},
571+
{:keep_state, %Data{data | pre_online_check: :confirmed_real},
572572
schedule_fetch(0, data)}
573573

574-
%Data{mcu2_online_check: :idle} ->
574+
%Data{pre_online_check: :idle} ->
575575
Logger.warning(
576-
"MCU2 real online detected: power is a number, but mcu2_online_check is :idle, shouldn't be possible, treating as real online",
576+
"Real online detected: power is a number, but pre_online_check is :idle, shouldn't be possible, treating as real online",
577577
car_id: data.car.id
578578
)
579579

580-
{:keep_state, %Data{data | mcu2_online_check: :confirmed_real},
580+
{:keep_state, %Data{data | pre_online_check: :confirmed_real},
581581
schedule_fetch(0, data)}
582582

583583
%Data{} ->
584-
# mcu2_online_check already :confirmed_real — don't fetch again to avoid 'Fetch already in progress'
584+
# pre_online_check already :confirmed_real — don't fetch again to avoid 'Fetch already in progress'
585585
:keep_state_and_data
586586
end
587587

@@ -924,7 +924,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
924924
:ok = disconnect_stream(data)
925925

926926
{:next_state, {:asleep, asleep_interval()},
927-
%{data | last_state_change: last_state_change, stream_pid: nil, mcu2_online_check: :idle},
927+
%{data | last_state_change: last_state_change, stream_pid: nil, pre_online_check: :idle},
928928
[broadcast_summary(), schedule_fetch(data)]}
929929
end
930930

@@ -937,7 +937,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
937937
:ok = disconnect_stream(data)
938938

939939
{:next_state, {:offline, asleep_interval()},
940-
%{data | last_state_change: last_state_change, stream_pid: nil, mcu2_online_check: :idle},
940+
%{data | last_state_change: last_state_change, stream_pid: nil, pre_online_check: :idle},
941941
[broadcast_summary(), schedule_fetch(data)]}
942942
end
943943

@@ -1498,7 +1498,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
14981498

14991499
{state, _} when state in [:asleep, :offline] ->
15001500
case data do
1501-
%Data{mcu2_online_check: :confirmed_real} -> true
1501+
%Data{pre_online_check: :confirmed_real} -> true
15021502
%Data{} -> false
15031503
end
15041504

0 commit comments

Comments
 (0)