Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions custom_components/panasonic_cc/panasonic/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import logging
import time
from dataclasses import dataclass
from typing import Any

Expand Down Expand Up @@ -148,6 +149,7 @@ def __init__(
) -> None:
"""Initialize the climate entity."""
self.entity_description = description
self._off_command_at: float | None = None
device = coordinator.device
hvac_modes = [HVACMode.OFF]
if device.features.auto_mode:
Expand Down Expand Up @@ -196,14 +198,24 @@ def __init__(
def _async_update_attrs(self) -> None:
"""Update attributes."""
state = self.coordinator.device.parameters
self._attr_hvac_mode = (
HVACMode.OFF
if state.power == constants.Power.Off
else convert_operation_mode_to_hvac_mode(
if state.power == constants.Power.Off:
self._off_command_at = None
self._attr_hvac_mode = HVACMode.OFF
self._attr_hvac_action = HVACAction.OFF
elif (
self._off_command_at is not None
and (time.monotonic() - self._off_command_at) < 10.0
and state.power == constants.Power.On
):
self._attr_hvac_mode = HVACMode.OFF
self._attr_hvac_action = HVACAction.OFF
else:
if self._off_command_at is not None:
self._off_command_at = None
self._attr_hvac_mode = convert_operation_mode_to_hvac_mode(
state.mode,
state.iautox_mode == constants.IAutoXMode.On,
)
)

self._set_temp_range()
self._attr_current_temperature = state.inside_temperature
Expand All @@ -221,7 +233,7 @@ def _async_update_attrs(self) -> None:
self._attr_preset_mode = self._powerful_preset
else:
self._attr_preset_mode = PRESET_NONE
if self.coordinator.device.has_inside_temperature:
if self.coordinator.device.has_inside_temperature and self._attr_hvac_mode != HVACMode.OFF:
self._attr_hvac_action = convert_state_to_hvac_action(state)

def _set_temp_range(self) -> None:
Expand Down Expand Up @@ -283,7 +295,9 @@ async def async_turn_off(self) -> None:
builder.set_power_mode(constants.Power.Off)
await self.coordinator.async_apply_changes(builder)
await self.coordinator.async_schedule_refresh()
self._off_command_at = time.monotonic()
self._attr_hvac_mode = HVACMode.OFF
self._attr_hvac_action = HVACAction.OFF
except Exception:
_LOGGER.exception(
"Failed to turn off device %s",
Expand Down