From f630ec3b7dce2688090ce09bf24bdc9886d9c314 Mon Sep 17 00:00:00 2001 From: Michael Benz Date: Mon, 2 May 2022 03:03:56 +0000 Subject: [PATCH 1/4] Turn on climate for the same car. --- custom_components/tesla_custom/helpers.py | 8 +++++--- custom_components/tesla_custom/select.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/custom_components/tesla_custom/helpers.py b/custom_components/tesla_custom/helpers.py index ffe7597e..12d16faa 100644 --- a/custom_components/tesla_custom/helpers.py +++ b/custom_components/tesla_custom/helpers.py @@ -19,6 +19,7 @@ async def get_device( config_entry_id: str, device_category: str, device_type: str, + vin: str, ): """Get a tesla Device for a Config Entry ID.""" @@ -26,7 +27,8 @@ async def get_device( devices = entry_data["devices"].get(device_category, []) for device in devices: - if device.type == device_type: + # pylint: disable=protected-access + if device.type == device_type and device._vin == vin: return device return None @@ -68,14 +70,14 @@ def enable_entity( async def wait_for_climate( - hass: HomeAssistant, config_entry_id: str, timeout: int = 30 + hass: HomeAssistant, config_entry_id: str, vin: str, timeout: int = 30 ): """Wait for HVac. Optional Timeout. defaults to 30 seconds """ climate_device = await get_device( - hass, config_entry_id, "climate", "HVAC (climate) system" + hass, config_entry_id, "climate", "HVAC (climate) system", vin ) if climate_device is None: diff --git a/custom_components/tesla_custom/select.py b/custom_components/tesla_custom/select.py index 59682de1..7f4ba50e 100644 --- a/custom_components/tesla_custom/select.py +++ b/custom_components/tesla_custom/select.py @@ -35,7 +35,8 @@ async def async_select_option(self, option: str, **kwargs): """Change the selected option.""" level: int = OPTIONS.index(option) - await wait_for_climate(self.hass, self.config_entry_id) + # pylint: disable=protected-access + await wait_for_climate(self.hass, self.config_entry_id, self.tesla_device._vin) _LOGGER.debug("Setting %s to %s", self.name, level) await self.tesla_device.set_seat_heat_level(level) self.async_write_ha_state() From 157acab57a94bc3cfc4af426fe7b54b83deeccc5 Mon Sep 17 00:00:00 2001 From: Michael Benz Date: Mon, 2 May 2022 03:09:43 +0000 Subject: [PATCH 2/4] Use Proper Accesses --- custom_components/tesla_custom/climate.py | 6 +++++- custom_components/tesla_custom/helpers.py | 2 +- custom_components/tesla_custom/select.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/tesla_custom/climate.py b/custom_components/tesla_custom/climate.py index 150426b0..b1eea7f1 100644 --- a/custom_components/tesla_custom/climate.py +++ b/custom_components/tesla_custom/climate.py @@ -157,6 +157,7 @@ def refresh(self) -> None: vin = self.tesla_device.vin() # Get all the climate parameters so we can determine what is supported by this vin. + # pylint: disable=protected-access climate_params = self.tesla_device._controller.get_climate_params(vin=vin) if climate_params is None or len(climate_params) == 0: # No data available @@ -203,15 +204,18 @@ async def update_climate_related_devices(self): # We have to manually update the controller becuase changing the HVAC state only updates its state in Home assistant, # and not the underlying cache in cliamte_parms. This does mean we talk to Tesla, but we only do so Once. + # pylint: disable=protected-access await self.tesla_device._controller.update( self.tesla_device._id, wake_if_asleep=False, force=True ) + vin = self.tesla_device.vin() + for c_device in CLIMATE_DEVICES: _LOGGER.debug("Refreshing Device: %s.%s", c_device[0], c_device[1]) device = await get_device( - self.hass, self.config_entry_id, c_device[0], c_device[1] + self.hass, self.config_entry_id, c_device[0], c_device[1], vin ) if device is not None: class_name = device.__class__.__name__ diff --git a/custom_components/tesla_custom/helpers.py b/custom_components/tesla_custom/helpers.py index 12d16faa..dcf7817d 100644 --- a/custom_components/tesla_custom/helpers.py +++ b/custom_components/tesla_custom/helpers.py @@ -28,7 +28,7 @@ async def get_device( for device in devices: # pylint: disable=protected-access - if device.type == device_type and device._vin == vin: + if device.type == device_type and device.vin() == vin: return device return None diff --git a/custom_components/tesla_custom/select.py b/custom_components/tesla_custom/select.py index 7f4ba50e..8b91987f 100644 --- a/custom_components/tesla_custom/select.py +++ b/custom_components/tesla_custom/select.py @@ -35,8 +35,8 @@ async def async_select_option(self, option: str, **kwargs): """Change the selected option.""" level: int = OPTIONS.index(option) - # pylint: disable=protected-access - await wait_for_climate(self.hass, self.config_entry_id, self.tesla_device._vin) + vin = self.tesla_device.vin() + await wait_for_climate(self.hass, self.config_entry_id, vin) _LOGGER.debug("Setting %s to %s", self.name, level) await self.tesla_device.set_seat_heat_level(level) self.async_write_ha_state() From ea0f08dcefbc62892850ea2b25a1a0616b509188 Mon Sep 17 00:00:00 2001 From: Michael Benz Date: Mon, 2 May 2022 03:10:55 +0000 Subject: [PATCH 3/4] remove unneeded exclusion --- custom_components/tesla_custom/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/custom_components/tesla_custom/helpers.py b/custom_components/tesla_custom/helpers.py index dcf7817d..3b60e77c 100644 --- a/custom_components/tesla_custom/helpers.py +++ b/custom_components/tesla_custom/helpers.py @@ -27,7 +27,6 @@ async def get_device( devices = entry_data["devices"].get(device_category, []) for device in devices: - # pylint: disable=protected-access if device.type == device_type and device.vin() == vin: return device From 9da55232389633d5189e95d9ef501afa87aed2f2 Mon Sep 17 00:00:00 2001 From: Michael Benz Date: Mon, 2 May 2022 04:05:19 +0000 Subject: [PATCH 4/4] Update heated Steering wheel. --- custom_components/tesla_custom/switch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/tesla_custom/switch.py b/custom_components/tesla_custom/switch.py index 24726825..f0d5b003 100644 --- a/custom_components/tesla_custom/switch.py +++ b/custom_components/tesla_custom/switch.py @@ -35,7 +35,10 @@ class HeatedSteeringWheelSwitch(TeslaDevice, SwitchEntity): async def async_turn_on(self, **kwargs): """Send the on command.""" _LOGGER.debug("Turn on Heating Steering Wheel: %s", self.name) - await wait_for_climate(self.hass, self.config_entry_id) + + vin = self.tesla_device.vin() + await wait_for_climate(self.hass, self.config_entry_id, vin) + await self.tesla_device.set_steering_wheel_heat(True) self.async_write_ha_state()