From 9571fcbf11ef5fbc2dbfab32131305ccc98e4983 Mon Sep 17 00:00:00 2001 From: zim514 Date: Sat, 30 Dec 2023 11:40:09 -0500 Subject: [PATCH] Add geolocation not configured logging --- .github/workflows/increment-version.yml | 60 ------------------- script.service.hue/addon.xml | 2 +- script.service.hue/resources/lib/hue.py | 5 ++ script.service.hue/resources/lib/reporting.py | 17 ++++-- 4 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/increment-version.yml diff --git a/.github/workflows/increment-version.yml b/.github/workflows/increment-version.yml deleted file mode 100644 index 695b3a38..00000000 --- a/.github/workflows/increment-version.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Increment version when languages are updated - -on: - push: - branches: [ main ] - paths: - - '**resource.language.**strings.po' - - -jobs: - default: - if: github.repository == 'zim514/script.service.hue' - runs-on: ubuntu-latest - name: Increment add-on version when languages are updated - - steps: - - - name: Checkout Repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - path: ${{ github.event.repository.name }} - - - name: Checkout Scripts - uses: actions/checkout@v4 - with: - fetch-depth: 0 - repository: xbmc/weblate-supplementary-scripts - path: scripts - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.9' - - - name: Get changed files - uses: trilom/file-changes-action@v1.2.4 - - - name: Increment add-on version - run: | - python3 ../scripts/repo-resources/increment_version.py $HOME/files.json -n - working-directory: ${{ github.event.repository.name }} - - - name: Install dependencies - run: | - sudo apt-get install libxml2-utils xmlstarlet - - - name: Get required variables - id: required-variables - run: | - version=$(xmlstarlet fo -R "$(find . -name addon.xml)" | xmlstarlet sel -t -v 'string(/addon/@version)') - echo ::set-output name=version::$version - working-directory: ${{ github.event.repository.name }} - - - name: Commit - uses: stefanzweifel/git-auto-commit-action@v5 - with: - repository: ${{ github.event.repository.name }} - commit_message: Increment addon.xml version to ${{ steps.required-variables.outputs.version }} - add_options: '--all' \ No newline at end of file diff --git a/script.service.hue/addon.xml b/script.service.hue/addon.xml index 50a2baa3..e1cb5f38 100644 --- a/script.service.hue/addon.xml +++ b/script.service.hue/addon.xml @@ -1,4 +1,4 @@ - + diff --git a/script.service.hue/resources/lib/hue.py b/script.service.hue/resources/lib/hue.py index f0d25801..47104fcf 100644 --- a/script.service.hue/resources/lib/hue.py +++ b/script.service.hue/resources/lib/hue.py @@ -99,6 +99,7 @@ def make_api_request(self, method, resource, discovery=False, **kwargs): return 500 else: xbmc.log(f"[script.service.hue] v2 make_request: HTTPError: {x}\nResponse: {x.response.text}") + reporting.process_exception(f"Response: {x.response.text}, Exception: {x}", logging=True) return x.response.status_code except (Timeout, json.JSONDecodeError) as x: xbmc.log(f"[script.service.hue] v2 make_request: Timeout/JSONDecodeError: Response: {x.response.text}\n{x}") @@ -313,6 +314,10 @@ def update_sunset(self): geolocation = self.make_api_request("GET", "geolocation") # TODO: Support cases where geolocation is not configured on bridge. xbmc.log(f"[script.service.hue] v2 update_sunset(): geolocation: {geolocation}") sunset_str = self.search_dict(geolocation, "sunset_time") + if sunset_str is None: + reporting.process_exception(f"Sunset time not found in geolocation response: {geolocation}", logging=True) + return + self.sunset = convert_time(sunset_str) xbmc.log(f"[script.service.hue] v2 update_sunset(): sunset: {self.sunset}") diff --git a/script.service.hue/resources/lib/reporting.py b/script.service.hue/resources/lib/reporting.py index f305d440..af046618 100644 --- a/script.service.hue/resources/lib/reporting.py +++ b/script.service.hue/resources/lib/reporting.py @@ -17,16 +17,18 @@ from .language import get_string as _ -def process_exception(exc, level="critical", error=""): +def process_exception(exc, level="critical", error="", logging=False): xbmc.log(f"[script.service.hue] *** EXCEPTION ***: Type: {type(exc)},\n Exception: {exc},\n Error: {error},\n Traceback: {traceback.format_exc()}") + if ADDON.getSettingBool("error_reporting"): + if _error_report_dialog(exc): + _report_error(level, error, exc, logging) +''' if exc is RequestException: xbmc.log("[script.service.hue] RequestException, not reporting to rollbar") notification(_("Hue Service"), _("Connection Error"), icon=xbmcgui.NOTIFICATION_ERROR) else: - if ADDON.getSettingBool("error_reporting"): - if _error_report_dialog(exc): - _report_error(level, error, exc) +''' def _error_report_dialog(exc): @@ -38,7 +40,7 @@ def _error_report_dialog(exc): return response -def _report_error(level="critical", error="", exc=""): +def _report_error(level="critical", error="", exc="", logging=False): if any(val in ADDONVERSION for val in ["dev", "alpha", "beta"]): env = "dev" else: @@ -52,4 +54,7 @@ def _report_error(level="critical", error="", exc=""): 'exc': exc } rollbar.init(ROLLBAR_API_KEY, capture_ip=False, code_version="v" + ADDONVERSION, root=ADDONPATH, scrub_fields='bridgeUser, bridgeIP, bridge_user, bridge_ip, server.host', environment=env) - rollbar.report_exc_info(sys.exc_info(), extra_data=data, level=level) + if logging: + rollbar.report_message(exc, extra_data=data, level=level) + else: + rollbar.report_exc_info(sys.exc_info(), extra_data=data, level=level)