Skip to content

Commit e254899

Browse files
authored
Allow disabling polling and fix oauth (#105)
* Add support for disabling polling * Fix Nissan oauth realm changes * Disable polling by default
1 parent 134ee87 commit e254899

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ From the Home Assistant Integrations page, search for and add the Nissan Connect
4343

4444
## Update Time
4545
Terminology used for this integration:
46-
* Polling - the car is woken up and new status is reported
46+
* Polling - the car is woken up and new status is reported. This is disabled by default, but can be enabled by setting the polling interval to a non-zero value
4747
* Update - data is fetched from Nissan but the car is not woken up
4848

49-
Following the model of leaf2mqtt, this integration can be set to use a different update time when plugged in. When HVAC is turned on the update time drops to once per minute.
49+
Following the model of leaf2mqtt, this integration can be set to use a different polling time when plugged in. When HVAC is turned on the polling time always drops to once per minute.
5050

51-
To prevent excessive 12v battery drain when plugged in but not charging for extended periods of time, the interval reverts to the standard update interval after 4 consecutive updates show the car as plugged in but not charging.
51+
To prevent excessive 12v battery drain when plugged in but not charging for extended periods of time, the polling interval reverts to the standard interval after 4 consecutive updates show the car as plugged in but not charging.
5252
This logic was added to give the benefit of quicker response times on the charging status binary sensor, which can be especially useful when charging with load-balanced or 'smart' chargers.
5353

5454
## Translations

custom_components/nissan_connect/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DATA_COORDINATOR_POLL = "coordinator_poll"
88
DATA_COORDINATOR_STATISTICS = "coordinator_statistics"
99

10-
DEFAULT_INTERVAL_POLL = 60
10+
DEFAULT_INTERVAL_POLL = 0
1111
DEFAULT_INTERVAL_CHARGING = 15
1212
DEFAULT_INTERVAL_STATISTICS = 60
1313

custom_components/nissan_connect/coordinator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ async def _async_update_data(self):
105105
try:
106106
for vehicle in self._vehicles:
107107
time_since_updated = round((time() - self._last_updated[vehicle]) / 60)
108-
if self._force_update[vehicle] or time_since_updated >= self._intervals[vehicle]:
108+
if not self._intervals[vehicle] == 0 and (self._force_update[vehicle] or time_since_updated >= self._intervals[vehicle]):
109109
_LOGGER.debug("Polling #%s as %d mins have elapsed (interval %d)", vehicle[-3:], time_since_updated, self._intervals[vehicle])
110110
self._last_updated[vehicle] = int(time())
111111
self._force_update[vehicle] = False
112112
await self._hass.async_add_executor_job(self._vehicles[vehicle].refresh)
113113
else:
114-
_LOGGER.debug("NOT polling #%s as %d mins have elapsed (interval %d)", vehicle[-3:], time_since_updated, self._intervals[vehicle])
114+
_LOGGER.debug("NOT polling #%s. %d mins have elapsed (interval %d)", vehicle[-3:], time_since_updated, self._intervals[vehicle])
115115
except BaseException:
116116
_LOGGER.warning("Error communicating with API")
117117
return False

custom_components/nissan_connect/kamereon/kamereon.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def login(self, username=None, password=None):
151151
_LOGGER.error("Invalid credentials provided: %s", resp.text)
152152
raise RuntimeError("Invalid credentials")
153153

154-
oauth_authorize_url = '{}oauth2{}/authorize'.format(
154+
oauth_authorize_url = '{}oauth2/{}/authorize'.format(
155155
self.settings['auth_base_url'],
156-
oauth_data['realm']
156+
self.settings['realm']
157157
)
158158
nonce = generate_nonce()
159159
resp = self.session.get(
@@ -168,9 +168,9 @@ def login(self, username=None, password=None):
168168
allow_redirects=False)
169169
oauth_authorize_url = resp.headers['location']
170170

171-
oauth_token_url = '{}oauth2{}/access_token'.format(
171+
oauth_token_url = '{}oauth2/{}/access_token'.format(
172172
self.settings['auth_base_url'],
173-
oauth_data['realm']
173+
self.settings['realm']
174174
)
175175
self._oauth = OAuth2Session(
176176
client_id=self.settings['client_id'],

custom_components/nissan_connect/sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class ChargeTimeRequiredSensor(KamereonEntity, SensorEntity):
264264
_attr_translation_key = "charge_time"
265265
_attr_device_class = SensorDeviceClass.DURATION
266266
_attr_native_unit_of_measurement = UnitOfTime.MINUTES
267+
_attr_suggested_unit_of_measurement = UnitOfTime.HOURS
267268

268269
CHARGING_SPEED_NAME = {
269270
ChargingSpeed.FASTEST: '50kw',

custom_components/nissan_connect/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"data_description": {
4343
"password": "If you are not changing your credentials, leave the password field empty.",
44-
"interval_charging": "The car will be woken up and new data requested at every polling interval.",
44+
"interval_charging": "The car will be woken up and new data requested at every polling interval. 0 = Polling disabled",
4545
"interval_statistics": "On update intervals, the latest data will be fetched from Nissan but the car will not be woken up."
4646
}
4747
}

0 commit comments

Comments
 (0)