Skip to content

Commit

Permalink
Merge pull request #246 from robinostlund/charging_control
Browse files Browse the repository at this point in the history
Re-enable charging control
  • Loading branch information
robinostlund authored Jan 31, 2024
2 parents 29f1a5b + 2cf5b3a commit 7aaaca8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 11 additions & 6 deletions volkswagencarnet/vw_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,30 +782,35 @@ async def setClimater(self, vin, data, action):

async def setWindowHeater(self, vin, action):
"""Execute window heating actions."""

action = "start" if action else "stop"

try:
response_raw = await self.post(
f"{BASE_API}/vehicle/v1/vehicles/{vin}/windowheating/{action}", json={}, return_raw=True
)
return await self._handle_action_result(response_raw)

except Exception as e:
raise Exception("Unknown error during setWindowHeater") from e

async def setCharging(self, vin, action):
"""Execute charging actions."""
action = "start" if action else "stop"
try:
response_raw = await self.post(
f"{BASE_API}/vehicle/v1/vehicles/{vin}/charging/{action}", json={}, return_raw=True
)
return await self._handle_action_result(response_raw)
except Exception as e:
raise Exception("Unknown error during setCharging") from e

async def setLock(self, vin, lock, spin):
"""Remote lock and unlock actions."""
await self.check_spin_state()

action = "lock" if lock else "unlock"

try:
response_raw = await self.post(
f"{BASE_API}/vehicle/v1/vehicles/{vin}/access/{action}", json={"spin": spin}, return_raw=True
)
return await self._handle_action_result(response_raw)

except Exception as e:
raise Exception("Unknown error during setLock") from e

Expand Down
18 changes: 13 additions & 5 deletions volkswagencarnet/vw_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,18 @@ async def set_charge_min_level(self, level: int):
raise Exception("Should have to be re-implemented")

async def set_charger(self, action) -> bool:
"""Charging actions."""
raise Exception("Should have to be re-implemented")
"""Turn on/off window charging."""
if self.is_charging_supported:
if action not in ["start", "stop"]:
_LOGGER.error(f'Charging action "{action}" is not supported.')
raise Exception(f'Charging action "{action}" is not supported.')
response = await self._connection.setCharging(self.vin, (action == "start"))
return await self._handle_response(
response=response, topic="charging", error_msg=f"Failed to {action} charging"
)
else:
_LOGGER.error("No charging support.")
raise Exception("No charging support.")

# Climatisation electric/auxiliary/windows (CLIMATISATION)
async def set_climatisation_temp(self, temperature=20):
Expand Down Expand Up @@ -769,9 +779,7 @@ def charging_last_updated(self) -> datetime:
@property
def is_charging_supported(self) -> bool:
"""Return true if charging is supported."""
# return is_valid_path(self.attrs, f"{Services.CHARGING}.chargingStatus.value.chargingState")
# CURRENTLY NOT SUPPORTED
return False
return is_valid_path(self.attrs, f"{Services.CHARGING}.chargingStatus.value.chargingState")

@property
def charging_power(self) -> int:
Expand Down

0 comments on commit 7aaaca8

Please sign in to comment.