custom_components/smartir/climate.py
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the IR Climate platform."""
    device_code = config.get(CONF_DEVICE_CODE)
    device_files_subdir = os.path.join('codes', 'climate')
    device_files_absdir = os.path.join(COMPONENT_ABS_DIR, device_files_subdir)

    if not os.path.isdir(device_files_absdir):
        os.makedirs(device_files_absdir)

    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_absdir, 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/"
                            "kolyanu4/SmartIR/master/"
                            "codes/climate/{}.json")

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

    with open(device_json_path) as j:
        try:
            device_data = json.load(j)
        except Exception:
            _LOGGER.error("The device Json file is invalid")
            return

    async_add_entities([SmartIRClimate(hass, config, device_data)])
Set up the IR Climate platform.
Set up the IR Climate platform.
Set up the IR Climate platform .
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    device_code = config.get(CONF_DEVICE_CODE)
    device_files_subdir = os.path.join('codes', 'climate')
    device_files_absdir = os.path.join(COMPONENT_ABS_DIR, device_files_subdir)
    if not os.path.isdir(device_files_absdir):
        os.makedirs(device_files_absdir)
    device_json_filename = str(device_code) + '.json'
    device_json_path = os.path.join(device_files_absdir, 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/"
                            "kolyanu4/SmartIR/master/"
                            "codes/climate/{}.json")
            await Helper.downloader(codes_source.format(device_code), device_json_path)
        except Exception:
            _LOGGER.error("There was an error while downloading the device Json file. "
                          "Please check your internet connection or if the device code "
                          "exists on GitHub. If the problem still exists please "
                          "place the file manually in the proper directory.")
            return
    with open(device_json_path) as j:
        try:
            device_data = json.load(j)
        except Exception:
            _LOGGER.error("The device Json file is invalid")
            return
    async_add_entities([SmartIRClimate(hass, config, device_data)])
async def async_setup_platform ( hass , config , async_add_entities , discovery_info = None ) : device_code = config . get ( CONF_DEVICE_CODE ) device_files_subdir = os . path . join ( 'codes' , 'climate' ) device_files_absdir = os . path . join ( COMPONENT_ABS_DIR , device_files_subdir ) if not os . path . isdir ( device_files_absdir ) : os . makedirs ( device_files_absdir ) device_json_filename = str ( device_code ) + '.json' device_json_path = os . path . join ( device_files_absdir , 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/" "kolyanu4/SmartIR/master/" "codes/climate/{}.json" ) await Helper . downloader ( codes_source . format ( device_code ) , device_json_path ) except Exception : _LOGGER . error ( "There was an error while downloading the device Json file. " "Please check your internet connection or if the device code " "exists on GitHub. If the problem still exists please " "place the file manually in the proper directory." ) return with open ( device_json_path ) as j : try : device_data = json . load ( j ) except Exception : _LOGGER . error ( "The device Json file is invalid" ) return async_add_entities ( [ SmartIRClimate ( hass , config , device_data ) ] )
Set up the IR Climate platform.
Set up the IR Climate platform .
"""Set up the IR Climate platform."""
hass
config
async_add_entities
discovery_info