Exemple #1
0
 def start_remote_control(self):
     if self.args.remote_disable:
         logger.info("mqtt disabled")
     elif not self.args.web_conf or path.isfile(OTP_CONFIG_NAME):
         if self.myp.remote_client.mqtt_client is not None:
             self.myp.remote_client.mqtt_client.disconnect()
         try:
             self.myp.remote_client.start()
             if self.args.charge_control:
                 Config.chc = ChargeControls.load_config(
                     self.myp, name=self.args.charge_control)
                 Config.chc.init()
                 self.myp.start_refresh_thread()
         except ConfigException:
             logger.error("start_remote_control failed redo otp config")
Exemple #2
0
# Psacc

psacc = MyPSACC(None, client_id, client_secret, REMOTE_REFRESH_TOKEN,
                customer_id, BRAND[package_name]["realm"], country_code)
psacc.connect(client_email, client_password)

os.chdir(current_dir)
psacc.save_config(name="test.json")
res = psacc.get_vehicles()

for vehicle in res_dict["vehicles"]:
    car = psacc.vehicles_list.get_car_by_vin(vehicle["vin"])
    if "short_label" in vehicle and car.label == "unknown":
        car.label = vehicle["short_label"].split(" ")[
            -1]  # remove new, nouvelle, neu word....
        car.set_energy_capacity()
    else:
        print("Warning: Can't get car model please check cars.json")
psacc.vehicles_list.save_cars()

print(f"\nYour vehicles: {res}")

# Charge control
charge_controls = ChargeControls("charge_config1.json")
for vehicle in res:
    chc = ChargeControl(psacc, vehicle.vin, 100, [0, 0])
    charge_controls[vehicle.vin] = chc
charge_controls.save_config()

print("Success !!!")
Exemple #3
0
    else:
        try:
            web.app.myp.refresh_token()
        except OAuthError:
            if args.mail and args.password:
                client_email = args.mail
                client_password = args.password
            else:
                client_email = input(f"{web.app.myp.get_app_name()} email: ")
                client_password = getpass(f"{web.app.myp.get_app_name()} password: "******"mqtt disabled")
        else:
            web.app.myp.start_mqtt()
        if args.refresh or args.charge_control:
            if args.refresh:
                web.app.myp.info_refresh_rate = args.refresh * 60
            if args.charge_control:
                web.app.chc = ChargeControls.load_config(web.app.myp, name=args.charge_control)
                web.app.chc.init()
            t2 = Thread(target=web.app.myp.refresh_vehicle_info)
            t2.setDaemon(True)
            t2.start()

    save_config(web.app.myp, CONFIG_NAME)
    t1 = Thread(target=start_app, args=["My car info", args.base_path, logger.level < 20, args.listen, int(args.port)])
    t1.setDaemon(True)
    t1.start()
def firstLaunchConfig(
        package_name,
        client_email,
        client_password,
        country_code,  # pylint: disable=too-many-locals
        config_prefix=""):
    filename = package_name.split(".")[-1] + ".apk"
    apk_parser = get_content_from_apk(filename, country_code)

    try:
        res = requests.post(apk_parser.host_brandid_prod + "/GetAccessToken",
                            headers={
                                "Connection": "Keep-Alive",
                                "Content-Type": "application/json",
                                "User-Agent": "okhttp/2.3.0"
                            },
                            params={
                                "jsonRequest":
                                json.dumps({
                                    "siteCode": apk_parser.site_code,
                                    "culture": "fr-FR",
                                    "action": "authenticate",
                                    "fields": {
                                        "USR_EMAIL": {
                                            "value": client_email
                                        },
                                        "USR_PASSWORD": {
                                            "value": client_password
                                        }
                                    }
                                })
                            })

        token = res.json()["accessToken"]
    except Exception as ex:
        msg = traceback.format_exc() + f"\nHOST_BRANDID : {apk_parser.host_brandid_prod} " \
                                       f"sitecode: {apk_parser.site_code}"
        try:
            msg += res.text
        except:  # pylint: disable=bare-except
            pass
        logger.error(msg)
        raise Exception(msg) from ex
    try:
        res2 = requests.post(
            f"https://mw-{BRAND[package_name]['brand_code'].lower()}-m2c.mym.awsmpsa.com/api/v1/user",
            params={
                "culture": apk_parser.culture,
                "width": 1080,
                "version": APP_VERSION
            },
            data=json.dumps({
                "site_code": apk_parser.site_code,
                "ticket": token
            }),
            headers={
                "Connection": "Keep-Alive",
                "Content-Type": "application/json;charset=UTF-8",
                "Source-Agent": "App-Android",
                "Token": token,
                "User-Agent": "okhttp/4.8.0",
                "Version": APP_VERSION
            },
            cert=("certs/public.pem", "certs/private.pem"),
        )

        res_dict = res2.json()["success"]
        customer_id = BRAND[package_name]["brand_code"] + "-" + res_dict["id"]
    except Exception as ex:
        msg = traceback.format_exc()
        try:
            msg += res2.text
        except:  # pylint: disable=bare-except
            pass
        logger.error(msg)
        raise Exception(msg) from ex
    # Psacc
    psacc = MyPSACC(None, apk_parser.client_id, apk_parser.client_secret, None,
                    customer_id, BRAND[package_name]["realm"], country_code)
    psacc.connect(client_email, client_password)
    psacc.save_config(name=config_prefix + "config.json")
    res = psacc.get_vehicles()

    if len(res) == 0:
        Exception(
            "No vehicle in your account is compatible with this API, you vehicle is probably too old..."
        )

    for vehicle in res_dict["vehicles"]:
        car = psacc.vehicles_list.get_car_by_vin(vehicle["vin"])
        if car is not None and "short_label" in vehicle and car.label == "unknown":
            car.label = vehicle["short_label"].split(" ")[
                -1]  # remove new, nouvelle, neu word....
    psacc.vehicles_list.save_cars()

    logger.info("\nYour vehicles: %s", res)

    # Charge control
    charge_controls = ChargeControls(config_prefix + "charge_config.json")
    for vehicle in res:
        chc = ChargeControl(psacc, vehicle.vin, 100, [0, 0])
        charge_controls[vehicle.vin] = chc
    charge_controls.save_config()
    return "Success !!!"
 def test_charge_control(self):
     charge_control = ChargeControls()
     charge_control.file_name = "test_charge_control.json"
     charge_control.save_config(force=True)