Skip to content

Commit

Permalink
tigher controls over climate Refresh hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Megabytemb committed Apr 24, 2022
1 parent 4a4bba6 commit bfd8cb5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
_LOGGER = logging.getLogger(__name__)

SUPPORT_HVAC = [HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF]
import pprint


async def async_setup_entry(hass, config_entry, async_add_entities):
Expand Down Expand Up @@ -143,6 +144,15 @@ async def update_climate_related_devices(self):
# this does not cause an api call, but instead enabled the undering device
# to read from the shared climate data cache in the teslajsonpy library.

# First, we need to force the controller to update, as the refresh functions asume it
# has been uddated.
# 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.

await self.tesla_device._controller.update(
self.tesla_device._id, wake_if_asleep=False, force=True
)

climate_devices = [
["switch", "heated steering switch"],
["select", "heated seat left"],
Expand All @@ -153,11 +163,15 @@ async def update_climate_related_devices(self):
]

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]
)
if device is not None:
class_name = device.__class__.__name__
attr_str = f"_{class_name}__manual_update_time"
setattr(device, attr_str, 0)
await device.async_update(force=True, wake_if_asleep=False)

# Does not cause an API call.
device.refresh()

0 comments on commit bfd8cb5

Please sign in to comment.