def _add_default_arguments(parser: argparse.ArgumentParser): """Add the default arguments username, password, region to the parser.""" parser.add_argument('username', help='Connected Drive user name') parser.add_argument('password', help='Connected Drive password') parser.add_argument('region', choices=valid_regions(), help='Region of the Connected Drive account')
def main() -> None: """Main function.""" print() print('Motorlaunch, Copyright (C) 2019 Robert Bruce.') print('A text mode interface to the bimmer_connected library,') print('this program provides access to services and information') print('from BMW ConnectedDrive.') print() username, regionname, vin, browsername = read_config() print('Current username {}'.format(username)) print('Selected region {}'.format(regionname)) print('Selected VIN {}'.format(vin)) print() if username and regionname: password = getpass.getpass(prompt="Please enter your password: "******"Type an option ") print() while choice != 'q': print(choice) if choice == '0': print('Current Region is {}'.format(regionname)) print('Select Region From {}'.format((valid_regions()))) regionname = input("Type region ") for region_name, region in Regions.__members__.items(): if regionname.lower() == region_name.lower(): print('Region {}'.format(region)) regionname = region_name.lower() if choice == '1': print('Current username: {}'.format(username)) username = input("Type your new username ") if choice == '2': print('Paste a google maps URL, or') gps_position = parse_coordinates( input('enter lat, long in decimal format: ')) print('Lat {}, Lon {}'.format(gps_position[0], gps_position[1])) if vehicle: vehicle.set_observer_position(gps_position[0], gps_position[1]) poi = PointOfInterest(gps_position[0], gps_position[1]) if choice == '3': if vehicle: print('Current vehicle {}'.format(vehicle.vin)) vins = [] index = 1 for vehicle in account.vehicles: print('{} VIN: {} {}'.format(index, vehicle.vin, vehicle.name)) vins.append(vehicle.vin) index += 1 index = int(input('Enter number of vehicle to select. ')) vehicle = account.get_vehicle(vins[index - 1]) vin = vehicle.vin print('Current vehicle is now {} {}'.format( vehicle.vin, vehicle.name)) quick_status(vehicle) else: print('No vehicle selected.') if choice == '4': if vehicle: print('vehicle status: ') print('VIN: {}'.format(vehicle.vin)) print('Doors:') print(' {}'.format(vehicle.state.attributes["doorLockState"])) print(' Driver Front: {}'.format( vehicle.state.attributes["doorDriverFront"])) print(' Driver Rear: {}'.format( vehicle.state.attributes["doorDriverRear"])) print(' Passenger Front: {}'.format( vehicle.state.attributes["doorPassengerFront"])) print(' Passenger Rear: {}'.format( vehicle.state.attributes["doorPassengerRear"])) print('Hood: {}'.format(vehicle.state.attributes["hood"])) print('Trunk: {}'.format(vehicle.state.attributes["trunk"])) print('Windows:') print(' Driver Front: {}'.format( vehicle.state.attributes["windowDriverFront"])) print(' Driver Rear: {}'.format( vehicle.state.attributes["windowDriverRear"])) print(' Passenger Front: {}'.format( vehicle.state.attributes["windowPassengerFront"])) print(' Passenger Rear: {}'.format( vehicle.state.attributes["windowPassengerRear"])) print(' Sunroof: {}'.format( vehicle.state.attributes["sunroof"])) print(' Rear: {}'.format( vehicle.state.attributes["rearWindow"])) print('Fuel:') print(' Remaining Fuel: {}/{}'.format( vehicle.state.attributes["remainingFuel"], vehicle.state.attributes["maxFuel"])) print(' Fuel Range: {}'.format( vehicle.state.attributes["remainingRangeFuel"])) print('Battery:') print(' Percent Remaining: {}'.format( vehicle.state.attributes["chargingLevelHv"])) print(' Electric Range: {}/{}'.format( vehicle.state.attributes["remainingRangeElectric"], vehicle.state.attributes["maxRangeElectric"])) print('') else: print('No vehicle selected.') if choice == '5': if vehicle: light_flash(vehicle) else: print('No vehicle selected.') if choice == '6': if vehicle: sound_horn(vehicle) else: print('No vehicle selected.') if choice == '7': if vehicle and vehicle.state.is_vehicle_tracking_enabled: print('Latitude {}, Longitude {}'.format( vehicle.state.gps_position[0], vehicle.state.gps_position[1])) send = input('Send to Pure Maps? ') if send == 'y' or send == 'Y': mapper = 'harbour-pure-maps' command = '{} geo:{},{} &'.format( mapper, vehicle.state.gps_position[0], vehicle.state.gps_position[1]) os.system(command) else: print('I\'m sorry Dave, I\'m afraid I can\'t do that.') if choice == '8': vehicle.remote_services.trigger_remote_door_lock() if choice == '9': vehicle.remote_services.trigger_remote_door_unlock() if choice == 'a': vehicle.remote_services.trigger_remote_air_conditioning() if choice == 'b': browsername = input( 'Please enter the executable name of your browser ') if choice == 'c': # Electric drivetrain only vehicle.remote_services.trigger_remote_charge_now() if choice == 'd': #Send a POI to car print('Paste a google maps URL, or') gps_position = parse_coordinates( input( 'Enter lat, long in decimal format, e.g. 34.01234, -92.98765 : ' )) print('Lat {}, Lon {}'.format(gps_position[0], gps_position[1])) poiname = input('Name this destination or hit <Enter> for none: ') streetname = input('Enter address or hit <Enter> for none: ') cityname = input('Enter city. <Enter> for none: ') zip = input('Enter postal (ZIP) code. <Enter> for none: ') countryname = input('Enter country name. <Enter> for none: ') if vehicle: poi = PointOfInterest(gps_position[0], gps_position[1], name=poiname, street=streetname, city=cityname, postalcode=zip) vehicle.send_poi(poi) if choice == 'l': # Get last trip statistics print('Last trip statistics:') print(json.dumps(vehicle.get_vehicle_lasttrip(), indent=4)) if choice == 'm': if browsername != '': print('Range Map:') maps = vehicle.get_vehicle_rangemap() #if sort_keys then rangemaps are sorted by "type" print('The following rangemaps are available') i = 1 for map in maps['rangemaps']: print('{} {}'.format(i, map['type'])) i += 1 i = int(input('Select a rangemap: ')) map = maps['rangemaps'][i - 1]['polyline'] f = open("rangemap.html", "w+") f.write(map1) f.write('center: [{}, {}],'.format(maps["center"]["lon"], maps["center"]["lat"])) f.write(map2) firstline = True for point in map: if not firstline: f.write(',') f.write('[{}, {}]'.format(point['lon'], point['lat'])) firstline = False f.write(map3) f.close() #input('Press Enter') #browser = 'sailfish-browser' #command = '{} {} &'.format(browsername, f.name) #os.system(command) webbrowser.open(f.name) #print(json.dumps(maps,sort_keys=True, indent=4)) #['rangemaps'][1] else: print('Enter your browser\'s executable name first. ') if choice == 'n': # Get destinations print('Vehicle destinations:') print(json.dumps(vehicle.get_vehicle_destinations(), indent=4)) if choice == 's': # Get all trip statistics print('All trip statistics:') print(json.dumps(vehicle.get_vehicle_alltrips(), indent=4)) if choice == 'o': password = input("Please enter your password: "******"doorLockState"])) print('Position: {}'.format( vehicle.state.attributes["position"]["status"])) if vin: vehicle = account.get_vehicle(vin) if choice == 'p': if vehicle: index = 1 while index != 0: views = [] for view in VehicleViewDirection: print('{} {}'.format(index, view.name)) views.append(view.name) index += 1 index = int( input('Please select view or type 0 for done. ')) if index != 0: print('{}'.format(views[index - 1])) get_image(vehicle, VehicleViewDirection(views[index - 1])) index = 1 else: print('No vehicle selected - select one first') if choice == 'r': if vehicle: print('Raw status info (You asked for it):') print('VIN: {}'.format(vehicle.vin)) print(json.dumps(vehicle.state.attributes, indent=4)) else: print('No vehicle selected.') if choice == 'w': # Get weekly charging planner print('Charging profile:') print(json.dumps(vehicle.get_vehicle_charging_profile(), indent=4)) if choice == 'z': # Send message to car subject = input('Type the subject: ') message = input('Type your message ') vehicle.send_message(message, subject) if choice == 'i': if vehicle: print('Inquire a single status field:') field = input('Carefully type exact field name: ') print('VIN: {}'.format(vehicle.vin)) print(json.dumps(vehicle.state.attributes[field], indent=4)) else: print('No vehicle selected.') if choice == '?': print_about() printmenu() choice = input("Type an option ") print() write_config(username, regionname, vin, browsername)
def test_valid_regions(self): """Test valid regions.""" self.assertListEqual(["north_america", "china", "rest_of_world"], valid_regions())
def test_valid_regions(self): """Test getting list of regions.""" self.assertIn('china', valid_regions())