jonasman / TeslaSwift

Swift library to access the Tesla API
MIT License
240 stars 72 forks source link

New functionality, Seat heaters #32

Closed mortimern closed 5 years ago

mortimern commented 5 years ago

Hi,

Will there be an update to the library as the new functionality to turn on seat heaters in the app has been made available? I can see that it has been added to the API. Steering wheel heater has also bee added.

I hope you are still active in updating the library :)

Thank you :)

jonasman commented 5 years ago

Hi,

Yes all these functionality are planned. If you want to help Im open for a PR :)

João

On 15 Feb 2019, at 14:52, mortimern notifications@github.com<mailto:notifications@github.com> wrote:

Hi,

Will there be an update to the library as the new functionality to turn on seat heaters in the app has been made available? I can see that it has been added to the API. Steering wheel heater has also bee added.

I hope you are still active in updating the library :)

Thank you :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jonasman/TeslaSwift/issues/32, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABrmXs4TMGXVvbpgMTlf0MPo9p0lSJbOks5vNq15gaJpZM4a9mED.

mortimern commented 5 years ago

I would love to help, but cannot guarantee that it will be helpful :) I will fork it and see if I can figure out a solution :)

jor-dan commented 5 years ago

I opened a pull (#33) to help with seat heaters. I can't really test the steering wheel heater so I'll leave that alone.

mortimern commented 5 years ago

Hi jor-dan. I have found a few places that say this for the numbering on the seats. I can see that you named the seats, instead of numbers so you might want to add all seats to the list.

SeatHeaterFrontLeft: 0 SeatHeaterFrontRight: 1 SeatHeaterRearLeft: 2 SeatHeaterRearLeftBack: 3 SeatHeaterRearCenter: 4 SeatHeaterRearRight: 5 SeatHeaterRearRightBack: 6 SeatHeater3rdRowLeft: 7 SeatHeater3rdRowRight: 8

Since I get build errors here, you might want to add the steering wheel functions from my code? Or I can test yours on my car before you make a new PR. I have commited and tested the code on my fork and it works locally on my device.

jor-dan commented 5 years ago

I added the missing seats. Thanks for the help!

I was able to test my steering wheel implementation and it works fine (also is essentially the same as yours). I see through testing in Postman that the Tesla API returns a successful response even if the car doesn't have a steering wheel heater. If you enable debugging in this library then you can see the successful response

RESPONSE BODY: {"response":{"reason":"","result":true}}

in the console even if you can't see it in the car itself.

mortimern commented 5 years ago

Great :) Good job. I have seen both the true result, but also the false result with reason "cabin comfort remote settings not enabled". From what I have read and researched it just means that the climate is not turned on, or noone is present in the car. In the final App you just have to make that exception if the climate is off.

Thank you for the quick fix and help with this. Hopefully Jonasman can now accept the pullrequest and merge the builds :)

jonasman commented 5 years ago

I can test the code as my car has all the heaters with the winter package

jonasman commented 5 years ago

Tested that seat heater and steering wheel works good. I renamed some classes to make it more clear to the API user

mortimern commented 5 years ago

Thank you :)

mortimern commented 5 years ago

jonasman, would you mind posting the JSON answer to climate state from your car that has all the seatheaters? I am looking for the names in the answer, but dont have all seats heated in my car..

Hope you can help :) Thank you.

jonasman commented 5 years ago

Climate State does not have seat information

mortimern commented 5 years ago

Yes it does.. It reports back what level each seat is set to. Here is the JSON answer from one of the cars I have access to:

"climate_state": { "battery_heater": false, "battery_heater_no_power": false, "driver_temp_setting": 23.5, "fan_status": 0, "inside_temp": 5.3, "is_auto_conditioning_on": true, "is_climate_on": false, "is_front_defroster_on": false, "is_preconditioning": false, "is_rear_defroster_on": false, "left_temp_direction": 506, "max_avail_temp": 28, "min_avail_temp": 15, "outside_temp": 0.5, "passenger_temp_setting": 23.5, "remote_heater_control_enabled": false, "right_temp_direction": 506, "seat_heater_left": 0, "seat_heater_rear_center": 0, "seat_heater_rear_left": 0, "seat_heater_rear_right": 0, "seat_heater_right": 0, "side_mirror_heaters": false, "smart_preconditioning": false, "steering_wheel_heater": false, "timestamp": 1550621178903, "wiper_blade_heater": false }

When you set level to the heater it reports back the level. It is not just if it is present or not. The car from the JSON over is a MS with winter package. This JSON is from a MS without winter package: { "response": { "battery_heater": false, "battery_heater_no_power": false, "driver_temp_setting": 20, "fan_status": 0, "inside_temp": 8.1, "is_auto_conditioning_on": false, "is_climate_on": false, "is_front_defroster_on": false, "is_preconditioning": false, "is_rear_defroster_on": false, "left_temp_direction": 150, "max_avail_temp": 28, "min_avail_temp": 15, "outside_temp": 4, "passenger_temp_setting": 20, "remote_heater_control_enabled": false, "right_temp_direction": 150, "seat_heater_left": 0, "seat_heater_right": 0, "side_mirror_heaters": false, "smart_preconditioning": false, "timestamp": 1550956038884, "wiper_blade_heater": false }

I have altered the climatestate.swift file to read it as an int and it is returning the level. Doesnt your car report back the seat heater information? A MX would give back the names for the third row seats too I would imagine?

Morten

jonasman commented 5 years ago

Sorry i read from the wrong place and thought there was no seat heater info.

My car is a model S with 5 seats and winter package.

{ "battery_heater":false, "battery_heater_no_power":false, "driver_temp_setting":21.5, "fan_status":0, "inside_temp":20.2, "is_auto_conditioning_on":false, "is_climate_on":false, "is_front_defroster_on":false, "is_preconditioning":false, "is_rear_defroster_on":false, "left_temp_direction":60, "max_avail_temp":28.0, "min_avail_temp":15.0, "outside_temp":13.5, "passenger_temp_setting":21.5, "remote_heater_control_enabled":false, "right_temp_direction":60, "seat_heater_left":0, "seat_heater_rear_center":0, "seat_heater_rear_left":0, "seat_heater_rear_right":0, "seat_heater_right":0, "side_mirror_heaters":false, "smart_preconditioning":false, "steering_wheel_heater":false, "timestamp":1550956690108, "wiper_blade_heater":false }

mortimern commented 5 years ago

:) I have some problems getting a pull request built here, I dont know why, it complain about missing links, but cant really find them. It builds and works on my machine. I am not too familiar with Git, so I might do something wrong. If you could edit the climatestate.swift file, I have tested it to be good. It reports back the level of the heater instead of a Bool value.

open var seatHeaterLeft: Int? open var seatHeaterRearCenter: Int? open var seatHeaterRearLeft: Int? open var seatHeaterRearLeftBack: Int? open var seatHeaterRearRight: Int? open var seatHeaterRearRightBack: Int? open var seatHeaterRight: Int?

seatHeaterLeft = try? container.decode(Int.self, forKey: .seatHeaterLeft) seatHeaterRearCenter = try? container.decode(Int.self, forKey: .seatHeaterRearCenter) seatHeaterRearLeft = try? container.decode(Int.self, forKey: .seatHeaterRearLeft) seatHeaterRearLeftBack = try? container.decode(Int.self, forKey: .seatHeaterRearLeftBack) seatHeaterRearRight = try? container.decode(Int.self, forKey: .seatHeaterRearRight) seatHeaterRearRightBack = try? container.decode(Int.self, forKey: .seatHeaterRearRightBack) seatHeaterRight = try? container.decode(Int.self, forKey: .seatHeaterRight)

Simple fix to the file :) Only the lines above are affected.

Other than that I think it works as it should, atleast for now. Another thing, when streaming from the car, do you know if there are a time limit on the stream from Tesla servers? I cant stream for more than 20-21minutes before I have restart the stream..

EDIT: Need theese changes in VehicleConfig also as it is an int returned, not bool: (0-3) An X came back with: "rear_seat_heaters":3

Line 25-26 From:

To:

Line 51 From:

To:

Line 81 From:

To:

Line 112 From:

To:

Morten

jonasman commented 5 years ago

sorry i didnt have time. I can look at this soon.

jonasman commented 5 years ago

https://github.com/jonasman/TeslaSwift/commit/b388315e927b02060de86e522fd3d0194027a911 https://github.com/jonasman/TeslaSwift/commit/c1b0c8cf29f751eba3c110a37d7d9ace63d6c5c4 @mortimern all fixed

jonasman commented 5 years ago

tag 4.6.1