Skip to content

Commit

Permalink
Expose LG's sleep mode function
Browse files Browse the repository at this point in the history
  • Loading branch information
ldotlopez committed Aug 17, 2023
1 parent 706dd45 commit 26fdc93
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions custom_components/smartthinq_sensors/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ def _async_discover_device(lge_devices: dict) -> None:
]
)

# add AC sleep mode switch
lge_switch.extend(
[
LGESleepModeSwitch(lge_device)
for lge_device in lge_devices.get(DeviceType.AC, [])
]
)

# add MicroWave switch
lge_switch.extend(
[
Expand Down Expand Up @@ -345,3 +353,28 @@ async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
self._wrap_device.device.set_duct_zone(self._zone, True)
self._api.async_set_updated()


class LGESleepModeSwitch(LGESwitch):
"""Class to control LGE AC reservation sleep time as switch"""

def __init__(self, api: LGEDevice):
desc = ThinQSwitchEntityDescription(
key=AirConditionerFeatures.RESERVATION_SLEEP_TIME,
name="Sleep mode",
icon="mdi:weather-night",
available_fn=lambda x: x.device.is_reservation_sleep_time_available,
turn_off_fn=lambda x: x.device.set_reservation_sleep_time(0),
turn_on_fn=lambda x: x.device.set_reservation_sleep_time(60 * 7),
)
super().__init__(api, desc)

@property
def is_on(self):
"""Return the state of the switch."""
return self._get_switch_state() > 0

# No sure if this should be a sensor
# @property
# def extra_state_attributes(self):
# return {"Remaining time (in minutes)": self._get_switch_state()}
1 change: 1 addition & 0 deletions custom_components/smartthinq_sensors/wideq/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AirConditionerFeatures(StrEnum):
ROOM_TEMP = "room_temperature"
WATER_IN_TEMP = "water_in_temperature"
WATER_OUT_TEMP = "water_out_temperature"
RESERVATION_SLEEP_TIME = "reservation_sleep_time"


class AirPurifierFeatures(StrEnum):
Expand Down
32 changes: 32 additions & 0 deletions custom_components/smartthinq_sensors/wideq/devices/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from enum import Enum
import logging
from math import ceil

from ..const import AirConditionerFeatures, TemperatureUnit
from ..core_async import ClientAsync
Expand Down Expand Up @@ -61,6 +62,7 @@
STATE_MODE_AIRCLEAN = ["AirClean", "airState.wMode.airClean"]
STATE_MODE_JET = ["Jet", "airState.wMode.jet"]
STATE_LIGHTING_DISPLAY = ["DisplayControl", "airState.lightingState.displayControl"]
STATE_RESERVATION_SLEEP_TIME = ["SleepTime", "airState.reservation.sleepTime"]

FILTER_TYPES = [
[
Expand All @@ -87,6 +89,7 @@
CMD_STATE_MODE_AIRCLEAN = [CTRL_BASIC, "Set", STATE_MODE_AIRCLEAN]
CMD_STATE_MODE_JET = [CTRL_BASIC, "Set", STATE_MODE_JET]
CMD_STATE_LIGHTING_DISPLAY = [CTRL_BASIC, "Set", STATE_LIGHTING_DISPLAY]
CMD_RESERVATION_SLEEP_TIME = [CTRL_BASIC, "Set", STATE_RESERVATION_SLEEP_TIME]

# AWHP Section
STATE_WATER_IN_TEMP = ["WaterInTempCur", "airState.tempState.inWaterCurrent"]
Expand Down Expand Up @@ -866,6 +869,24 @@ async def get_filter_state_v2(self):
self._filter_status_supported = False
return None

async def set_reservation_sleep_time(self, value: float):
keys = self._get_cmd_keys(CMD_RESERVATION_SLEEP_TIME)
await self.set(
keys[0], # "basicCtrl",
keys[1], # "Set",
key=keys[2], # key="airState.reservation.sleepTime",
value=str(ceil(value)),
)

@property
def is_reservation_sleep_time_available(self):
value = self._status.is_on and (
self._status.operation_mode
in [ACMode.ACO.name, ACMode.FAN.name, ACMode.COOL.name, ACMode.DRY.name]
)

return value

async def set(
self, ctrl_key, command, *, key=None, value=None, data=None, ctrl_path=None
):
Expand Down Expand Up @@ -1274,6 +1295,16 @@ def hot_water_target_max_temp(self):
key = self._get_state_key(STATE_HOT_WATER_MAX_TEMP)
return self._str_to_temp(self._data.get(key))

@property
def reservation_sleep_time(self):
"""Return display lighting status."""
key = self._get_state_key(STATE_RESERVATION_SLEEP_TIME)
value = float(self._data.get(key))

return self._update_feature(
AirConditionerFeatures.RESERVATION_SLEEP_TIME, value, False
)

def _update_features(self):
_ = [
self.current_temp,
Expand All @@ -1287,4 +1318,5 @@ def _update_features(self):
self.water_out_current_temp,
self.mode_awhp_silent,
self.hot_water_current_temp,
self.reservation_sleep_time,
]

0 comments on commit 26fdc93

Please sign in to comment.