Skip to content

Commit

Permalink
Add remaining_time
Browse files Browse the repository at this point in the history
- Add a new line to the console app for readabiliy.
- Renamed variables (chargingStatus, pluggedStatus) so that ! makes more
sense.
- Add support for charging time remaining (conditional code is a bit
clumsy, open to performant readability improvement suggestions).
- Fixed unicode strings being forced on non-unicode strings.
  • Loading branch information
Matthew1471 committed May 7, 2018
1 parent 5ad7bf9 commit 6902503
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
29 changes: 10 additions & 19 deletions python/zoe-console.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,10 @@

battery = zeServices_json['charge_level']
remaining_range = kmToMiles * zeServices_json['remaining_range']
chargingStatus = zeServices_json['charging']
pluggedStatus = zeServices_json['plugged']
charging = zeServices_json['charging']
pluggedIn = zeServices_json['plugged']
updateTime = zeServices_json['last_update']

if (chargingStatus):
chargingText = u'Charging'
else:
chargingText = u'Not charging'

if (pluggedStatus):
pluggedText = u'Plugged in'
else:
pluggedText = u'Unplugged'
if charging: remaining_time = zeServices_json['remaining_time'] if 'remaining_time' in zeServices_json else None

# (Optionally) Create a MY Renault object.
if 'MyRenaultEmail' in credentials and 'MyRenaultPassword' in credentials:
Expand All @@ -74,17 +65,17 @@
# Check the Windows console can display UTF-8 characters.
if sys.platform != 'win32' or locale.getpreferredencoding() == 'cp65001':
# Generate the UTF-8 status (with emojis).
status = u'🔋 ' + str(battery) + '%'
status = u'\n🔋 ' + str(battery) + '%'
status += u'\n🚗 ' + str('%.0f' % round(remaining_range)) + ' miles'
status += u'\n🔌 ' + pluggedText
status += u'\n⚡ ' + chargingText
status += u'\n🔌 ' + ('Plugged in' if pluggedIn else 'Unplugged')
status += u'\n⚡ ' + ('Charging ' + ('(' + str(remaining_time) + ' minutes remain)' if remaining_time is not None else '') if charging else 'Not charging')
if totalMileage > 0: status += u'\n🛣️ ' + str(totalMileage) + ' miles (since ' + lastMileageRefresh + ')'
else:
# Generate the ASCII standard text status.
status = u'Battery: ' + str(battery) + '%'
status += u'\nRange: ' + str('%.0f' % round(remaining_range)) + ' miles'
status += u'\nPlugged In: ' + pluggedText
status += u'\nCharging: ' + chargingText
status = '\nBattery: ' + str(battery) + '%'
status += '\nRange: ' + str('%.0f' % round(remaining_range)) + ' miles'
status += '\nPlugged In: ' + ('Plugged in' if pluggedIn else 'Unplugged')
status += '\nCharging: ' + ('Charging ' + ('(' + str(remaining_time) + ' minutes remain)' if remaining_time is not None else '') if charging else 'Not charging')
if totalMileage > 0: status += u'\nMileage: ' + str(totalMileage) + ' miles (since ' + lastMileageRefresh + ')'

print(status)
37 changes: 14 additions & 23 deletions python/zoe-tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,12 @@
# ZE Services vehicle status.
zeServices_json = zeServices.apiCall('/api/vehicle/' + vin + '/battery')

battery = zeServices_json['charge_level']
remaining_range = kmToMiles * zeServices_json['remaining_range']
chargingStatus = zeServices_json['charging']
pluggedStatus = zeServices_json['plugged']
updateTime = zeServices_json['last_update']

if (chargingStatus):
chargingText = u'Charging'
else:
chargingText = u'Not charging'

if (pluggedStatus):
pluggedText = u'Plugged in'
else:
pluggedText = u'Unplugged'
battery = zeServices_json['charge_level']
remaining_range = kmToMiles * zeServices_json['remaining_range']
charging = zeServices_json['charging']
pluggedIn = zeServices_json['plugged']
updateTime = zeServices_json['last_update']
if charging: remaining_time = zeServices_json['remaining_time'] if 'remaining_time' in zeServices_json else None

# (Optionally) Create a MY Renault object.
if 'MyRenaultEmail' in credentials and 'MyRenaultPassword' in credentials:
Expand All @@ -81,23 +72,23 @@
# Generate the status.
status = u'\n🔋 ' + str(battery) + '%'
status += u'\n🚗 ' + str('%.0f' % round(remaining_range)) + ' miles'
status += u'\n🔌 ' + pluggedText
status += u'\n⚡ ' + chargingText
status += u'\n🔌 ' + ('Plugged in' if pluggedIn else 'Unplugged')
status += u'\n⚡ ' + ('Charging ' + ('(' + str(remaining_time) + ' minutes remain)' if remaining_time is not None else '') if charging else 'Not charging')
if totalMileage > 0: status += u'\n🛣️ ' + str(totalMileage) + ' miles (since ' + lastMileageRefresh + ')'
status += u'\n#RenaultZOE'
status += '\n#RenaultZOE'

# Check the Windows console can display UTF-8 characters.
if sys.platform != 'win32' or locale.getpreferredencoding() == 'cp65001':
# Display the UTF-8 status (with emojis).
print(status)
else:
# Generate an ASCII standard text status.
altstatus = u'\nBattery: ' + str(battery) + '%'
altstatus += u'\nRange: ' + str('%.0f' % round(remaining_range)) + ' miles'
altstatus += u'\nPlugged In: ' + pluggedText
altstatus += u'\nCharging: ' + chargingText
altstatus = '\nBattery: ' + str(battery) + '%'
altstatus += '\nRange: ' + str('%.0f' % round(remaining_range)) + ' miles'
altstatus += '\nPlugged In: ' + ('Plugged in' if pluggedIn else 'Unplugged')
altstatus += '\nCharging: ' + ('Charging ' + ('(' + str(remaining_time) + ' minutes remain)' if remaining_time is not None else '') if charging else 'Not charging')
if totalMileage > 0: altstatus += u'\nMileage: ' + str(totalMileage) + ' miles (since ' + lastMileageRefresh + ')'
altstatus += u'\n#RenaultZOE'
altstatus += '\n#RenaultZOE'
print(altstatus)

# Check if a Twitter library is installed.
Expand Down

0 comments on commit 6902503

Please sign in to comment.