Skip to content

Commit

Permalink
Merge pull request #1 from dan-r/dev
Browse files Browse the repository at this point in the history
Fixed failures with ICE Qashqai
  • Loading branch information
dan-r authored Jan 20, 2024
2 parents 02ed86a + 7ecabaf commit 7fdf43e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This is an unofficial integration. I have no affiliation with Nissan besides own

Tested with the following vehicles:
* Nissan Leaf Tekna (2022) - UK
* Nissan Qashqai (2021) - EU

If you find any bugs or would like to request a feature, please open an issue.

Expand Down Expand Up @@ -36,22 +37,22 @@ Following the model of leaf2mqtt, this integration can be set to use a different
This integration exposes the following entities. Please note that entities will only be shown if the functionality is supported by your car.

* Binary Sensors
* Car Connected - On when the car is plugged in (EV Only)
* Car Charging - On when the car is plugged in and drawing power (EV Only)
* Car Plugged In (EV Only)
* Car Charging (EV Only)
* Sensors
* Battery Level
* Charge Time
* Internal Temperature
* External Temperature
* Range
* Range (EV Only)
* Odometer
* Daily Distance
* Daily Trips
* Daily Efficiency
* Daily Efficiency (EV Only)
* Monthly Distance
* Monthly Trips
* Monthly Efficiency
* Monthly Efficiency (EV Only)
* Climate
* Device Tracker
* Buttons
* Update Data - Force an update
* Update Data
2 changes: 1 addition & 1 deletion custom_components/nissan_connect/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def async_setup_entry(hass, config, async_add_entities):
coordinator = hass.data[DOMAIN][DATA_COORDINATOR]

for vehicle in data:
if Feature.TEMPERATURE in data[vehicle].features or Feature.INTERIOR_TEMP_SETTINGS in data[vehicle].features:
if Feature.INTERIOR_TEMP_SETTINGS in data[vehicle].features:
async_add_entities([KamereonClimate(coordinator, data[vehicle], hass)], update_before_add=True)


Expand Down
36 changes: 23 additions & 13 deletions custom_components/nissan_connect/kamereon.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,16 @@ def __init__(self, region):
# ugly hack
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

def login(self):
"""Login with cached credentials."""
return self.login(self._username, self._password)

def login(self, username, password):
# Cache credentials
self._username = username
self._password = password

def login(self, username=None, password=None):
if username is not None and password is not None:
# Cache credentials
self._username = username
self._password = password
else:
# Use cached credentials
username = self._username
password = self._password

# Reset session
self.session = requests.session()

Expand Down Expand Up @@ -751,10 +752,16 @@ def session(self):
def __init__(self, data, user_id):
self.user_id = user_id
self.vin = data['vin'].upper()
self.features = [
Feature(str(u['id']))
for u in data.get('services', [])
if u['activationState'] == "ACTIVATED"]
self.features = []

# Try to parse every feature, but dont fail if we dont recognise one
for u in data.get('services', []):
if u['activationState'] == "ACTIVATED":
try:
self.features.append(Feature(str(u['id'])))
except ValueError:
pass

self.can_generation = data.get('canGeneration')
self.color = data.get('color')
self.energy = data.get('energy')
Expand Down Expand Up @@ -1094,6 +1101,9 @@ def unlock(self, srp: str, group: LockableDoorGroup=None):
return self.lock_unlock(srp, 'unlock', group)

def fetch_hvac_status(self):
if Feature.INTERIOR_TEMP_SETTINGS not in self.features and Feature.TEMPERATURE not in self.features:
return

resp = self._get(
'{}v1/cars/{}/hvac-status'.format(self.session.settings['car_adapter_base_url'], self.vin),
headers={'Content-Type': 'application/vnd.api+json'}
Expand Down

0 comments on commit 7fdf43e

Please sign in to comment.