Skip to content
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

Add support for energy sites to re-write #250

Merged
merged 110 commits into from
Oct 16, 2022
Merged

Conversation

shred86
Copy link
Collaborator

@shred86 shred86 commented Aug 18, 2022

Added support for Tesla energy sites and updates to cars. Requires updates to teslajsonpy submitted in this pull request. This is a breaking change as some naming conventions were changed to align with Home Assistant. Tested on my setup which is a 2015 Tesla Model S 85D and Tesla solar system with a Tesla inverter (no Powerwalls). Please feel free to help out with finishing this rewrite by referencing the "To do" section below.

Breaking Changes

  • All entities will be recreated - recommend removing the integration before adding this updated version.
  • Changed trunk, frunk and charger door from lock to cover entities.
  • Created separate sensor (TeslaCarChargerPower class) for charger power.
  • Moved charger amps, charger volts and charger phases extra state attributes to the new charger power sensor.
  • Moved added range extra state attributes to the charger energy added sensor.

Changes

  • Move car specific code out of TeslaBaseEntity to a newly created TeslaCarEntity.
  • New TeslaEnergyEntity class which also inherits from TeslaBaseEntity.
  • New TeslaEnergyPowerSensor class used for creating power sensors (solar, grid, load and battery).
  • New TeslaEnergyBattery class for Powerwall battery percentage sensor.
  • New TeslaEnergyBatteryRemaining class for Powerewall battery Watt hour remaining sensor.
  • New TeslaEnergyBackupReserve class for Powerwall backup reserve percentage setting sensor.
  • New TeslaEnergyBatteryCharging class for Powerwall battery charging binary sensor.
  • New TeslaEnergyGridStatus class for Powerwall grid status binary sensor.
  • New TeslaEnergyGridCharging class for Powerwall grid charging select.
  • New TeslaEnergyExportRule class for Powerwall export rule select.
  • New TeslaEnergyOperationMode class for Powerwall operation mode select.
    • New TeslaCarChargerPower class for car charger power (kW).
  • Updated properties and method calls to teslajsonpy to reflect the changes made to teslajsonpy.
  • Added additional checks to only add entities for what a car actually has (seat heaters, heated steering wheel, HomeLink, etc.)
  • Updated naming to align with current Home Assistant convention.
  • Changed unique IDs to use VIN + entity type for vehicles.
  • Update class naming to TeslaCar* and TeslaEnergy* for all vehicle and energy site related classes respectively.
  • Renamed TeslaCarMileage to TeslaCarOdometer.
  • TeslaCarParkingBrake will indicate "On" when the car is on and in "Park" but also when the car is off (parking brake still engaged).
  • Updated icons to better reflect entities purpose.
  • Added a check to the car energy added sensor to report 0 unless the car is charging, then report the actual charge energy added. This is due to the Tesla API reporting a decreasing value over time when not charging causing issues with the HA sensor state class "TOTAL_INCREASING".
  • Removed extra state attributes that are already a separate entity (charge energy added, charge current request).
  • Moved charger actual current, charger voltage and charger power extra state attributes from the charging rate to energy added entity.
  • Updated TeslaCarChargerConnection device class to PLUG.
  • Removed unused helpers.py.
  • Cast vehicle ID and ID to a string in TeslaCarOnline extra state attributes to prevent HA from automatically formatting with commas.
  • Check users HA unit system locale settings for determining to return miles vs kilometers.
  • Vehicles will be forced to wake up the first time the integration is set up. For subsequent integration or HA restarts, vehicles will not be forced to wake up unless enabled in the configuration options (defaults to off).
  • Added two new options, "Include Vehicles" and "Include Energy Sites" to the setup config flow. These will allow a user to include/exclude vehicles or energy sites. Defaults selected.
  • Updated doc strings.
  • Updated and added tests to cover changes.

Fixes

Known Issues

  • When turning the HVAC system on from HA, the state of the HVAC entity in HA remains off. If you subsequently turn the HVAC system off from HA, the state of the HVAC entity in HA shows on. What's happening is update_controller is being called when async_set_hvac_mode is called. We're immediately updating the state in teslajsonpy upon a successful response but update_controller triggers another Controller.update which returns a response that indicates the HVAC system is off when we just turned it on, and vice versa. It appears we're not giving the Tesla server enough time to write/save the new is_climate_on status so we're getting the "old" state. The entity state is being updated immediately in teslajsonpy so we're simply refreshing the HA entity state.
  • Climate preset modes (climate keeper modes) do not work on the 2015 Model S 85D. It doesn't let me set it in the Tesla app so there must be a key it's using to hide the controls. Either that or it's just filtering by the car model.
  • Heated seat select feature doesn't work for my 2015 Model S. The response I receive is 00: {"response":{"reason":"cabin comfort remote settings not enabled","result":false}} even though VEHICLE_DATA shows I do have it enabled, 'remote_heater_control_enabled': True. I can also control seated heats from my Tesla app.
  • Battery percentage and battery remaining for energy sites sometimes erroneously reports 0. This is coming straight from Tesla's endpoint but only seems to happen for a very short period (usually starts reporting correctly within 10-20 sec).
  • HomeLink button will become unavailable if HA is restarted when the car is asleep. The reason is we're checking for homelink_device_count to determine whether or not to add the HomeLink button, but when the car is asleep it's returning None.
  • When restarting HA with "Force cars awake on startup" enabled, if the integration does have to wake up a vehicle, it can cause the HA start up to be very slow because we're waiting for the vehicle wake up to complete before moving on with the rest of the HA start up.

To do:

  • Update tests where needed for full coverage.
  • Clean-up and review services.py
  • Re-create app-like functionality, where the climate is enabled before heated seats are enabled
  • Create media_player entity
  • Add authentication option using username & password
  • Update the Wiki on this repo.
  • Add include_vehicle and include_energysite options into config flow for Controller.connect

@shred86 shred86 changed the title Add support for energy sites to re-write DRAFT: Add support for energy sites to re-write Aug 18, 2022
@shred86 shred86 marked this pull request as draft August 18, 2022 00:30
@alandtse
Copy link
Owner

The native key has always been there. I don't think it's the solution. We should go with the solution provided by the Chinese user. No need optimizing blind.

@shred86
Copy link
Collaborator Author

shred86 commented Oct 11, 2022

Sounds good - I'm not quite sure what the difference is with native_location.

Just added the GCJ02 to WGS84 conversion back in with some slight modifications to make it work with the rewrite.

@alandtse
Copy link
Owner

Ok, for #218, while it may rely on some older teslajsonpy functions, the changes were specifically for HA to enable the Delete Button. We'll want to not lose that.

The failing CI for Validate/Hacsfest should resolve once we publish teslajsonpy. I'm a bit more concerned about the failing unit tests. We should at least be on parity for unit testing before we push this out to dev. Once we've done the teslajsonpy release, I'll also put this on a dev system and see if I can help clear out the remaining issues with you.

@shred86
Copy link
Collaborator Author

shred86 commented Oct 11, 2022

Sounds good. I usually don’t have much time on weekdays as I’m sure like most folks, I’m just doing this when I have free time outside of work and family time.

I’ll try to take a look at the tests and #218 sometime this week if I can. The coverage was pretty high when I last checked except for init.py and config_flow.py, but I didn’t think they were any less than the current integration.

@alandtse
Copy link
Owner

Don't forget to bump poetry. See example: #276

@shred86
Copy link
Collaborator Author

shred86 commented Oct 14, 2022

Whoops, done!

I'm hoping to be able to update the tests this weekend.

@alandtse
Copy link
Owner

alandtse commented Oct 15, 2022

Finally tested this. Looks like we're upping the minimum HA version. Please make sure we fix hacs.json to enforce it.

2022-10-15 08:15:44 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform tesla_custom.sensor: Platform not found (No module named 'homeassistant.util.unit_conversion').

EDIT: Looks like 2022.10.0 home-assistant/core@6002377

@alandtse alandtse merged commit 6a1f9c3 into alandtse:dev Oct 16, 2022
@alandtse alandtse mentioned this pull request Oct 16, 2022
@alandtse
Copy link
Owner

Thanks. Please note this is live in dev. Users will need to opt in. The plan will be do a full release after 1 week or so.

@purcell-lab
Copy link
Contributor

I installed it from dev yesterday and this is running solid for me so far.

Congratulations and well done on a fantastic rewrite that adds a lot of functionality!

@shred86 @alandtse

@alandtse
Copy link
Owner

This was all @shred86. I can't take any real credit for this.

Btw @shred86 , did you point anyone to the dev branch for testing? I haven't seen any new issues and it seems fine from my production server. I didn't check the HA forums though. My plan is to take this live this weekend unless you aren't around to deal with any potential issues. Let me know.

Thanks,
Alan

@purcell-lab
Copy link
Contributor

Btw @shred86 , did you point anyone to the dev branch for testing?

I'm happy to point some eager users from community.homeassistant which is probably a good idea before we go for a wide release, but I'll wait your confirmation.

@shred86
Copy link
Collaborator Author

shred86 commented Oct 19, 2022

@Megabytemb did most of the work honestly. I just continued what he did and redid the teslajsonpy side.

I haven’t mentioned the beta yet. @purcell-lab no issues spreading the word. The more folks we can have test the better. If you don’t mind sharing the thread you post in, we can check it if there’s any questions to answer.

@alandtse I won’t have much time Saturday but I should be around Sunday. There are a couple minor known issues and I still haven’t added the ability to delete entities yet, but maybe those are things we can add later.

@purcell-lab
Copy link
Contributor

purcell-lab commented Oct 19, 2022

I have released a post https://community.home-assistant.io/t/add-support-for-tesla-powerwall/142280/309?u=markpurcell

Found. If you have community.HomeAssistant usernames please let me know so I can tag the post (I had a search but couldn't confirm your identity)

@alandtse
Copy link
Owner

Thanks. I haven't seen any influx of issues yet, so I'll plan to do the release Friday. That way it'll give some people time to install it and we can address any new issues over the weekend.

@alandtse
Copy link
Owner

This is now live as 3.0. Congrats @shred86

@purcell-lab
Copy link
Contributor

and just like that I get a notification here. Great work.

Screenshot_20221022-121539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants