<commit_before>/**
 * Copyright (c) 2010-2019 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.netatmo.internal.welcome;

import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.eclipse.smarthome.io.net.http.HttpUtil;
import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler;

import io.swagger.client.model.NAWelcomeCamera;

/**
 * {@link NAWelcomeCameraHandler} is the class used to handle the Welcome Camera Data
 *
 * @author Ing. <NAME> - Initial contribution
 *
 */
public class NAWelcomeCameraHandler extends NetatmoModuleHandler<NAWelcomeCamera> {
    private static final String LIVE_PICTURE = "/live/snapshot_720.jpg";
    private String livePictureURL;
    private String vpnUrl;
    private boolean isLocal = false;
    private String liveStreamURL;

    public NAWelcomeCameraHandler(@NonNull Thing thing) {
        super(thing);
    }

    @Override
    protected void updateProperties(NAWelcomeCamera moduleData) {
        updateProperties(null, moduleData.getType());
    }

    @SuppressWarnings("null")
    @Override
    protected State getNAThingProperty(String chanelId) {
        switch (chanelId) {
            case CHANNEL_WELCOME_CAMERA_STATUS:
                return module != null ? toOnOffType(module.getStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_SDSTATUS:
                return module != null ? toOnOffType(module.getSdStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_ALIMSTATUS:
                return module != null ? toOnOffType(module.getAlimStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_ISLOCAL:
                return (module == null || module.getIsLocal() == null) ? UnDefType.UNDEF
                        : module.getIsLocal() ? OnOffType.ON : OnOffType.OFF;
            case CHANNEL_WELCOME_CAMERA_LIVEPICTURE_URL:
                return getLivePictureURL() == null ? UnDefType.UNDEF : toStringType(getLivePictureURL());
            case CHANNEL_WELCOME_CAMERA_LIVEPICTURE:
                return getLivePictureURL() == null ? UnDefType.UNDEF : HttpUtil.downloadImage(getLivePictureURL());
            case CHANNEL_WELCOME_CAMERA_LIVESTREAM_URL:
                return getLiveStreamURL() == null ? UnDefType.UNDEF : new StringType(getLiveStreamURL());
        }
        return super.getNAThingProperty(chanelId);
    }

    /**
     * Get the url for the live snapshot
     *
     * @return Url of the live snapshot
     */
    @SuppressWarnings("null")
    private String getLivePictureURL() {
        if (livePictureURL == null && module != null && module.getVpnUrl() != null) {
            livePictureURL = module.getVpnUrl() + LIVE_PICTURE;
        }
        return livePictureURL;
    }

    /**
     * Get the url for the live stream depending wether local or not
     *
     * @return Url of the live stream
     */
    private String getLiveStreamURL() {
        if (liveStreamURL == null && module != null) {
            liveStreamURL = getVpnUrl();
            if (liveStreamURL != null) {
                liveStreamURL += "/live/index";
                liveStreamURL += isLocal ? "_local" : "";
                liveStreamURL += ".m3u8";
            }
        }
        return liveStreamURL;
    }

    @SuppressWarnings("null")
    private String getVpnUrl() {
        if (vpnUrl == null && module != null) {
            vpnUrl = module.getVpnUrl();
            if (vpnUrl != null) {
                isLocal = module.getIsLocal();
            }
        }
        return vpnUrl;
    }

    public String getStreamURL(String videoId) {
        String result = getVpnUrl();
        if (result != null) {
            result += "/vod/" + videoId + "/index";
            result += isLocal ? "_local" : "";
            result += ".m3u8";
        }
        return result;
    }

}<commit_msg>[netatmo] Recompute VPN URL (#5809)<commit_after>/**
 * Copyright (c) 2010-2019 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.netatmo.internal.welcome;

import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.eclipse.smarthome.io.net.http.HttpUtil;
import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler;

import io.swagger.client.model.NAWelcomeCamera;

/**
 * {@link NAWelcomeCameraHandler} is the class used to handle the Welcome Camera Data
 *
 * @author Ing. <NAME> - Initial contribution
 *
 */
public class NAWelcomeCameraHandler extends NetatmoModuleHandler<NAWelcomeCamera> {
    private static final String LIVE_PICTURE = "/live/snapshot_720.jpg";

    public NAWelcomeCameraHandler(@NonNull Thing thing) {
        super(thing);
    }

    @Override
    protected void updateProperties(NAWelcomeCamera moduleData) {
        updateProperties(null, moduleData.getType());
    }

    @SuppressWarnings("null")
    @Override
    protected State getNAThingProperty(String chanelId) {
        switch (chanelId) {
            case CHANNEL_WELCOME_CAMERA_STATUS:
                return module != null ? toOnOffType(module.getStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_SDSTATUS:
                return module != null ? toOnOffType(module.getSdStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_ALIMSTATUS:
                return module != null ? toOnOffType(module.getAlimStatus()) : UnDefType.UNDEF;
            case CHANNEL_WELCOME_CAMERA_ISLOCAL:
                return (module == null || module.getIsLocal() == null) ? UnDefType.UNDEF
                        : module.getIsLocal() ? OnOffType.ON : OnOffType.OFF;
            case CHANNEL_WELCOME_CAMERA_LIVEPICTURE_URL:
                return getLivePictureURL() == null ? UnDefType.UNDEF : toStringType(getLivePictureURL());
            case CHANNEL_WELCOME_CAMERA_LIVEPICTURE:
                return getLivePictureURL() == null ? UnDefType.UNDEF : HttpUtil.downloadImage(getLivePictureURL());
            case CHANNEL_WELCOME_CAMERA_LIVESTREAM_URL:
                return getLiveStreamURL() == null ? UnDefType.UNDEF : new StringType(getLiveStreamURL());
        }
        return super.getNAThingProperty(chanelId);
    }

    /**
     * Get the url for the live snapshot
     *
     * @return Url of the live snapshot
     */
    private String getLivePictureURL() {
        String result = getVpnUrl();
        if (result != null) {
            result += LIVE_PICTURE;
        }
        return result;
    }

    /**
     * Get the url for the live stream depending wether local or not
     *
     * @return Url of the live stream
     */
    private String getLiveStreamURL() {
        String result = getVpnUrl();
        if (result != null) {
            result += "/live/index";
            result += isLocal() ? "_local" : "";
            result += ".m3u8";
        }
        return result;
    }

    @SuppressWarnings("null")
    private String getVpnUrl() {
        return (module == null) ? null : module.getVpnUrl();
    }

    public String getStreamURL(String videoId) {
        String result = getVpnUrl();
        if (result != null) {
            result += "/vod/" + videoId + "/index";
            result += isLocal() ? "_local" : "";
            result += ".m3u8";
        }
        return result;
    }

    @SuppressWarnings("null")
    private boolean isLocal() {
        return (module == null || module.getIsLocal() == null) ? false : module.getIsLocal().booleanValue();
    }

}
{'fraction_non_alphanumeric': 0.10389757534556991, 'fraction_numerical': 0.005211874008610922, 'mean_word_length': 2.6994970662196143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3322718', 'n_tokens_mistral': 2667, 'n_tokens_neox': 2584, 'n_words': 578}