Unverified Commit 11af7f19 authored by Vassilis Panos's avatar Vassilis Panos Committed by GitHub
Browse files

Update climate.py

parent 2712a2d2
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ from . import Helper

_LOGGER = logging.getLogger(__name__)

VERSION = '1.1.0'
VERSION = '1.1.1'

DEFAULT_NAME = "SmartIR Climate"

@@ -65,17 +65,37 @@ 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/climate/{}.json".format(abspath, device_code)
    device_files_subdir = os.path.join('codes', 'climate')
    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/climate/{}.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:
            _LOGGER.error("The device JSON file is invalid")
            _LOGGER.error("The device Json file is invalid")
            return

    async_add_devices([SmartIRClimate(