Browse Source

Fix the built-in updater

Vassilis Panos 7 years ago
parent
commit
20d47da799
3 changed files with 33 additions and 15 deletions
  1. 17 12
      custom_components/smartir/__init__.py
  2. 14 1
      custom_components/smartir/manifest.json
  3. 2 2
      version.json

+ 17 - 12
custom_components/smartir/__init__.py

@@ -16,13 +16,15 @@ from homeassistant.helpers.typing import ConfigType
 _LOGGER = logging.getLogger(__name__)
 _LOGGER = logging.getLogger(__name__)
 
 
 DOMAIN = 'smartir'
 DOMAIN = 'smartir'
-VERSION = '1.6.0'
-VERSION_URL = (
+VERSION = '1.6.1'
+MANIFEST_URL = (
     "https://raw.githubusercontent.com/"
     "https://raw.githubusercontent.com/"
-    "smartHomeHub/SmartIR/{}/version.json")
+    "smartHomeHub/SmartIR/{}/"
+    "custom_components/smartir/manifest.json")
 REMOTE_BASE_URL = (
 REMOTE_BASE_URL = (
     "https://raw.githubusercontent.com/"
     "https://raw.githubusercontent.com/"
-    "smartHomeHub/SmartIR/{}/smartir/")
+    "smartHomeHub/SmartIR/{}/"
+    "custom_components/smartir/")
 COMPONENT_ABS_DIR = os.path.dirname(
 COMPONENT_ABS_DIR = os.path.dirname(
     os.path.abspath(__file__))
     os.path.abspath(__file__))
 
 
@@ -63,7 +65,7 @@ async def async_setup(hass, config):
 
 
 async def _update(hass, branch, do_update=False, notify_if_latest=True):
 async def _update(hass, branch, do_update=False, notify_if_latest=True):
     try:
     try:
-        request = requests.get(VERSION_URL.format(branch), stream=True, timeout=10)
+        request = requests.get(MANIFEST_URL.format(branch), stream=True, timeout=10)
     except:
     except:
         _LOGGER.error("An error occurred while checking for updates. "
         _LOGGER.error("An error occurred while checking for updates. "
                       "Please check your internet connection.")
                       "Please check your internet connection.")
@@ -75,9 +77,9 @@ async def _update(hass, branch, do_update=False, notify_if_latest=True):
         return
         return
 
 
     data = request.json()
     data = request.json()
-    last_version = data['version']
-    min_ha_version = data['minHAVersion']
-    release_notes = data['releaseNotes']
+    min_ha_version = data['homeassistant']
+    last_version = data['updater']['version']
+    release_notes = data['updater']['releaseNotes']
 
 
     if StrictVersion(last_version) <= StrictVersion(VERSION):
     if StrictVersion(last_version) <= StrictVersion(VERSION):
         if notify_if_latest:
         if notify_if_latest:
@@ -87,17 +89,20 @@ async def _update(hass, branch, do_update=False, notify_if_latest=True):
 
 
     if StrictVersion(current_ha_version) < StrictVersion(min_ha_version):
     if StrictVersion(current_ha_version) < StrictVersion(min_ha_version):
         hass.components.persistent_notification.async_create(
         hass.components.persistent_notification.async_create(
-            "There is a new version of SmartIR, but it is **incompatible** "
-            "with your HA version. Please first update Home Assistant.", title='SmartIR')
+            "There is a new version of SmartIR integration, but it is **incompatible** "
+            "with your system. Please first update Home Assistant.", title='SmartIR')
         return
         return
 
 
     if do_update is False:
     if do_update is False:
         hass.components.persistent_notification.async_create(
         hass.components.persistent_notification.async_create(
-            release_notes, title='SmartIR')
+            "A new version of SmartIR integration is available ({}). "
+            "Call the ``smartir.update_component`` service to update "
+            "the integration. \n\n **Release notes:** \n{}"
+            .format(last_version, release_notes), title='SmartIR')
         return
         return
 
 
     # Begin update
     # Begin update
-    files = data['files']
+    files = data['updater']['files']
     has_errors = False
     has_errors = False
 
 
     for file in files:
     for file in files:

+ 14 - 1
custom_components/smartir/manifest.json

@@ -5,5 +5,18 @@
   "dependencies": [],
   "dependencies": [],
   "codeowners": ["@smartHomeHub"],
   "codeowners": ["@smartHomeHub"],
   "requirements": [],
   "requirements": [],
-  "homeassistant": "0.96.0b1"
+  "homeassistant": "0.96.0b1",
+  "updater": {
+    "version": "1.6.1",
+    "releaseNotes": "* Fix the built-in updater",
+    "files": [
+      "__init__.py",
+      "climate.py",
+      "media_player.py",
+      "fan.py",
+      "controller.py",
+      "manifest.json",
+      "services.yaml"
+    ]
+  }
 }
 }

+ 2 - 2
version.json

@@ -1,7 +1,7 @@
 {            
 {            
-    "version": "1.6.0",
+    "version": "1.6.1",
     "minHAVersion": "0.96.0b1",
     "minHAVersion": "0.96.0b1",
-    "releaseNotes": "A new version (1.6.0) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
+    "releaseNotes": "A new version (1.6.1) is available that is compatible with your system. Call the ``smartir.update_component`` service to update the component.",
     "files": [
     "files": [
         "__init__.py",
         "__init__.py",
         "climate.py",
         "climate.py",