Skip to content

Commit

Permalink
Added start charge button (#20)
Browse files Browse the repository at this point in the history
* Added charge start button

* Doc updates

* Fixed statistics error when not using UTC day boundary
  • Loading branch information
dan-r authored Apr 13, 2024
1 parent 1b9e89c commit 1f4d99f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ If you find any bugs or would like to request a feature, please open an issue.
This integration has been tested with the following vehicles:
* Nissan Leaf Tekna (2022) - UK [@dan-r]
* Nissan Qashqai (2021) - EU
* Nissan Ariya - EU

### North America
The API used in North America is completely separate to Europe and it appears that Nissan USA are [a lot more hostile](https://tobis.dk/blog/the-farce-of-nissanconnect-north-america/) towards third-party access. Any future US support would rely on library support (such as [dartnissanconnectna](https://gitlab.com/tobiaswkjeldsen/dartnissanconnectna)) or someone in North America maintaining that side of things. If you're interested, get in touch!
Expand Down Expand Up @@ -74,3 +75,4 @@ This integration exposes the following entities. Please note that entities will
* Update Data
* Flash Lights
* Honk Horn
* Start Charge
18 changes: 17 additions & 1 deletion custom_components/nissan_connect/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async def async_setup_entry(hass, config, async_add_entities):
HornLightsButtons(coordinator, data[vehicle], "flash_lights", "mdi:car-light-high", "lights"),
HornLightsButtons(coordinator, data[vehicle], "honk_horn", "mdi:bullhorn", "horn_lights")
]

if Feature.CHARGING_START in data[vehicle].features:
entities.append(ChargeControlButtons(coordinator, data[vehicle], "charge_start", "mdi:play", "start"))

async_add_entities(entities, update_before_add=True)

Expand Down Expand Up @@ -59,3 +60,18 @@ def icon(self):

def press(self):
self.vehicle.control_horn_lights('start', self._action)

class ChargeControlButtons(KamereonEntity, ButtonEntity):
def __init__(self, coordinator, vehicle, translation_key, icon, action):
self._attr_translation_key = translation_key
self._icon = icon
self._action = action
KamereonEntity.__init__(self, coordinator, vehicle)

@property
def icon(self):
return self._icon

def press(self):
self.vehicle.control_charging(self._action)

4 changes: 2 additions & 2 deletions custom_components/nissan_connect/kamereon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,10 @@ def fetch_trip_histories(self, period: Period=None, start: datetime.date=None, e
if period is None:
period = Period.DAILY
if start is None and end is None and period == Period.MONTHLY:
end = datetime.date.today()
end = datetime.datetime.utcnow().date()
start = end.replace(day=1)
elif start is None:
start = datetime.date.today()
start = datetime.datetime.utcnow().date()
if end is None:
end = start
resp = self._get(
Expand Down
3 changes: 3 additions & 0 deletions custom_components/nissan_connect/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
},
"update_data": {
"name": "Daten aktualisieren"
},
"charge_start": {
"name": "Starten Sie den Ladevorgang"
}
},
"climate": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/nissan_connect/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
},
"update_data": {
"name": "Update Data"
},
"charge_start": {
"name": "Start Charge"
}
},
"climate": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/nissan_connect/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
},
"update_data": {
"name": "Mettre à jour les données"
},
"charge_start": {
"name": "Démarrer la recharge"
}
},
"climate": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/nissan_connect/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
},
"update_data": {
"name": "Aggiorna dati"
},
"charge_start": {
"name": "Avvia carica"
}
},
"climate": {
Expand Down

0 comments on commit 1f4d99f

Please sign in to comment.