Skip to content

Commit

Permalink
Merge pull request #631 from alandtse/dev
Browse files Browse the repository at this point in the history
chore: 2023-06-13 release
  • Loading branch information
alandtse authored Jun 13, 2023
2 parents 423e616 + 66850bb commit 24760f6
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 213 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ repos:
)$
rev: v3.0.0-alpha.9-for-vscode
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.6.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/prospector
rev: 1.10.1
rev: 1.10.2
hooks:
- id: prospector
exclude: ^(tests)/.+\.py$
Expand All @@ -92,7 +92,7 @@ repos:
# pass_filenames: false
# always_run: true
- repo: https://github.com/floatingpurr/sync_with_poetry
rev: "0.4.0" # the revision or tag to clone at
rev: "1.0.0" # the revision or tag to clone at
hooks:
- id: sync_with_poetry
args: [] # optional args
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def async_set_temperature(self, **kwargs):
temp = round(temperature, 1)

await self._car.set_temperature(temp)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
Expand Down
16 changes: 8 additions & 8 deletions custom_components/tesla_custom/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ async def async_close_cover(self, **kwargs):
"""Send close cover command."""
_LOGGER.debug("Closing cover: %s", self.name)
await self._car.charge_port_door_close()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand All @@ -86,14 +86,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.toggle_frunk()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.toggle_frunk()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down Expand Up @@ -130,14 +130,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.toggle_trunk()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.toggle_trunk()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down Expand Up @@ -176,14 +176,14 @@ async def async_close_cover(self, **kwargs):
_LOGGER.debug("Closing cover: %s", self.name)
if self.is_closed is False:
await self._car.close_windows()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_open_cover(self, **kwargs):
"""Send open cover command."""
_LOGGER.debug("Opening cover: %s", self.name)
if self.is_closed is True:
await self._car.vent_windows()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_closed(self):
Expand Down
8 changes: 4 additions & 4 deletions custom_components/tesla_custom/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ async def async_lock(self, **kwargs):
"""Send lock command."""
_LOGGER.debug("Locking: %s", self.name)
await self._car.lock()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_unlock(self, **kwargs):
"""Send unlock command."""
_LOGGER.debug("Unlocking: %s", self.name)
await self._car.unlock()
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def is_locked(self):
Expand All @@ -77,13 +77,13 @@ async def async_open(self, **kwargs):
"""Send open command."""
_LOGGER.debug("Opening: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_unlock(self, **kwargs):
"""Send unlock command."""
_LOGGER.debug("Unlocking: %s", self.name)
await self._car.charge_port_door_open()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_lock(self, **kwargs):
"""Log lock command not possible."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/alandtse/tesla/issues",
"loggers": ["teslajsonpy"],
"requirements": ["teslajsonpy==3.8.1"],
"requirements": ["teslajsonpy==3.9.0"],
"version": "3.12.3"
}
6 changes: 3 additions & 3 deletions custom_components/tesla_custom/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update charge limit."""
await self._car.change_charge_limit(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update charging amps."""
await self._car.set_charging_amps(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(
async def async_set_native_value(self, value: int) -> None:
"""Update backup reserve percentage."""
await self._energysite.set_reserve_percent(value)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def native_value(self) -> int:
Expand Down
83 changes: 79 additions & 4 deletions custom_components/tesla_custom/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
"Auto",
]

STEERING_HEATER_OPTIONS = [
"Off",
"Low",
"High",
"Auto",
]

STEERING_HEATER_OPTIONS_MAP = {"Off": 0, "Low": 1, "High": 3}

OPERATION_MODE = [
"Self-Powered",
"Time-Based Control",
Expand Down Expand Up @@ -78,6 +87,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry, async_add_entitie
for vin, car in cars.items():
coordinator = coordinators[vin]
entities.append(TeslaCarCabinOverheatProtection(hass, car, coordinator))
entities.append(TeslaCarHeatedSteeringWheel(hass, car, coordinator))
for seat_name in SEAT_ID_MAP:
if "rear" in seat_name and not car.rear_seat_heaters:
continue
Expand Down Expand Up @@ -172,6 +182,71 @@ def options(self):
return HEATER_OPTIONS


class TeslaCarHeatedSteeringWheel(TeslaCarEntity, SelectEntity):
"""Representation of a Tesla car heated steering wheel select."""

def __init__(
self,
hass: HomeAssistant,
car: TeslaCar,
coordinator: TeslaDataUpdateCoordinator,
):
"""Initialize heated seat entity."""
super().__init__(hass, car, coordinator)
self.type = "heated steering wheel"
self._attr_icon = "mdi:steering"
self._enabled_by_default = self._car.steering_wheel_heater

async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""

if option == STEERING_HEATER_OPTIONS[3]:
_LOGGER.debug("Setting Heated Steering to Auto")
await self._car.remote_auto_steering_wheel_heat_climate_request(True)
else:
level: int = STEERING_HEATER_OPTIONS_MAP[option]

await self._car.remote_auto_steering_wheel_heat_climate_request(False)

if not self._car.is_climate_on and level > 0:
await self._car.set_hvac_mode("on")

_LOGGER.debug("Setting Heated Steering to %s", level)
await self._car.set_heated_steering_wheel_level(level)

await self.update_controller(force=True)

@property
def current_option(self):
"""Return current heated steering setting."""
if self._car.is_auto_steering_wheel_heat is True:
current_str = "Auto"
else:
current_value = self._car.get_heated_steering_wheel_level()
current_str = next(
(
key
for key, val in STEERING_HEATER_OPTIONS_MAP.items()
if val == current_value
),
None,
)

options_idx = STEERING_HEATER_OPTIONS.index(current_str)

return STEERING_HEATER_OPTIONS[options_idx]

@property
def options(self):
"""Return heated seat options."""
return STEERING_HEATER_OPTIONS

@property
def available(self) -> bool:
"""Return True if steering wheel heater is available."""
return super().available and self._car.steering_wheel_heater


class TeslaCarCabinOverheatProtection(TeslaCarEntity, SelectEntity):
"""Representation of a Tesla car cabin overheat protection select."""

Expand All @@ -191,7 +266,7 @@ def __init__(
async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""
await self._car.set_cabin_overheat_protection(option)
await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self):
Expand Down Expand Up @@ -220,7 +295,7 @@ async def async_select_option(self, option: str, **kwargs):
else:
await self._energysite.set_grid_charging(False)

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self):
Expand Down Expand Up @@ -259,7 +334,7 @@ async def async_select_option(self, option: str, **kwargs):
if option == EXPORT_RULE[1]:
await self._energysite.set_export_rule("battery_ok")

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self) -> str:
Expand Down Expand Up @@ -295,7 +370,7 @@ async def async_select_option(self, option: str, **kwargs):
if option == OPERATION_MODE[2]:
await self._energysite.set_operation_mode("backup")

await self.async_update_ha_state()
self.async_write_ha_state()

@property
def current_option(self) -> str:
Expand Down
24 changes: 12 additions & 12 deletions custom_components/tesla_custom/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(
super().__init__(hass, car, coordinator)
self.type = "heated steering"
self._attr_icon = "mdi:steering"
# Entity is only enabled upon first install if steering wheel heater is available
self._enabled_by_default = self._car.steering_wheel_heater
# Entity is disabled for new installs, as Select has been created.
self._enabled_by_default = False

@property
def available(self) -> bool:
Expand All @@ -60,12 +60,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.set_heated_steering_wheel(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.set_heated_steering_wheel(False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarPolling(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -95,13 +95,13 @@ async def async_turn_on(self, **kwargs):
"""Send the on command."""
_LOGGER.debug("Enable polling: %s %s", self.name, self._car.vin)
self._coordinator.controller.set_updates(vin=self._car.vin, value=True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
_LOGGER.debug("Disable polling: %s %s", self.name, self._car.vin)
self._coordinator.controller.set_updates(vin=self._car.vin, value=False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarCharger(TeslaCarEntity, SwitchEntity):
Expand All @@ -126,12 +126,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.start_charge()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.stop_charge()
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarSentryMode(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -169,12 +169,12 @@ def is_on(self):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
await self._car.set_sentry_mode(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
await self._car.set_sentry_mode(False)
await self.async_update_ha_state()
self.async_write_ha_state()


class TeslaCarValetMode(TeslaCarEntity, SwitchEntity):
Expand Down Expand Up @@ -203,7 +203,7 @@ async def async_turn_on(self, **kwargs):
_LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.")
else:
await self._car.valet_mode(True)
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
"""Send the off command."""
Expand All @@ -212,4 +212,4 @@ async def async_turn_off(self, **kwargs):
_LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.")
else:
await self._car.valet_mode(False)
await self.async_update_ha_state()
self.async_write_ha_state()
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def async_set_value(self, value: str) -> None:

await self.teslsmate.set_car_id(self._car.vin, value)
await self.teslsmate.watch_cars()
await self.async_update_ha_state()
self.async_write_ha_state()

async def async_update(self) -> None:
"""Update the entity."""
Expand Down
Loading

0 comments on commit 24760f6

Please sign in to comment.