test = "SettingsCommand{trackingInterval=5, gpsInterval=5, gpsInitialFix=false, encryptionEnabled=true, noSleep=true, include_altitude=false, battery_reporting=true, automatic_tracking=false, connection_mode=Bluetooth, log_type=BluetoothLog, log_type_bitmask=1, sent_timestamp=1738704970, sat_disabled=OptionalBoolFalse, led_disabled=OptionalBoolFalse, radio_mode=RadioModeEnabled, include_speed_and_course=OptionalBoolFalse, button_1=ButtonFunctionSensor, low_speed_frequency_hz=925750000, high_speed_frequency_hz=905250000, radio_power_mode=PowerModeHigh, swap_radios=OptionalBoolFalse, sent_by_user_id=0, backhaul_enabled=OptionalBoolFalse, haptics_disabled=OptionalBoolFalse, low_data_mode_enabled=OptionalBoolFalse, ble_adv_device_name_disabled=OptionalBoolFalse, location_backhaul_rate=0}"


def parse_settings(payload):
    """ long term lets get the protos in here but until then lets use this hack job"""
    if payload is None:
        print("Settings Payload is None")
        return None
    settings = payload.split("SettingsCommand{")[1].split("}")[0]
    settings = settings.split(", ")
    settings_dict = {}
    for setting in settings:
        # print(f"Parsing settings: {setting}")
        ary = setting.split("=")
        key, value = ary[0], ary[1]
        if 'OptionalBool' in value:
            value = value.split('OptionalBool')[1]
            if value == 'True':
                value = True
            else:
                value = False
        settings_dict[key] = value

    return settings_dict


info_test = "InfoCommand{firmwareVersion=3.26.3, imei=301434060029310, trackingOn=true, serial=NGBBLRXC7171, battery=0, hardware_flavor=HardwareFlavorPC02, firmware_flavor=FirmwareFlavorBase, network_core_version=3.0.0, has_line_in_capability=true}"


def parse_info_command(payload):
    if payload is None:
        print("Info Payload is None")
        return None
    info = payload.split("{")[1].split("}")[0]
    info = info.split(", ")
    info_dict = {}
    for i in info:
        if "=" not in i:
            continue
        key, value = i.split("=")
        info_dict[key] = value

    return info_dict


info = parse_info_command(info_test)

print(info)