From 937852dc0e237b87d95a46ff29db632403e9bd87 Mon Sep 17 00:00:00 2001 From: Geert Meersman Date: Wed, 12 Apr 2023 20:10:10 +0200 Subject: [PATCH] Headers fixed in case of multiple accounts --- .github/PULL_REQUEST_TEMPLATE.md | 1 - .github/labels.yml | 6 ------ .pre-commit-config.yaml | 1 + custom_components/nexxtmove/client.py | 19 ++++++++++++++----- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e563e25..a515826 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,7 +18,6 @@ - [ ] **Breaking change** (fix or feature that would cause existing functionality to change) - [ ] **Enhancement** (changes that improvement of current feature or performance) - [ ] **Refactoring** (changes that neither fixes a bug nor adds a feature) -- [ ] **Test Case** (changes that add missing tests or correct existing tests) - [ ] **Code style optimization** (changes that do not affect the meaning of the code) - [ ] **Docs** (changes that only update documentation) - [ ] **Chore** (changes that don't modify src or test files) diff --git a/.github/labels.yml b/.github/labels.yml index f39d8a7..3964159 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -1,12 +1,6 @@ - name: fix description: A bug correction color: d3fc03 -- name: bug - description: Something isn't working - color: d73a4a -- name: feature - description: A new feature or request - color: a2eeef - name: enhancement description: A new feature or request color: a2eeef diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 511f9f0..8825f88 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,7 @@ repos: entry: flake8 language: system types: [python] + args: ["-j8", "--ignore=E501,W503"] require_serial: true - id: reorder-python-imports name: Reorder python imports diff --git a/custom_components/nexxtmove/client.py b/custom_components/nexxtmove/client.py index 41ed3ed..48b0ac7 100644 --- a/custom_components/nexxtmove/client.py +++ b/custom_components/nexxtmove/client.py @@ -32,11 +32,11 @@ def __init__( environment: NexxtmoveEnvironment = DEFAULT_NEXXTMOVE_ENVIRONMENT, ) -> None: """Initialize NexxtmoveClient.""" - self.session = session if session else Session() + self.session = Session() self.username = username self.password = password self.environment = environment - self.session.headers = headers + self._headers = headers self.profile = {} self.request_error = {} self.token = None @@ -54,10 +54,19 @@ def request( """Send a request to Nexxtmove.""" if data is None: log_debug(f"{caller} Calling GET {url}") - response = self.session.get(url, timeout=REQUEST_TIMEOUT) + response = self.session.get( + url, + timeout=REQUEST_TIMEOUT, + headers=self._headers | {"Authorize": f"Token {self.token}"}, + ) else: log_debug(f"{caller} Calling POST {url} with {data}") - response = self.session.post(url, json=data, timeout=REQUEST_TIMEOUT) + response = self.session.post( + url, + json=data, + timeout=REQUEST_TIMEOUT, + headers=self._headers | {"Authorize": f"Token {self.token}"}, + ) log_debug( f"{caller} http status code = {response.status_code} (expecting {expected})" ) @@ -102,7 +111,7 @@ def login(self) -> dict: result = response.json() try: self.token = result.get("authToken") - self.session.headers |= {"Authorize": f"Token {self.token}"} + log_debug(f"Setting Token {self.token}") self.profile = result.get("profile") except Exception as exception: raise BadCredentialsException(