Skip to content

Commit

Permalink
Allow configuration of IKEA update url (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adminiuga committed Sep 30, 2020
1 parent a1010cb commit a9f1537
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions zigpy/config/__init__.py
Expand Up @@ -36,6 +36,7 @@
CONF_OTA = "ota"
CONF_OTA_DIR = "otau_directory"
CONF_OTA_IKEA = "ikea_provider"
CONF_OTA_IKEA_URL = "ikea_update_url"
CONF_OTA_LEDVANCE = "ledvance_provider"
CONF_TOPO_SCAN_PERIOD = "topology_scan_period"

Expand Down Expand Up @@ -72,6 +73,7 @@
SCHEMA_OTA = {
vol.Optional(CONF_OTA_DIR, default=CONF_OTA_OTAU_DIR_DEFAULT): vol.Any(None, str),
vol.Optional(CONF_OTA_IKEA, default=CONF_OTA_IKEA_DEFAULT): cv_boolean,
vol.Optional(CONF_OTA_IKEA_URL): vol.Url(),
vol.Optional(CONF_OTA_LEDVANCE, default=CONF_OTA_LEDVANCE_DEFAULT): cv_boolean,
}

Expand Down
7 changes: 5 additions & 2 deletions zigpy/ota/provider.py
Expand Up @@ -11,7 +11,7 @@
import aiohttp
import attr

from zigpy.config import CONF_OTA_DIR
from zigpy.config import CONF_OTA_DIR, CONF_OTA_IKEA_URL
from zigpy.ota.image import ImageKey, OTAImage, OTAImageHeader
import zigpy.util

Expand All @@ -29,6 +29,7 @@ class Basic(zigpy.util.LocalLogMixin, ABC):
REFRESH = datetime.timedelta(hours=12)

def __init__(self):
self.config = {}
self._cache = {}
self._is_enabled = False
self._locks = defaultdict(asyncio.Semaphore)
Expand Down Expand Up @@ -145,6 +146,7 @@ class Trådfri(Basic):

async def initialize_provider(self, ota_config: Dict) -> None:
self.info("OTA provider enabled")
self.config = ota_config
await self.refresh_firmware_list()
self.enable()

Expand All @@ -154,7 +156,8 @@ async def refresh_firmware_list(self) -> None:

async with self._locks[LOCK_REFRESH]:
async with aiohttp.ClientSession(headers=self.HEADERS) as req:
async with req.get(self.UPDATE_URL) as rsp:
url = self.config.get(CONF_OTA_IKEA_URL, self.UPDATE_URL)
async with req.get(url) as rsp:
# IKEA does not always respond with an appropriate Content-Type
# but the response is always JSON
if not (200 <= rsp.status <= 299):
Expand Down

0 comments on commit a9f1537

Please sign in to comment.