Browse Source

Update to 1.3.2

Vassilis Panos 7 năm trước cách đây
mục cha
commit
fbf5c51db6
1 tập tin đã thay đổi với 23 bổ sung và 17 xóa
  1. 23 17
      smartir/__init__.py

+ 23 - 17
smartir/__init__.py

@@ -16,42 +16,48 @@ from homeassistant.helpers.typing import ConfigType
 _LOGGER = logging.getLogger(__name__)
 
 DOMAIN = 'smartir'
-VERSION = '1.3.0'
+VERSION = '1.3.2'
 VERSION_URL = (
-    "https://raw.githubusercontent.com/smartHomeHub/SmartIR/master/version.json")
+    "https://raw.githubusercontent.com/"
+    "smartHomeHub/SmartIR/{}/version.json")
 REMOTE_BASE_DIR = (
-    "https://raw.githubusercontent.com/smartHomeHub/SmartIR/master/smartir/"
-)
+    "https://raw.githubusercontent.com/"
+    "smartHomeHub/SmartIR/{}/smartir/")
 CONF_CHECK_UPDATES = 'check_updates'
+CONF_UPDATE_BRANCH = 'update_branch'
 
 CONFIG_SCHEMA = vol.Schema({
     DOMAIN: vol.Schema({
-        vol.Optional(CONF_CHECK_UPDATES, default=True): cv.boolean
+        vol.Optional(CONF_CHECK_UPDATES, default=True): cv.boolean,
+        vol.Optional(CONF_UPDATE_BRANCH, default='master'): vol.In(
+            ['master', 'rc'])
     })
 }, extra=vol.ALLOW_EXTRA)
 
 async def async_setup(hass, config):
     """Set up the SmartIR component."""
     conf = config.get(DOMAIN)
+    check_updates = conf[CONF_CHECK_UPDATES]
+    update_branch = conf[CONF_UPDATE_BRANCH]
 
-    async def check_updates(service):
-        await _update(hass)
+    async def _check_updates(service):
+        await _update(hass, update_branch)
 
-    async def update_component(service):
-        await _update(hass, True)
+    async def _update_component(service):
+        await _update(hass, update_branch, True)
 
-    hass.services.async_register(DOMAIN, 'check_updates', check_updates)
-    hass.services.async_register(DOMAIN, 'update_component', update_component)
+    hass.services.async_register(DOMAIN, 'check_updates', _check_updates)
+    hass.services.async_register(DOMAIN, 'update_component', _update_component)
 
-    if conf[CONF_CHECK_UPDATES]:
-        await _update(hass, False, False)
+    if check_updates:
+        await _update(hass, update_branch, False, False)
 
     return True
 
-async def _update(hass, do_update=False, notify_if_latest=True):
+async def _update(hass, branch, do_update=False, notify_if_latest=True):
     has_errors = False
 
-    request = requests.get(VERSION_URL, stream=True, timeout=10)
+    request = requests.get(VERSION_URL.format(branch), stream=True, timeout=10)
     
     if request.status_code == 200:
         data = request.json()
@@ -62,7 +68,7 @@ async def _update(hass, do_update=False, notify_if_latest=True):
         if StrictVersion(last_version) <= StrictVersion(VERSION):
             if notify_if_latest:
                 hass.components.persistent_notification.async_create(
-                    "You're already using the latest version", title='SmartIR')
+                    "You're already using the latest version!", title='SmartIR')
             return
             
         if StrictVersion(current_ha_version) >= StrictVersion(min_ha_version):
@@ -72,7 +78,7 @@ async def _update(hass, do_update=False, notify_if_latest=True):
 
                 for file in files:
                     try:
-                        source = REMOTE_BASE_DIR + file
+                        source = REMOTE_BASE_DIR.format(branch) + file
                         dest = os.path.join(abspath, file)
                         os.makedirs(os.path.dirname(dest), exist_ok=True)
                         Helper.downloader(source, dest)