From e35a7e5fbb394ac17a9e58bc2cf2da04d7aa728a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sun, 22 Jul 2018 17:54:18 +0200 Subject: [PATCH] Removed the need for a serperate sensor file Removed the need for a serperate sensor file --- .github/CODEOWNERS | 1 + .github/settings.yml | 10 +++---- README.md | 13 +--------- custom_components/custom_cards.py | 43 ++++++------------------------- 4 files changed, 15 insertions(+), 52 deletions(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b609384 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @ludeeus \ No newline at end of file diff --git a/.github/settings.yml b/.github/settings.yml index 9227fef..6b75ccc 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -10,14 +10,14 @@ repository: allow_rebase_merge: false labels: - name: "Feature Request" - color: fbca04 + color: "fbca04" - name: "Bug" - color: d73a4a + color: "b60205" - name: "Wont Fix" - color: ffffff + color: "ffffff" - name: "Enhancement" color: a2eeef - name: "Documentation" - color: 008672 + color: "008672" - name: "Stale" - color: 930191 \ No newline at end of file + color: "930191" \ No newline at end of file diff --git a/README.md b/README.md index 39f0be3..5f1ed20 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,7 @@ To get the best use for this card, use together with [tracker-card](https://gith To get started put `/custom_components/custom_cards.py` here: `/custom_components/custom_cards.py` -## Configuration - -| key | default | required | description -| --- | --- | --- | --- -| **hide_sensor** | False | no | Download and register the sensor used by the [tracker-card](https://github.com/ciotlosm/custom-lovelace/tree/master/tracker-card), can be `True`/`False` - -☢️ It is strongly adviced to not have this auto update - -## Example +## Example configuration In your `configuration.yaml`: @@ -29,8 +21,6 @@ In your `configuration.yaml`: custom_cards: ``` -ℹ️ The sensor will get discovered automatically if installation was done correctly. - ## Debug logging In your `configuration.yaml` @@ -40,7 +30,6 @@ logger: default: warn logs: custom_components.custom_cards: debug - custom_components.sensor.custom_cards: debug ``` ## Update single card diff --git a/custom_components/custom_cards.py b/custom_components/custom_cards.py index a77c6b7..255972f 100644 --- a/custom_components/custom_cards.py +++ b/custom_components/custom_cards.py @@ -8,37 +8,25 @@ import os import subprocess from datetime import timedelta +import time import requests -import voluptuous as vol -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import track_time_interval -from homeassistant.helpers.discovery import load_platform -from homeassistant.helpers.dispatcher import async_dispatcher_send -__version__ = '1.1.14' +__version__ = '2.0.0' DOMAIN = 'custom_cards' DATA_CC = 'custom_cards_data' -CONF_HIDE_SENSOR = 'hide_sensor' -SIGNAL_SENSOR_UPDATE = 'custom_cards_update' ATTR_CARD = 'card' INTERVAL = timedelta(days=1) -CONFIG_SCHEMA = vol.Schema({ - DOMAIN: vol.Schema({ - vol.Optional(CONF_HIDE_SENSOR, default=False): cv.boolean, - }) -}, extra=vol.ALLOW_EXTRA) - _LOGGER = logging.getLogger(__name__) 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/' -SENSOR_URL = 'https://raw.githubusercontent.com/custom-components/sensor.custom_cards/master/custom_components/sensor/custom_cards.py' def setup(hass, config): """Set up the component.""" @@ -47,7 +35,6 @@ def setup(hass, config): __version__, __name__.split('.')[1]) conf_dir = str(hass.config.path()) controller = CustomCards(hass, conf_dir) - hide_sensor = config[DOMAIN][CONF_HIDE_SENSOR] def update_all_service(call): """Set up service for manual trigger.""" @@ -64,23 +51,6 @@ def update_single_service(call): DOMAIN, 'update_single', update_single_service) hass.services.register( DOMAIN, 'check_all', controller.cache_versions) - if not hide_sensor: - sensor_dir = str(hass.config.path("custom_components/sensor/")) - sensor_file = 'custom_cards.py' - sensor_full_path = sensor_dir + sensor_file - if not os.path.isfile(sensor_full_path): - _LOGGER.debug('Could not find %s in %s, trying to download.', sensor_file, sensor_dir) - response = requests.get(SENSOR_URL) - if response.status_code == 200: - _LOGGER.debug('Checking folder structure') - directory = os.path.dirname(sensor_dir) - if not os.path.exists(directory): - os.makedirs(directory) - with open(sensor_full_path, 'wb+') as sensorfile: - sensorfile.write(response.content) - else: - _LOGGER.critical('Failed to download sensor from %s', SENSOR_URL) - load_platform(hass, 'sensor', DOMAIN) return True @@ -93,7 +63,7 @@ def __init__(self, hass, conf_dir): self.hass.data[DATA_CC] = {} self.cache_versions(None) # Force a cache update on startup - def cache_versions(self, time): + def cache_versions(self, call): """Cache""" self.cards = self.get_installed_cards() self.hass.data[DATA_CC] = {} # Empty list to start from scratch @@ -102,14 +72,17 @@ def cache_versions(self, time): localversion = self.get_local_version(card[0]) remoteversion = self.get_remote_version(card[0]) has_update = (localversion != False and remoteversion != False and remoteversion != localversion) + not_local = (remoteversion != False and not localversion) self.hass.data[DATA_CC][card[0]] = { "local": localversion, "remote": remoteversion, "has_update": has_update, + "not_local": not_local, } self.hass.data[DATA_CC]['domain'] = DOMAIN self.hass.data[DATA_CC]['repo'] = VISIT_REPO - async_dispatcher_send(self.hass, SIGNAL_SENSOR_UPDATE) + self.hass.states.set('sensor.custom_card_tracker', time.time(), self.hass.data[DATA_CC]) + def update_all(self): """Update all cards""" @@ -130,7 +103,7 @@ def update_single(self, card, card_dir=None): _LOGGER.info('Upgrade of %s from version %s to version %s complete', card, self.hass.data[DATA_CC][card]['local'], self.hass.data[DATA_CC][card]['remote']) self.hass.data[DATA_CC][card]['local'] = self.hass.data[DATA_CC][card]['remote'] self.hass.data[DATA_CC][card]['has_update'] = False - async_dispatcher_send(self.hass, SIGNAL_SENSOR_UPDATE) + self.hass.states.set('sensor.custom_card_tracker', time.time(), self.hass.data[DATA_CC]) else: _LOGGER.debug('Skipping upgrade for %s, no update available', card) else: