Update sunroof feature to changed Tesla API (#12031)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2022-01-12 08:41:10 +01:00 committed by GitHub
parent a925fb52d0
commit b7e78e3a0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 36 deletions

View File

@ -180,8 +180,8 @@ Additionally, these advanced channels are available (not all are available on al
| soc | Number | State of Charge | State of Charge, in % |
| state | String | State | “online”, “asleep”, “waking” |
| steeringwheelheater | Switch | Steering Wheel Heater | Indicates if the steering wheel heater is switched on |
| sunroofstate | String | Sunroof State | “unknown”, “open”, “closed”, “vent”, “comfort” |
| sunroof | Dimmer | Sunroof | Open or close the sunroof to provided % (0 closed, 100 fully open) |
| sunroofstate | String | Sunroof State | Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent". |
| sunroof | Dimmer | Sunroof | Indicates the opening state of the sunroof (0% closed, 100% fully open) |
| temperature | Number:Temperature | Temperature | Set the temperature of the autoconditioning system. The temperature for the driver and passenger will be synced. |
| timetofullcharge | Number | Time To Full Charge | Number of hours to fully charge the battery |
| tripcharging | Switch | Trip Charging | Not documented / To be defined |

View File

@ -290,22 +290,6 @@ public class TeslaVehicleHandler extends BaseThingHandler {
}
break;
}
case SUN_ROOF: {
if (command instanceof PercentType) {
moveSunroof(((PercentType) command).intValue());
} else if (command instanceof OnOffType && command == OnOffType.ON) {
moveSunroof(100);
} else if (command instanceof OnOffType && command == OnOffType.OFF) {
moveSunroof(0);
} else if (command instanceof IncreaseDecreaseType
&& command == IncreaseDecreaseType.INCREASE) {
moveSunroof(Math.min(vehicleState.sun_roof_percent_open + 1, 100));
} else if (command instanceof IncreaseDecreaseType
&& command == IncreaseDecreaseType.DECREASE) {
moveSunroof(Math.max(vehicleState.sun_roof_percent_open - 1, 0));
}
break;
}
case CHARGE_TO_MAX: {
if (command instanceof OnOffType) {
if (((OnOffType) command) == OnOffType.ON) {
@ -582,18 +566,14 @@ public class TeslaVehicleHandler extends BaseThingHandler {
}
public void setSunroof(String state) {
JsonObject payloadObject = new JsonObject();
payloadObject.addProperty("state", state);
sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget);
requestData(VEHICLE_STATE);
}
public void moveSunroof(int percent) {
JsonObject payloadObject = new JsonObject();
payloadObject.addProperty("state", "move");
payloadObject.addProperty("percent", percent);
sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget);
requestData(VEHICLE_STATE);
if (state.equals("vent") || state.equals("close")) {
JsonObject payloadObject = new JsonObject();
payloadObject.addProperty("state", state);
sendCommand(COMMAND_SUN_ROOF, gson.toJson(payloadObject), account.commandTarget);
requestData(VEHICLE_STATE);
} else {
logger.warn("Ignoring invalid command '{}' for sunroof.", state);
}
}
/**

View File

@ -252,9 +252,11 @@ channel-type.tesla.state.description = “online”, “asleep”, “waking”
channel-type.tesla.steeringwheelheater.label = Steering Wheel Heater
channel-type.tesla.steeringwheelheater.description = Indicates if the steering wheel heater is switched on
channel-type.tesla.sunroof.label = Sunroof
channel-type.tesla.sunroof.description = Open or close the sunroof to provided % (0 closed, 100 fully open)
channel-type.tesla.sunroof.description = Indicates the opening state of the sunroof (0% closed, 100% fully open)
channel-type.tesla.sunroofstate.label = Sunroof State
channel-type.tesla.sunroofstate.description = “unknown”, “open”, “closed”, “vent”, “comfort”
channel-type.tesla.sunroofstate.description = Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent".
channel-type.tesla.sunroofstate.command.option.close = close
channel-type.tesla.sunroofstate.command.option.vent = vent
channel-type.tesla.timetofullcharge.label = Time To Full Charge
channel-type.tesla.timetofullcharge.description = Number of hours to fully charge the battery
channel-type.tesla.tripcharging.label = Trip Charging

View File

@ -583,14 +583,19 @@
<channel-type id="sunroofstate" advanced="true">
<item-type>String</item-type>
<label>Sunroof State</label>
<description>“unknown”, “open”, “closed”, “vent”, “comfort”</description>
<state readOnly="true"></state>
<description>Valid states are “unknown”, “open”, “closed”, “vent”, “comfort”. Accepts commands "close" and "vent".</description>
<command>
<options>
<option value="close">close</option>
<option value="vent">vent</option>
</options>
</command>
</channel-type>
<channel-type id="sunroof">
<item-type>Dimmer</item-type>
<label>Sunroof</label>
<description>Open or close the sunroof to provided % (0 closed, 100 fully open)</description>
<state pattern="%d %%"></state>
<description>Indicates the opening state of the sunroof (0% closed, 100% fully open)</description>
<state pattern="%d %%" readOnly="true"></state>
</channel-type>
<channel-type id="combinedtemp" advanced="true">
<item-type>Number:Temperature</item-type>