Repository: bimmerconnected/bimmer_connected
Pull request #231 (2020-11-03 19:58:22)

Create codeql-analysis.yml
<!--
  Thanks for your contribution to bimmer_connected!
-->

## Proposed change
https://securitylab.github.com/tools/codeql

## Type of change
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (which adds functionality to this library)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [x] Code quality improvements to existing code or addition of tests

## Additional information
<!--
  Details are important, and help maintainers processing your PR.
  Please be sure to fill out additional details, if applicable.
-->

- This PR fixes or closes issue: fixes #
- This PR is related to issue: 

## Checklist
<!--
  Put an `x` in the boxes that apply. You can also fill these out after
  creating the PR. If you're unsure about any of them, don't hesitate to ask.
  We're here to help! This is simply a reminder of what we are going to look
  for before merging your code.
-->

- [ ] The code change is tested and works locally.
- [ ] Tests have been added to verify that the new code works.



Patch:
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..3bbe902
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,60 @@
+name: "CodeQL"
+
+on:
+  push:
+    branches: [dev, master]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: [dev]
+
+jobs:
+  analyze:
+    name: Analyze
+    runs-on: ubuntu-latest
+
+    strategy:
+      fail-fast: false
+      matrix:
+        # Override automatic language detection by changing the below list
+        # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
+        language: ['python']
+        # Learn more...
+        # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
+
+    steps:
+    - name: Checkout repository
+      uses: actions/checkout@v2
+      with:
+        # We must fetch at least the immediate parents so that if this is
+        # a pull request then we can checkout the head.
+        fetch-depth: 2
+
+    # If this run was triggered by a pull request event, then checkout
+    # the head of the pull request instead of the merge commit.
+    - run: git checkout HEAD^2
+      if: ${{ github.event_name == 'pull_request' }}
+
+    # Initializes the CodeQL tools for scanning.
+    - name: Initialize CodeQL
+      uses: github/codeql-action/init@v1
+      with:
+        languages: ${{ matrix.language }}
+
+    # Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
+    # If this step fails, then you should remove it and run the build manually (see below)
+    - name: Autobuild
+      uses: github/codeql-action/autobuild@v1
+
+    # ℹ️ Command-line programs to run using the OS shell.
+    # 📚 https://git.io/JvXDl
+
+    # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+    #    and modify them (or add more) to build your code if your project
+    #    uses a compiled language
+
+    #- run: |
+    #   make bootstrap
+    #   make release
+
+    - name: Perform CodeQL Analysis
+      uses: github/codeql-action/analyze@v1
diff --git a/bimmer_connected/country_selector.py b/bimmer_connected/country_selector.py
index 3de9679..300d077 100644
--- a/bimmer_connected/country_selector.py
+++ b/bimmer_connected/country_selector.py
@@ -22,7 +22,7 @@ _SERVER_URLS = {
 
 #: Mapping from regions to servers
 _GCDM_OAUTH_ENDPOINTS = {
-    Regions.NORTH_AMERICA: 'customer.bmwgroup.com/gcdm/usa',
+    Regions.NORTH_AMERICA: 'b2vapi.bmwgroup.us/gcdm',
     Regions.REST_OF_WORLD: 'customer.bmwgroup.com/gcdm',
     Regions.CHINA: 'customer.bmwgroup.cn/gcdm'
 }
diff --git a/bimmer_connected/vehicle_status.py b/bimmer_connected/vehicle_status.py
index 19552ff..fae550c 100644
--- a/bimmer_connected/vehicle_status.py
+++ b/bimmer_connected/vehicle_status.py
@@ -136,13 +136,25 @@ class VehicleStatus:  # pylint: disable=too-many-public-methods
         Returns a tuple of (latitude, longitude).
         This only provides data, if the vehicle tracking is enabled!
         """
-        pos = self._state.attributes[SERVICE_STATUS]['position']
         if not self.is_vehicle_tracking_enabled:
-            _LOGGER.warning('Positioning status is %s', pos['status'])
+            _LOGGER.warning('Vehicle tracking is disabled')
             return None
         pos = self._state.attributes[SERVICE_STATUS]['position']
         return float(pos['lat']), float(pos['lon'])
 
+    @property
+    @backend_parameter
+    def gps_heading(self) -> (int):
+        """Get the last known heading of the vehicle.
+
+        This only provides data, if the vehicle tracking is enabled!
+        """
+        if not self.is_vehicle_tracking_enabled:
+            _LOGGER.warning('Vehicle tracking is disabled')
+            return None
+        pos = self._state.attributes[SERVICE_STATUS]['position']
+        return int(pos['heading'])
+
     @property
     @backend_parameter
     def is_vehicle_tracking_enabled(self) -> bool:


Test patch:
diff --git a/test/test_vehicle_status.py b/test/test_vehicle_status.py
index 1708772..d33d99e 100644
--- a/test/test_vehicle_status.py
+++ b/test/test_vehicle_status.py
@@ -37,6 +37,7 @@ class TestState(unittest.TestCase):
         self.assertTrue(state.vehicle_status.is_vehicle_tracking_enabled)
         self.assertAlmostEqual(50.5050, state.vehicle_status.gps_position[0])
         self.assertAlmostEqual(10.1010, state.vehicle_status.gps_position[1])
+        self.assertAlmostEqual(174, state.vehicle_status.gps_heading)
 
         self.assertAlmostEqual(33, state.vehicle_status.remaining_fuel)
 
@@ -68,6 +69,7 @@ class TestState(unittest.TestCase):
 
         self.assertFalse(state.vehicle_status.is_vehicle_tracking_enabled)
         self.assertIsNone(state.vehicle_status.gps_position)
+        self.assertIsNone(state.vehicle_status.gps_heading)
 
     def test_parse_f48(self):
         """Test if the parsing of the attributes is working."""
@@ -84,6 +86,7 @@ class TestState(unittest.TestCase):
         self.assertTrue(state.vehicle_status.is_vehicle_tracking_enabled)
         self.assertAlmostEqual(50.505050, state.vehicle_status.gps_position[0])
         self.assertAlmostEqual(10.1010101, state.vehicle_status.gps_position[1])
+        self.assertAlmostEqual(141, state.vehicle_status.gps_heading)
 
         self.assertAlmostEqual(39, state.vehicle_status.remaining_fuel)