Unverified Commit 81bb802b authored by Vassilis Panos's avatar Vassilis Panos Committed by GitHub
Browse files

Update media_player.py

parent 1aee7a28
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ from . import Helper

_LOGGER = logging.getLogger(__name__)

VERSION = '1.1.0'
VERSION = '1.1.1'

DEFAULT_NAME = "SmartIR Media Player"

@@ -45,13 +45,33 @@ async def async_setup_platform(hass, config, async_add_devices, discovery_info=N
    power_sensor = config.get(CONF_POWER_SENSOR)

    abspath = os.path.dirname(os.path.abspath(__file__))
    device_json_file = "{}/codes/media_player/{}.json".format(abspath, device_code)
    device_files_subdir = os.path.join('codes', 'media_player')
    device_files_path = os.path.join(abspath, device_files_subdir)

    if not os.path.exists(device_json_file):
        _LOGGER.error("The device JSON file was not found. [%s]", device_json_file)
    if not os.path.isdir(device_files_path):
        os.makedirs(device_files_path)

    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_path, device_json_filename)

    if not os.path.exists(device_json_path):
        _LOGGER.warning("Couldn't find the device Json file. The component will " \
                        "try to download it from the GitHub repo.")

        try:
            codes_source = ("https://raw.githubusercontent.com/"
                            "smartHomeHub/SmartIR/master/smartir/"
                            "codes/media_player/{}.json")

            Helper.downloader(codes_source.format(device_code), device_json_path)
        except:
            _LOGGER.error("There was an error while downloading the device Json file. " \
                          "Please check your internet connection or the device code " \
                          "exists on GitHub. If the problem still exists please " \
                          "place the file manually in the proper location.")
            return

    with open(device_json_file) as j:
    with open(device_json_path) as j:
        try:
            device_data = json.load(j)
        except: