refactor: replace fake_online_state integer with typed mcu2_online_ch…#5245
Conversation
|
This PR was entirely done with AI (opencode). So check it carefully. So far, looks OK to me. It also changed some of the log messages, which was a bit weird, but those changes good to me. |
…eck atom The integer values 0/1/2/3 were undocumented magic numbers that required reading multiple comments to understand. Replace with a self-documenting atom enum: :idle – no MCU2 check in progress (was: 0) :probing – stream connected, awaiting first power reading (was: 1) :confirmed_fake – stream reported power=nil, subsystem wakeup (was: 2) :confirmed_real – stream reported numeric power, genuine wakeup (was: 3) No behaviour changes.
cfdf652 to
9b4557f
Compare
Elixir's gradual type checker lost track of the %Data{} struct type in
three places after a with expression reassignment and one function head.
Add explicit %Data{} = pattern matches so the type system can verify the
struct updates at the two with sites, and annotate the streaming handler's
data parameter directly in its function head.
|
I think failing Elixir tests is standard feature of this branch. Will work on fixing that after these expected 4 PRs. This PR probably should be squashed and merged. |
Indeed it is :) The whole concept of connecting the Stream and messing with the states during online has made quite some negative impact on the tests :( I'm happy that some work is planned to get this closer to main. Much better with the enum 👍 If the plan is to still keep it that way, could we go with a more generic name? Maybe |
|
Happy to change it to pre_online_check. Will wait maybe a day and ensure everyone is happy with that before making the change. |
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.
6134ed8 to
d702ac3
Compare
|
Never mind, I just made the change. |
|
Let me know when you have it ready to test out. My time with a MCU2 car is coming to an end as a replacement has arrived. |
|
Now that is is merged into the mcu2-upgraded-cars branch, which should get built using. ghcr.io/teslamate-org/teslamate:pr-4453 In theory nothing has changed with this PR (and subsequent PRs I am working on also like #5259 ), this is just refactoring of code, which should have the same exact behavior. |
#5245) * refactor: replace fake_online_state integer with typed mcu2_online_check atom The integer values 0/1/2/3 were undocumented magic numbers that required reading multiple comments to understand. Replace with a self-documenting atom enum: :idle – no MCU2 check in progress (was: 0) :probing – stream connected, awaiting first power reading (was: 1) :confirmed_fake – stream reported power=nil, subsystem wakeup (was: 2) :confirmed_real – stream reported numeric power, genuine wakeup (was: 3) No behaviour changes.
#5245) * refactor: replace fake_online_state integer with typed mcu2_online_check atom The integer values 0/1/2/3 were undocumented magic numbers that required reading multiple comments to understand. Replace with a self-documenting atom enum: :idle – no MCU2 check in progress (was: 0) :probing – stream connected, awaiting first power reading (was: 1) :confirmed_fake – stream reported power=nil, subsystem wakeup (was: 2) :confirmed_real – stream reported numeric power, genuine wakeup (was: 3) No behaviour changes.
Summary
The
fake_online_statefield inVehicle.Dataused integer values 0–3 as magic numbers to track whether an apparent online event for MCU2-upgraded cars was a genuine wakeup or a brief subsystem check. The meaning of each value required reading multiple comments and mentally mapping integers to states.This PR replaces it with a self-documenting atom enum field
mcu2_online_check:fake_online_state)mcu2_online_check)0:idle1:probing2:confirmed_fakepower=nil— subsystem wakeup only3:confirmed_realPart of a larger simplification effort
This is step 1 of a planned series of mechanical refactors to make
vehicle.exeasier to understand before merging the MCU2 logic intomain. Subsequent steps will:Data:startre-dispatch hub in favour of a direct private function