// do something on state changes private static void HandleStateChange(TeslaState _oldState, TeslaState _newState) { Logfile.Log("change TeslaLogger state: " + _oldState.ToString() + " -> " + _newState.ToString()); DBHelper.currentJSON.CreateCurrentJSON(); // any -> Start if (_oldState != TeslaState.Start && _newState == TeslaState.Start) { webhelper.SetLastShiftState("P"); // reset shift state to default "P" } // charging -> any if (_oldState == TeslaState.Charge && _newState != TeslaState.Charge) { ResetHighFrequencyLogging(); } // sleeping -> any if (_oldState == TeslaState.Sleep && _newState != TeslaState.Sleep) { DBHelper.currentJSON.current_falling_asleep = false; DBHelper.currentJSON.CreateCurrentJSON(); } // any -> charging if (_oldState != TeslaState.Charge && _newState == TeslaState.Charge) { Address addr = WebHelper.geofence.GetPOI(DBHelper.currentJSON.latitude, DBHelper.currentJSON.longitude, false); if (addr != null && addr.specialFlags != null && addr.specialFlags.Count > 0) { foreach (KeyValuePair <Address.SpecialFlags, string> flag in addr.specialFlags) { switch (flag.Key) { case Address.SpecialFlags.OpenChargePort: break; case Address.SpecialFlags.HighFrequencyLogging: HandleSpecialFlag_HighFrequencyLogging(flag.Value); break; case Address.SpecialFlags.EnableSentryMode: break; case Address.SpecialFlags.SetChargeLimit: HandleSpecialFlag_SetChargeLimit(addr, flag.Value); break; case Address.SpecialFlags.ClimateOff: break; default: Logfile.Log("handleShiftStateChange unhandled special flag " + flag.ToString()); break; } } } } }