package com.cvte.dss.ups.u3hub.hub;

import android.content.Context;
import android.util.Log;
import com.cvte.dss.ups.u3hub.listener.OnUpgradeResultListener;
import com.cvte.dss.ups.u3hub.model.UpgradeResult;
import java.io.File;
import java.util.Objects;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.jvm.internal.o;
import o.a.e.a;
import o.a.g.b;
import o.a.h.e.a.d;
import o.a.h.e.a.g;

/* JADX INFO: loaded from: classes.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000J\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\u0018\u0000 \u001e2\u00020\u0001:\u0002\u001e\u001fB\u000f\u0012\u0006\u0010\u001b\u001a\u00020\u001a¢\u0006\u0004\b\u001c\u0010\u001dJ'\u0010\t\u001a\u00020\b2\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0007\u001a\u00020\u0006H\u0016¢\u0006\u0004\b\t\u0010\nJ\u001f\u0010\t\u001a\u00020\u000b2\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004H\u0016¢\u0006\u0004\b\t\u0010\fJ\u0019\u0010\r\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0003\u001a\u00020\u0002H\u0016¢\u0006\u0004\b\r\u0010\u000eJ\u0015\u0010\u0010\u001a\u00020\u000f2\u0006\u0010\u0003\u001a\u00020\u0002¢\u0006\u0004\b\u0010\u0010\u0011J\u000f\u0010\u0012\u001a\u00020\bH\u0016¢\u0006\u0004\b\u0012\u0010\u0013R\u0016\u0010\u0015\u001a\u00020\u00148\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0015\u0010\u0016R\u0016\u0010\u0018\u001a\u00020\u00178\u0002@\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0018\u0010\u0019¨\u0006 "}, d2 = {"Lcom/cvte/dss/ups/u3hub/hub/SingleHubDeviceManager;", "Lcom/cvte/dss/ups/u3hub/hub/BaseDevice;", "Landroid/content/Context;", "context", "", "path", "Lcom/cvte/dss/ups/u3hub/listener/OnUpgradeResultListener;", "onUpgradeResultListener", "", "upgrade", "(Landroid/content/Context;Ljava/lang/String;Lcom/cvte/dss/ups/u3hub/listener/OnUpgradeResultListener;)V", "Lcom/cvte/dss/ups/u3hub/model/UpgradeResult;", "(Landroid/content/Context;Ljava/lang/String;)Lcom/cvte/dss/ups/u3hub/model/UpgradeResult;", "getVersion", "(Landroid/content/Context;)Ljava/lang/String;", "", "getDeviceNum", "(Landroid/content/Context;)I", "destroy", "()V", "Lo/a/e/a;", "mCompositeDisposable", "Lo/a/e/a;", "Lcom/cvte/dss/ups/u3hub/hub/SingleHubUpgradeApi;", "hubApi", "Lcom/cvte/dss/ups/u3hub/hub/SingleHubUpgradeApi;", "Lcom/cvte/dss/ups/u3hub/hub/SingleHubDeviceManager$HubType;", "type", "<init>", "(Lcom/cvte/dss/ups/u3hub/hub/SingleHubDeviceManager$HubType;)V", "Companion", "HubType", "lib_release"}, k = 1, mv = {1, 4, 0})
public final class SingleHubDeviceManager extends BaseDevice {
    public static final String TAG = "SingleHubDeviceManager";
    private final SingleHubUpgradeApi hubApi;
    private final a mCompositeDisposable;

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0010\n\u0002\b\u0006\b\u0086\u0001\u0018\u00002\b\u0012\u0004\u0012\u00020\u00000\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003j\u0002\b\u0004j\u0002\b\u0005j\u0002\b\u0006¨\u0006\u0007"}, d2 = {"Lcom/cvte/dss/ups/u3hub/hub/SingleHubDeviceManager$HubType;", "", "<init>", "(Ljava/lang/String;I)V", "TYPE_SINGLE_817", "TYPE_SINGLE_211", "TYPE_SINGLE_7817", "lib_release"}, k = 1, mv = {1, 4, 0})
    public enum HubType {
        TYPE_SINGLE_817,
        TYPE_SINGLE_211,
        TYPE_SINGLE_7817
    }

    @Metadata(bv = {1, 0, 3}, d1 = {}, d2 = {}, k = 3, mv = {1, 4, 0})
    public final /* synthetic */ class WhenMappings {
        public static final /* synthetic */ int[] $EnumSwitchMapping$0;

        static {
            HubType.values();
            int[] iArr = new int[3];
            $EnumSwitchMapping$0 = iArr;
            iArr[HubType.TYPE_SINGLE_817.ordinal()] = 1;
            iArr[HubType.TYPE_SINGLE_211.ordinal()] = 2;
            iArr[HubType.TYPE_SINGLE_7817.ordinal()] = 3;
        }
    }

    public SingleHubDeviceManager(HubType hubType) {
        SingleHubUpgradeApi instance;
        o.g(hubType, "type");
        this.mCompositeDisposable = new a();
        int iOrdinal = hubType.ordinal();
        if (iOrdinal == 0) {
            instance = SingleHubUpgradeApi.INSTANCE.getINSTANCE();
        } else if (iOrdinal == 1) {
            instance = HubVL211UpgradeApi.INSTANCE.getINSTANCE();
        } else {
            if (iOrdinal != 2) {
                throw new NoWhenBranchMatchedException();
            }
            instance = HubVL7817UpgradeApi.INSTANCE.getINSTANCE();
        }
        this.hubApi = instance;
    }

    @Override // com.cvte.dss.ups.u3hub.hub.BaseDevice
    public void destroy() {
        this.mCompositeDisposable.f();
    }

    public final int getDeviceNum(Context context) {
        o.g(context, "context");
        return this.hubApi.getDeviceNum(context);
    }

    @Override // com.cvte.dss.ups.u3hub.hub.BaseDevice
    public String getVersion(Context context) {
        o.g(context, "context");
        String version = this.hubApi.getVersion(context);
        if (version == null || version.length() == 0) {
            return null;
        }
        return version;
    }

    @Override // com.cvte.dss.ups.u3hub.hub.BaseDevice
    public UpgradeResult upgrade(Context context, String path) {
        o.g(context, "context");
        o.g(path, "path");
        if (new File(path).exists()) {
            return this.hubApi.startUpgrade(context, path) ? UpgradeResult.SUCCESS : UpgradeResult.UNKNOWN_ERROR;
        }
        g.a.a.a.a.g0(path, "not exists", TAG);
        return UpgradeResult.PATH_ERROR;
    }

    @Override // com.cvte.dss.ups.u3hub.hub.BaseDevice
    public void upgrade(final Context context, final String path, final OnUpgradeResultListener onUpgradeResultListener) {
        o.g(context, "context");
        o.g(path, "path");
        o.g(onUpgradeResultListener, "onUpgradeResultListener");
        Boolean bool = Boolean.TRUE;
        Objects.requireNonNull(bool, "item is null");
        d dVar = new d(bool);
        o.a.d dVar2 = o.a.i.a.f6107b;
        Objects.requireNonNull(dVar2, "scheduler is null");
        this.mCompositeDisposable.c(new g(dVar, dVar2).a(new b<Boolean>() { // from class: com.cvte.dss.ups.u3hub.hub.SingleHubDeviceManager$upgrade$disposable$1
            @Override // o.a.g.b
            public final void accept(Boolean bool2) {
                onUpgradeResultListener.onUpgradeResult(this.this$0.upgrade(context, path));
            }
        }).d(new b<Boolean>() { // from class: com.cvte.dss.ups.u3hub.hub.SingleHubDeviceManager$upgrade$disposable$2
            @Override // o.a.g.b
            public final void accept(Boolean bool2) {
            }
        }, new b<Throwable>() { // from class: com.cvte.dss.ups.u3hub.hub.SingleHubDeviceManager$upgrade$disposable$3
            @Override // o.a.g.b
            public final void accept(Throwable th) {
                Log.e(SingleHubDeviceManager.TAG, "upgrade error", th);
                onUpgradeResultListener.onUpgradeResult(UpgradeResult.UNKNOWN_ERROR);
            }
        }));
    }
}
