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

KeyError: 'climate_state' #186

Closed
alandtse opened this issue Apr 3, 2021 · 3 comments
Closed

KeyError: 'climate_state' #186

alandtse opened this issue Apr 3, 2021 · 3 comments

Comments

@alandtse
Copy link
Collaborator

alandtse commented Apr 3, 2021

@Trupal00p

I'm getting this error in a live system. Can you please check and provide a fix? Please note there will be vehicles that may not have seat heaters.

  File "/workspaces/home-assistant/homeassistant/components/tesla/config_flow.py", line 229, in validate_input
    config = await controller.connect(
  File "/workspaces/home-assistant/config/teslajsonpy/controller.py", line 316, in connect
    self._add_components(car)
  File "/workspaces/home-assistant/config/teslajsonpy/controller.py", line 549, in _add_components
    self.__components.append(HeatedSeatSwitch(car, self, 'left'))
  File "/workspaces/home-assistant/config/teslajsonpy/homeassistant/heated_seats.py", line 47, in __init__
    self.__seat_heat_level = data['climate_state'][f'seat_heater_{seat_name}']
KeyError: 'climate_state'

I'll spawn a new issue with this comment so please respond there.

Originally posted by @alandtse in #180 (comment)

@alandtse
Copy link
Collaborator Author

alandtse commented Apr 3, 2021

I will put a temporary fix that won't load the seat sensors if a keyerror is found. That may be the solution, but I'd appreciate you taking a look and maybe considering another fix with a test for this case.

alandtse added a commit to alandtse/teslajsonpy that referenced this issue Apr 3, 2021
@alandtse
Copy link
Collaborator Author

alandtse commented Apr 3, 2021

It looks like you're relying on the sensors to already have data in them. However, the data won't have been pulled yet during init. You should move that into the update function.

@Trupal00p
Copy link
Contributor

Just opened a PR to fix this. Thanks for clarifying what was causing the issue, misunderstood the lifecycle of the tesla data when I originally added.

@alandtse alandtse closed this as completed May 1, 2021
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

No branches or pull requests

2 participants