Skip to content

Commit

Permalink
Change logging format
Browse files Browse the repository at this point in the history
  • Loading branch information
zim514 committed Jan 9, 2024
1 parent 67b578c commit 34e414d
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 159 deletions.
44 changes: 22 additions & 22 deletions script.service.hue/resources/lib/ambigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,58 +63,58 @@ def __init__(self, light_group_id, settings_monitor, bridge):
light = {L: {'gamut': gamut, 'prev_xy': (0, 0), "index": index}}
self.ambi_lights.update(light)
index = index + 1
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Lights: {self.ambi_lights}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Lights: {self.ambi_lights}")
# convert MS to seconds
if self.update_interval == 0:
self.update_interval = 0.1

def onAVStarted(self):
self.state = STATE_PLAYING
self.last_media_type = self._playback_type()
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] onPlaybackStarted. Group enabled: {self.enabled}, Bridge connected: {self.bridge.connected}, mediaType: {self.media_type}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] onPlaybackStarted. Group enabled: {self.enabled}, Bridge connected: {self.bridge.connected}, mediaType: {self.media_type}")

Check notice on line 74 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (196 \> 120 characters)

Check notice on line 74 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (196 \> 120 characters)

if not self.enabled or not self.bridge.connected:
return

xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] onPlaybackStarted. media_type: {self.media_type} == playback_type: {self._playback_type()}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] onPlaybackStarted. media_type: {self.media_type} == playback_type: {self._playback_type()}")

Check notice on line 79 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (165 \> 120 characters)

Check notice on line 79 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (165 \> 120 characters)
if self.media_type == self._playback_type() and self._playback_type() == VIDEO:
try:
self.video_info_tag = self.getVideoInfoTag()
except (AttributeError, TypeError) as x:
xbmc.log(f"[script.service.hue] AmbiGroup{self.light_group_id}: OnAV Started: Can't read infoTag")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup{self.light_group_id}: OnAV Started: Can't read infoTag")
reporting.process_exception(x)
else:
self.video_info_tag = None

if self.activation_check.validate():
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Running Play action")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Running Play action")

# Start the Ambi loop
ambi_loop_thread = Thread(target=self._ambi_loop, name="_ambi_loop", daemon=True)
ambi_loop_thread.start()

def onPlayBackStopped(self):
# always stop ambilight even if group is disabled or it'll run forever
xbmc.log(f"[script.service.hue] In ambiGroup[{self.light_group_id}], onPlaybackStopped()")
xbmc.log(f"[SCRIPT.SERVICE.HUE] In ambiGroup[{self.light_group_id}], onPlaybackStopped()")
self.state = STATE_STOPPED
AMBI_RUNNING.clear()

def onPlayBackPaused(self):
# always stop ambilight even if group is disabled or it'll run forever
xbmc.log(f"[script.service.hue] In ambiGroup[{self.light_group_id}], onPlaybackPaused()")
xbmc.log(f"[SCRIPT.SERVICE.HUE] In ambiGroup[{self.light_group_id}], onPlaybackPaused()")
self.state = STATE_PAUSED
AMBI_RUNNING.clear()

def _ambi_loop(self):
AMBI_RUNNING.set()
cap = xbmc.RenderCapture()
cap_image = bytes
xbmc.log("[script.service.hue] _ambiLoop started")
xbmc.log("[SCRIPT.SERVICE.HUE] _ambiLoop started")
aspect_ratio = cap.getAspectRatio()

self.capture_size_y = int(self.capture_size_x / aspect_ratio)
expected_capture_size = self.capture_size_x * self.capture_size_y * 4 # size * 4 bytes - RGBA
xbmc.log(f"[script.service.hue] aspect_ratio: {aspect_ratio}, Capture Size: ({self.capture_size_x},{self.capture_size_y}), expected_capture_size: {expected_capture_size}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] aspect_ratio: {aspect_ratio}, Capture Size: ({self.capture_size_x},{self.capture_size_y}), expected_capture_size: {expected_capture_size}")

Check notice on line 117 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (179 \> 120 characters)

Check notice on line 117 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (179 \> 120 characters)

cap.capture(self.capture_size_x, self.capture_size_y) # start the capture process https://github.com/xbmc/xbmc/pull/8613#issuecomment-165699101

Check notice on line 119 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (152 \> 120 characters)

Check notice on line 119 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (152 \> 120 characters)

Expand All @@ -127,14 +127,14 @@ def _ambi_loop(self):
cap_image = cap.getImage() # timeout to wait for OS in ms, default 1000

if cap_image is None or len(cap_image) < expected_capture_size:
xbmc.log("[script.service.hue] capImage is none or < expected. captured: {}, expected: {}".format(len(cap_image), expected_capture_size))
xbmc.log("[SCRIPT.SERVICE.HUE] capImage is none or < expected. captured: {}, expected: {}".format(len(cap_image), expected_capture_size))

Check notice on line 130 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (157 \> 120 characters)

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

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Expected type 'Sized', got 'None' instead

Check notice on line 130 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (157 \> 120 characters)

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

View workflow job for this annotation

GitHub Actions / Qodana for Python

Incorrect type

Expected type 'Sized', got 'None' instead
self.settings_monitor.waitForAbort(0.25) # pause before trying again
continue # no image captured, try again next iteration
image = Image.frombytes("RGBA", (self.capture_size_x, self.capture_size_y), bytes(cap_image), "raw", "BGRA", 0, 1) # Kodi always returns a BGRA image.

Check notice on line 133 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (167 \> 120 characters)

Check notice on line 133 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (167 \> 120 characters)

except ValueError:
xbmc.log(f"[script.service.hue] capImage: {len(cap_image)}")
xbmc.log("[script.service.hue] Value Error")
xbmc.log(f"[SCRIPT.SERVICE.HUE] capImage: {len(cap_image)}")
xbmc.log("[SCRIPT.SERVICE.HUE] Value Error")
self.settings_monitor.waitForAbort(0.25)
continue # returned capture is smaller than expected, but this happens when player is stopping so fail silently. give up this loop.

Check notice on line 139 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (148 \> 120 characters)

Check notice on line 139 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (148 \> 120 characters)

Expand All @@ -147,9 +147,9 @@ def _ambi_loop(self):

if not self.settings_monitor.abortRequested(): # ignore writing average process time if Kodi is shutting down
average_process_time = self._perf_average(PROCESS_TIMES)
xbmc.log(f"[script.service.hue] Average process time: {average_process_time}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Average process time: {average_process_time}")
ADDON.setSettingString("average_process_time", str(average_process_time))
xbmc.log("[script.service.hue] _ambiLoop stopped")
xbmc.log("[SCRIPT.SERVICE.HUE] _ambiLoop stopped")

def _update_hue_rgb(self, r, g, b, light, bri):
gamut = self.ambi_lights[light].get('gamut')
Expand Down Expand Up @@ -189,22 +189,22 @@ def _update_hue_rgb(self, r, g, b, light, bri):
if response is not None:
self.ambi_lights[light].update(prev_xy=xy)
elif response == 429 or response == 500:
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] _update_hue_rgb: {response}: Too Many Requests. Aborting request.")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] _update_hue_rgb: {response}: Too Many Requests. Aborting request.")

Check notice on line 192 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (148 \> 120 characters)

Check notice on line 192 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (148 \> 120 characters)
self.bridge_capacity_error()
notification(_("Hue Service"), _("Bridge overloaded, stopping ambilight"), icon=xbmcgui.NOTIFICATION_ERROR)

Check notice on line 194 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (123 \> 120 characters)

Check notice on line 194 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (123 \> 120 characters)
elif response == 404:
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Not Found")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Not Found")
AMBI_RUNNING.clear()
notification(header=_("Hue Service"), message=_(f"ERROR: Light not found, it may have been deleted"), icon=xbmcgui.NOTIFICATION_ERROR)

Check notice on line 198 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (150 \> 120 characters)

Check notice on line 198 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (150 \> 120 characters)
AMBI_RUNNING.clear() # shut it down
else:
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] RequestException Hue call fail")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] RequestException Hue call fail")
AMBI_RUNNING.clear() # shut it down
reporting.process_exception(response)

def bridge_capacity_error(self):
self.capacity_error_count = self.capacity_error_count + 1 # increment counter
xbmc.log(f"[script.service.hue] AmbiGroup[{self.light_group_id}] Bridge capacity error count: {self.capacity_error_count}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] AmbiGroup[{self.light_group_id}] Bridge capacity error count: {self.capacity_error_count}")

Check notice on line 207 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (131 \> 120 characters)

Check notice on line 207 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (131 \> 120 characters)
if self.capacity_error_count > 50 and self.settings_monitor.show500errors:
AMBI_RUNNING.clear() # shut it down
stop_showing_error = xbmcgui.Dialog().yesno(_("Hue Bridge over capacity"), _("The Hue Bridge is over capacity. Increase refresh rate or reduce the number of Ambilights."), yeslabel=_("Do not show again"), nolabel=_("Ok"))

Check notice on line 210 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (233 \> 120 characters)

Check notice on line 210 in script.service.hue/resources/lib/ambigroup.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (233 \> 120 characters)
Expand All @@ -217,7 +217,7 @@ def _get_light_gamut(bridge, light):
gamut = "C" # default
light_data = bridge.make_api_request("GET", f"light/{light}")
if light_data == 404:
xbmc.log(f"[script.service.hue] _get_light_gamut: Light[{light}] not found or ID invalid")
xbmc.log(f"[SCRIPT.SERVICE.HUE] _get_light_gamut: Light[{light}] not found or ID invalid")
return 404
elif light_data is not None and 'data' in light_data:
for item in light_data['data']:
Expand Down Expand Up @@ -255,7 +255,7 @@ def _get_and_save_light_states(self):
}
return states
else:
xbmc.log(f"[script.service.hue] Failed to get light states.")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Failed to get light states.")
return None

def _resume_all_light_states(self, states):
Expand All @@ -275,6 +275,6 @@ def _resume_all_light_states(self, states):
data["color_temperature"] = {"mirek": state['color_temperature']}
response = self.bridge.make_api_request('PUT', f'lights/{light_id}', json=data)
if response is not None:
xbmc.log(f"[script.service.hue] Light[{light_id}] state resumed successfully.")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Light[{light_id}] state resumed successfully.")
else:
xbmc.log(f"[script.service.hue] Failed to resume Light[{light_id}] state.")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Failed to resume Light[{light_id}] state.")
30 changes: 15 additions & 15 deletions script.service.hue/resources/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,40 @@ def __init__(self, settings_monitor):
}

def handle_command(self, command, *args):
xbmc.log(f"[script.service.hue] Started with {command}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Started with {command}")
command_func = self.commands.get(command)

if command_func:
command_func(*args)
else:
xbmc.log(f"[script.service.hue] Unknown command: {command}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Unknown command: {command}")
raise RuntimeError(f"Unknown Command: {command}")

def discover(self):
bridge = Hue(self.settings_monitor, discover=True)
if bridge.connected:
xbmc.log("[script.service.hue] Found bridge. Opening settings.")
xbmc.log("[SCRIPT.SERVICE.HUE] Found bridge. Opening settings.")
ADDON.openSettings()

else:
xbmc.log("[script.service.hue] No bridge found. Opening settings.")
xbmc.log("[SCRIPT.SERVICE.HUE] No bridge found. Opening settings.")
ADDON.openSettings()

def scene_select(self, light_group, action):
xbmc.log(f"[script.service.hue] sceneSelect: light_group: {light_group}, action: {action}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] sceneSelect: light_group: {light_group}, action: {action}")
bridge = Hue(self.settings_monitor)
if bridge.connected:
bridge.configure_scene(light_group, action)
else:
xbmc.log("[script.service.hue] No bridge found. sceneSelect cancelled.")
xbmc.log("[SCRIPT.SERVICE.HUE] No bridge found. sceneSelect cancelled.")
notification(_("Hue Service"), _("Check Hue Bridge configuration"))

def ambi_light_select(self, light_group):
bridge = Hue(self.settings_monitor)
if bridge.connected:
bridge.configure_ambilights(light_group)
else:
xbmc.log("[script.service.hue] No bridge found. Select ambi lights cancelled.")
xbmc.log("[SCRIPT.SERVICE.HUE] No bridge found. Select ambi lights cancelled.")
notification(_("Hue Service"), _("Check Hue Bridge configuration"))


Expand Down Expand Up @@ -130,7 +130,7 @@ def run(self):
if self.settings_monitor.waitForAbort(1):
break

xbmc.log("[script.service.hue] Abort requested...")
xbmc.log("[SCRIPT.SERVICE.HUE] Abort requested...")

def initialize_light_groups(self):
# Initialize light groups
Expand All @@ -142,7 +142,7 @@ def initialize_light_groups(self):

def activate(self):
# Activates play action as appropriate for all groups. Used at sunset and when service is re-enabled via Actions.

Check notice on line 144 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (121 \> 120 characters)

Check notice on line 144 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (121 \> 120 characters)
xbmc.log(f"[script.service.hue] Activating scenes")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Activating scenes")

for g in self.light_groups:
if ADDON.getSettingBool(f"group{g.light_group_id}_enabled"):
Expand All @@ -156,7 +156,7 @@ def _process_actions(self):
if action:
action_action = action[0]
action_light_group_id = int(action[1]) - 1
xbmc.log(f"[script.service.hue] Action command: {action}, action_action: {action_action}, action_light_group_id: {action_light_group_id}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Action command: {action}, action_action: {action_action}, action_light_group_id: {action_light_group_id}")

Check notice on line 159 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (150 \> 120 characters)

Check notice on line 159 in script.service.hue/resources/lib/core.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 coding style violation

PEP 8: E501 line too long (150 \> 120 characters)

# Run the action
self.light_groups[action_light_group_id].run_action(action_action)
Expand Down Expand Up @@ -185,10 +185,10 @@ def stop(self):
def _run_morning(self):
cache_set("daytime", True)
self.bridge.update_sunset()
xbmc.log(f"[script.service.hue] run_morning(): new sunset: {self.bridge.sunset}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] run_morning(): new sunset: {self.bridge.sunset}")

def _run_sunset(self):
xbmc.log(f"[script.service.hue] in run_sunset(): Sunset. ")
xbmc.log(f"[SCRIPT.SERVICE.HUE] in run_sunset(): Sunset. ")
cache_set("daytime", False)
self.hue_service.activate()

Expand All @@ -213,18 +213,18 @@ def _task_loop(self):
if time_to_sunset <= 0 or time_to_sunset > time_to_morning:

# Morning is next
xbmc.log(f"[script.service.hue] Timers: Morning is next. wait_time: {time_to_morning}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Timers: Morning is next. wait_time: {time_to_morning}")
if self.settings_monitor.waitForAbort(time_to_morning):
break
self._run_morning()

else:
# Sunset is next
xbmc.log(f"[script.service.hue] Timers: Sunset is next. wait_time: {time_to_sunset}")
xbmc.log(f"[SCRIPT.SERVICE.HUE] Timers: Sunset is next. wait_time: {time_to_sunset}")
if self.settings_monitor.waitForAbort(time_to_sunset):
break
self._run_sunset()
xbmc.log("[script.service.hue] Timers stopped")
xbmc.log("[SCRIPT.SERVICE.HUE] Timers stopped")

@staticmethod
def _time_until(current, target):
Expand Down
Loading

0 comments on commit 34e414d

Please sign in to comment.