Skip to content
This repository has been archived by the owner on Jul 23, 2018. It is now read-only.

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
* Removed the need for a serperate sensor file (#14)

* Removed the need for a serperate sensor file (#16)

Removed the need for a serperate sensor file

* Added support for cards from https://github.com/custom-cards/ (#17)

* Version bump
  • Loading branch information
ludeeus committed Jul 22, 2018
1 parent e35a7e5 commit dbbdaa0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 24 additions & 8 deletions custom_components/custom_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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."""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand All @@ -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

0 comments on commit dbbdaa0

Please sign in to comment.