Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Nissan leaf climate control (icon + fire & forget) #62855

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 3 additions & 28 deletions homeassistant/components/nissan_leaf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,41 +423,16 @@ async def async_get_climate(self):

async def async_set_climate(self, toggle):
"""Set climate control mode via Nissan servers."""
climate_result = None
if toggle:
_LOGGER.debug("Requesting climate turn on for %s", self.leaf.vin)
set_function = self.leaf.start_climate_control
result_function = self.leaf.get_start_climate_control_result
else:
_LOGGER.debug("Requesting climate turn off for %s", self.leaf.vin)
set_function = self.leaf.stop_climate_control
result_function = self.leaf.get_stop_climate_control_result

request = await self.hass.async_add_executor_job(set_function)
for attempt in range(MAX_RESPONSE_ATTEMPTS):
if attempt > 0:
_LOGGER.debug(
"Climate data not in yet (%s) (%s). Waiting (%s) seconds",
self.leaf.vin,
attempt,
PYCARWINGS2_SLEEP,
)
await asyncio.sleep(PYCARWINGS2_SLEEP)

climate_result = await self.hass.async_add_executor_job(
result_function, request
)

if climate_result is not None:
break

if climate_result is not None:
_LOGGER.debug("Climate result: %s", climate_result.__dict__)
async_dispatcher_send(self.hass, SIGNAL_UPDATE_LEAF)
return climate_result.is_hvac_running == toggle

_LOGGER.debug("Climate result not returned by Nissan servers")
return False
# Setting climate control is now a fire and forget
await self.hass.async_add_executor_job(set_function)
return True


class LeafEntity(Entity):
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/nissan_leaf/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def is_on(self):
"""Return true if climate control is on."""
return self.car.data[DATA_CLIMATE]

@property
def icon(self):
"""Return a representative icon."""
if self.car.data[DATA_CLIMATE]:
return "mdi:fan"
return "mdi:fan-off"

async def async_turn_on(self, **kwargs):
"""Turn on climate control."""
if await self.car.async_set_climate(True):
Expand Down