-
Notifications
You must be signed in to change notification settings - Fork 10
Add AC Current Limit functions #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Example script demonstrating AC current control functionality. | ||
|
|
||
| This script shows how to: | ||
| 1. Set the AC current limit for a vehicle | ||
| 2. Get the current AC current settings | ||
| 3. Monitor changes in AC current settings | ||
|
|
||
| Requirements: | ||
| - Python 3.7+ | ||
| - lucidmotors package installed | ||
| - Valid Lucid account credentials | ||
| """ | ||
|
|
||
| import asyncio | ||
| import logging | ||
| from lucidmotors import LucidAPI | ||
|
|
||
| # Set up logging | ||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def main(): | ||
| """Main function demonstrating AC current control.""" | ||
|
|
||
| # Initialize the API client | ||
| async with LucidAPI(auto_wake=True) as api: | ||
| try: | ||
| # Login with your credentials | ||
| logger.info("Logging in...") | ||
| await api.login("your_email@example.com", "your_password") | ||
| logger.info("Login successful!") | ||
|
|
||
| # Get your vehicles | ||
| vehicles = await api.fetch_vehicles() | ||
| if not vehicles: | ||
| logger.error("No vehicles found in your account") | ||
| return | ||
|
|
||
| vehicle = vehicles[0] # Use the first vehicle | ||
| logger.info(f"Using vehicle: {vehicle.vehicle_id}") | ||
|
|
||
| # Get current AC current settings | ||
| logger.info("Getting current AC current settings...") | ||
| current_settings = await api.get_ac_current_settings(vehicle) | ||
|
|
||
| logger.info("Current AC Current Settings:") | ||
| logger.info( | ||
| f" Active Session Limit: {current_settings['active_session_limit']}A" | ||
| ) | ||
| logger.info(f" Energy Limit: {current_settings['energy_limit']}A") | ||
| logger.info(f" Requested Limit: {current_settings['requested_limit']}A") | ||
|
|
||
| # Example: Set AC current limit to 32A (common for home charging) | ||
| new_limit = 32 | ||
| logger.info(f"Setting AC current limit to {new_limit}A...") | ||
| await api.set_ac_current_limit(vehicle, new_limit) | ||
| logger.info("AC current limit set successfully!") | ||
|
|
||
| # Wait a moment for the change to take effect | ||
| await asyncio.sleep(2) | ||
|
|
||
| # Get updated settings to confirm the change | ||
| logger.info("Getting updated AC current settings...") | ||
| updated_settings = await api.get_ac_current_settings(vehicle) | ||
|
|
||
| logger.info("Updated AC Current Settings:") | ||
| logger.info( | ||
| f" Active Session Limit: {updated_settings['active_session_limit']}A" | ||
| ) | ||
| logger.info(f" Energy Limit: {updated_settings['energy_limit']}A") | ||
| logger.info(f" Requested Limit: {updated_settings['requested_limit']}A") | ||
|
|
||
| # Example: Set AC current limit to 16A (lower power charging) | ||
| lower_limit = 16 | ||
| logger.info(f"Setting AC current limit to {lower_limit}A...") | ||
| await api.set_ac_current_limit(vehicle, lower_limit) | ||
| logger.info("AC current limit set successfully!") | ||
|
|
||
| # Wait and get final settings | ||
| await asyncio.sleep(2) | ||
| final_settings = await api.get_ac_current_settings(vehicle) | ||
|
|
||
| logger.info("Final AC Current Settings:") | ||
| logger.info( | ||
| f" Active Session Limit: {final_settings['active_session_limit']}A" | ||
| ) | ||
| logger.info(f" Energy Limit: {final_settings['energy_limit']}A") | ||
| logger.info(f" Requested Limit: {final_settings['requested_limit']}A") | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Error: {e}") | ||
| raise | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("AC Current Control Example") | ||
| print("=" * 30) | ||
| print( | ||
| "This script demonstrates how to control AC current limits for your Lucid vehicle." | ||
| ) | ||
| print("Make sure to update the credentials in the script before running.") | ||
| print() | ||
|
|
||
| # Run the example | ||
| asyncio.run(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1327,3 +1327,54 @@ async def creature_comfort_control( | |
| await _check_for_api_error( | ||
| self._vehicle_service.SetCreatureComfortMode(request) | ||
| ) | ||
|
|
||
| async def set_ac_current_limit(self, vehicle: Vehicle, current_limit: int) -> None: | ||
|
||
| """ | ||
| Set the AC current limit for a specific vehicle. | ||
|
|
||
| :param vehicle: The vehicle to set the AC current limit for | ||
| :param current_limit: The AC current limit in amperes (A) | ||
| """ | ||
|
|
||
| if self._auto_wake and not self.vehicle_is_awake(vehicle): | ||
| await self.wakeup_vehicle(vehicle) | ||
|
|
||
| request = vehicle_state_service_pb2.SetACCurrLimitRequest( | ||
| ac_curr_lim=current_limit, | ||
| vehicle_id=vehicle.vehicle_id, | ||
| ) | ||
| await _check_for_api_error(self._vehicle_service.SetACCurrLimit(request)) | ||
|
|
||
| async def get_ac_current_settings(self, vehicle: Vehicle) -> dict[str, int]: | ||
| """ | ||
| Get the current AC current settings for a specific vehicle. | ||
|
|
||
| :param vehicle: The vehicle to get AC current settings for | ||
| :return: Dictionary containing AC current settings: | ||
| - 'active_session_limit': Current AC current limit for active charging session (A) | ||
| - 'energy_limit': Energy AC current limit (A) | ||
| - 'requested_limit': Requested AC current limit (A) | ||
| """ | ||
|
|
||
| # Get fresh vehicle state to ensure we have current AC current settings | ||
| await self.fetch_vehicles() | ||
|
borski marked this conversation as resolved.
|
||
|
|
||
| # Find the updated vehicle data | ||
| updated_vehicle = next( | ||
| (v for v in self._vehicles if v.vehicle_id == vehicle.vehicle_id), None | ||
| ) | ||
|
|
||
| if not updated_vehicle: | ||
| raise APIValueError(f"Vehicle {vehicle.vehicle_id} not found") | ||
|
|
||
| return { | ||
| 'active_session_limit': getattr( | ||
| updated_vehicle.state.charging, 'active_session_ac_current_limit', 0 | ||
| ), | ||
| 'energy_limit': getattr( | ||
| updated_vehicle.state.charging, 'energy_ac_current_limit', 0 | ||
| ), | ||
| 'requested_limit': getattr( | ||
| updated_vehicle.state.mobile_app_request, 'ac_current_limit_req', 0 | ||
| ), | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.