Skip to content

Commit

Permalink
Maintenance
Browse files Browse the repository at this point in the history
- Implemented "WakeUp" service for washer and dryer
- Saved remote start status before suspension
- Fixed "Remote Start" for ThinQ1 washer and dryer
- Review "Remote Start" for ThinQ2 washer and dryer (based on saved status)
  • Loading branch information
ollo69 committed Jun 8, 2021
1 parent a1aa25b commit 6777da4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
12 changes: 12 additions & 0 deletions custom_components/smartthinq_sensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

# service definition
SERVICE_REMOTE_START = "remote_start"
SERVICE_WAKE_UP = "wake_up"

# sensor definition
ATTR_MEASUREMENT_NAME = "measurement_name"
Expand Down Expand Up @@ -506,6 +507,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
None,
"async_remote_start",
)
platform.async_register_entity_service(
SERVICE_WAKE_UP,
None,
"async_wake_up",
)


class LGESensor(CoordinatorEntity):
Expand Down Expand Up @@ -674,6 +680,12 @@ async def async_remote_start(self):
raise NotImplementedError()
await self.hass.async_add_executor_job(self._api.device.remote_start)

async def async_wake_up(self):
"""Call the wakeup command for WM devices."""
if self._api.type not in WM_DEVICE_TYPES:
raise NotImplementedError()
await self.hass.async_add_executor_job(self._api.device.wake_up)


class LGEWashDeviceSensor(LGESensor):
"""A sensor to monitor LGE Wash devices"""
Expand Down
14 changes: 14 additions & 0 deletions custom_components/smartthinq_sensors/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@ remote_start:
entity:
integration: smartthinq_sensors
domain: sensor

wake_up:
name: WakeUp
description: Send to ThinQ device the wakeup command.
fields:
entity_id:
name: Entity Name
description: Name of the target entity
required: true
example: "sensor.washer"
selector:
entity:
integration: smartthinq_sensors
domain: sensor
42 changes: 32 additions & 10 deletions custom_components/smartthinq_sensors/wideq/washerDryer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
POWER_STATUS_KEY = ["State", "state"]

CMD_POWER_OFF = [["Control", "WMControl"], ["Power", "WMOff"], ["Off", None]]
CMD_WAKE_UP = [["Control", "WMControl"], ["Operation", "WMWakeup"], ["WakeUp", None]]
CMD_REMOTE_START = [["Control", "WMStart"], ["OperationStart", "WMStart"], ["Start", "WMStart"]]

_LOGGER = logging.getLogger(__name__)
Expand All @@ -63,6 +64,7 @@ class WMDevice(Device):
"""A higher-level interface for washer and dryer."""
def __init__(self, client, device):
super().__init__(client, device, WMStatus(self, None))
self._remote_start_status = None

def _update_status(self, key, value):
if self._status:
Expand All @@ -75,7 +77,7 @@ def _prepare_command_v1(self, cmd, key, value):
"""Prepare command for specific ThinQ1 device."""
if "data" in cmd:
str_data = cmd["data"]
status_data = self._status.data
status_data = self._remote_start_status
for dt_key, dt_value in status_data.items():
# for start command we set initial bit to 1, assuming that
# is the 1st bit of Option2. This probably should be reviewed
Expand All @@ -86,8 +88,9 @@ def _prepare_command_v1(self, cmd, key, value):
_LOGGER.debug("Command data content: %s", str_data)
encode = cmd.pop("encode", False)
if encode:
cmd["format"] = "B64"
str_list = json.loads(str_data)
str_data = base64.b64encode(bytes(str_list)).decode("utf-8")
str_data = base64.b64encode(bytes(str_list)).decode("ascii")
cmd["data"] = str_data
return cmd

Expand All @@ -98,23 +101,29 @@ def _prepare_command_v2(self, cmd, key, value):
return cmd

if key and key == "WMStart":
status_data = self._status.data
status_data = self._remote_start_status
n_course_key = self.model_info.config_value("courseType")
s_course_key = self.model_info.config_value("smartCourseType")
cmd_data_set = {}

for cmd_key, cmd_value in data_set[WM_ROOT_DATA].items():
if cmd_key in ["course", "Course", "ApCourse", n_course_key]:
course_type = self._status.lookup_reference(n_course_key, ref_key="courseType")
course_data = status_data.get(n_course_key, "NOT_SELECTED")
course_type = self.model_info.reference_name(
n_course_key, course_data, ref_key="courseType"
)
if course_type:
cmd_data_set[n_course_key] = status_data.get(n_course_key)
cmd_data_set[n_course_key] = course_data
cmd_data_set["courseType"] = course_type
else:
cmd_data_set[n_course_key] = "NOT_SELECTED"
elif cmd_key in ["smartCourse", "SmartCourse", s_course_key]:
course_type = self._status.lookup_reference(s_course_key, ref_key="courseType")
course_data = status_data.get(s_course_key, "NOT_SELECTED")
course_type = self.model_info.reference_name(
s_course_key, course_data, ref_key="courseType"
)
if course_type:
cmd_data_set[s_course_key] = status_data.get(s_course_key)
cmd_data_set[s_course_key] = course_data
cmd_data_set["courseType"] = course_type
else:
cmd_data_set[s_course_key] = "NOT_SELECTED"
Expand Down Expand Up @@ -144,11 +153,14 @@ def power_off(self):
self.set(keys[0], keys[1], value=keys[2])
self._update_status(POWER_STATUS_KEY, STATE_WM_POWER_OFF)

def wake_up(self):
"""Wakeup the device."""
keys = self._get_cmd_keys(CMD_WAKE_UP)
self.set(keys[0], keys[1], value=keys[2])

def remote_start(self):
"""Remote start the device."""
if not self._status:
raise InvalidDeviceStatus()
if self._status.remotestart_state != STATE_OPTIONITEM_ON:
if not self._remote_start_status:
raise InvalidDeviceStatus()

keys = self._get_cmd_keys(CMD_REMOTE_START)
Expand All @@ -158,13 +170,23 @@ def reset_status(self):
self._status = WMStatus(self, None)
return self._status

def _set_remote_start_opt(self, res):

remote_enabled = self._status.remotestart_state == STATE_OPTIONITEM_ON
if not self._remote_start_status:
if remote_enabled:
self._remote_start_status = res
elif not remote_enabled:
self._remote_start_status = None

def poll(self) -> Optional["WMStatus"]:
"""Poll the device's current state."""

res = self.device_poll(WM_ROOT_DATA)
if not res:
return None

self._set_remote_start_opt(res)
self._status = WMStatus(self, res)
return self._status

Expand Down

0 comments on commit 6777da4

Please sign in to comment.