diff --git a/README.md b/README.md index 5f1ed20..18e31e9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ A component which allows you to update your custom_cards automatically and monit To get the best use for this card, use together with [tracker-card](https://github.com/ciotlosm/custom-lovelace/tree/master/tracker-card)\ **To use this card you can _NOT_ set `hide_sensor` to `true`** -⚠️ For now this wil ONLY work if your cards if from https://github.com/ciotlosm/custom-lovelace +⚠️ This wil ONLY work if your cards if from: + +- https://github.com/ciotlosm/custom-lovelace +- https://github.com/custom-cards ## Installation diff --git a/custom_components/custom_cards.py b/custom_components/custom_cards.py index 255972f..d51e406 100644 --- a/custom_components/custom_cards.py +++ b/custom_components/custom_cards.py @@ -13,7 +13,8 @@ import requests from homeassistant.helpers.event import track_time_interval -__version__ = '2.0.0' +__version__ = '2.1.0' + DOMAIN = 'custom_cards' DATA_CC = 'custom_cards_data' @@ -27,6 +28,8 @@ BROWSE_REPO = 'https//github.com/ciotlosm/custom-lovelace/master/' VISIT_REPO = 'https://github.com/ciotlosm/custom-lovelace/blob/master/%s/changelog.md' BASE_REPO = 'https://raw.githubusercontent.com/ciotlosm/custom-lovelace/master/' +VERSION_URL = 'https://raw.githubusercontent.com/custom-cards/information/master/repos.json' + def setup(hass, config): """Set up the component.""" @@ -112,11 +115,13 @@ def update_single(self, card, card_dir=None): def download_card(self, card, card_dir): """Downloading new card""" _LOGGER.debug('Downloading new version of %s', card) - downloadurl = BASE_REPO + card + '/' + card + '.js' - response = requests.get(downloadurl) + response = requests.get(VERSION_URL) if response.status_code == 200: - with open(self.conf_dir + card_dir + card + '.js', 'wb') as card_file: - card_file.write(response.content) + downloadurl = response.json()[card]['remote_location'] + download = requests.get(downloadurl) + if download.status_code == 200: + with open(self.conf_dir + card_dir + card + '.js', 'wb') as card_file: + card_file.write(download.content) def update_resource_version(self, card): """Updating the ui-lovelace file""" @@ -165,10 +170,9 @@ def get_card_dir(self, card): def get_remote_version(self, card): """Return the remote version if any.""" - remoteversion = BASE_REPO + card + '/VERSION' - response = requests.get(remoteversion) + response = requests.get(VERSION_URL) if response.status_code == 200: - remoteversion = response.text.strip() + remoteversion = response.json()[card]['version'] _LOGGER.debug('Remote version of %s is %s', card, remoteversion) else: _LOGGER.debug('Could not get the remote version for %s', card) @@ -189,3 +193,15 @@ def get_local_version(self, card): return localversion _LOGGER.debug('Could not get the local version for %s', card) return False + + def get_cards(self): + """Get all available cards""" + cards = [] + response = requests.get(VERSION_URL) + if response.status_code == 200: + for card in response.json(): + cards.append(card) + else: + _LOGGER.debug('Could not reach the remote repo') + _LOGGER.debug(cards) + return cards