Skip to content

Commit

Permalink
Don't attempt connection when IP or Key are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
zim514 committed Jul 20, 2024
1 parent 115fb59 commit 3f205c4
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions script.service.hue/resources/lib/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,30 @@ def _discover_new_ip(self):

def connect(self):
log(f"[SCRIPT.SERVICE.HUE] v2 connect: ip: {self.settings_monitor.ip}, key: {self.settings_monitor.key}")
self.base_url = f"https://{self.settings_monitor.ip}/clip/v2/resource/"
self.session.headers.update({'hue-application-key': self.settings_monitor.key})

self.devices = self.make_api_request("GET", "device")
if self.devices is None:
if self.settings_monitor.ip and self.settings_monitor.key:
self.base_url = f"https://{self.settings_monitor.ip}/clip/v2/resource/"
self.session.headers.update({'hue-application-key': self.settings_monitor.key})

self.devices = self.make_api_request("GET", "device")
if self.devices is None:
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection attempts failed. Setting connected to False")
self.connected = False
return False

self.scene_data = self.make_api_request("GET", "scene")

self.bridge_id = self.get_device_by_archetype(self.devices, 'bridge_v2')

Check warning on line 141 in script.service.hue/resources/lib/hue.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Type 'int' doesn't have expected attribute '__getitem__'
if self._check_version():
self.connected = True
self.update_sunset()
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection successful")
return True
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection attempts failed. Setting connected to False")
self.connected = False
return False

self.scene_data = self.make_api_request("GET", "scene")

self.bridge_id = self.get_device_by_archetype(self.devices, 'bridge_v2')
if self._check_version():
self.connected = True
self.update_sunset()
log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection successful")
return True

log(f"[SCRIPT.SERVICE.HUE] v2 connect: Connection attempts failed. Setting connected to False")
self.connected = False
log("[SCRIPT.SERVICE.HUE] No bridge IP or user key provided. Bridge not configured.")
notification(_("Hue Service"), _("Bridge not configured"), icon=xbmcgui.NOTIFICATION_ERROR)
return False

def discover(self):
Expand Down

0 comments on commit 3f205c4

Please sign in to comment.