Skip to content

Commit

Permalink
Maintenance
Browse files Browse the repository at this point in the history
- Fixed "wakeup" service for ThinQ2 washer and dryer devices
- Implemented use of default program for "remote_start" service
  • Loading branch information
ollo69 committed Jun 9, 2021
1 parent ad835c0 commit 683efa7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/smartthinq_sensors/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Support to interface with LGE ThinQ Devices.
"""

__version__ = "0.8.8"
__version__ = "0.8.9"
PROJECT_URL = "https://github.com/ollo69/ha-smartthinq-sensors/"
ISSUE_URL = "{}issues".format(PROJECT_URL)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/smartthinq_sensors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"requirements": ["pycountry>=20.7.3"],
"config_flow": true,
"iot_class": "cloud_polling",
"version": "0.8.8"
"version": "0.8.9"
}
9 changes: 4 additions & 5 deletions custom_components/smartthinq_sensors/wideq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,11 @@ def value_exist(self, name):

def data_root(self, name):
if name in self._data["MonitoringValue"]:
if self._data["MonitoringValue"][name].get("dataType"):
if "dataType" in self._data["MonitoringValue"][name]:
return self._data["MonitoringValue"][name]
else:
ref = self._data["MonitoringValue"][name].get("ref")
if ref:
return self._data.get(ref)
ref = self._data["MonitoringValue"][name].get("ref")
if ref:
return self._data.get(ref)

return None

Expand Down
49 changes: 45 additions & 4 deletions custom_components/smartthinq_sensors/wideq/washerDryer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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_WAKE_UP = [["Control", "WMWakeup"], ["Operation", "WMWakeup"], ["WakeUp", None]]
CMD_REMOTE_START = [["Control", "WMStart"], ["OperationStart", "WMStart"], ["Start", "WMStart"]]

_LOGGER = logging.getLogger(__name__)
Expand All @@ -73,11 +73,52 @@ def _update_status(self, key, value):
if status_value:
self._status.update_status(status_key, status_value)

def _get_course_info(self, course_key, course_id):
"""Get definition for a specific course ID."""
if course_key is None:
return None
if self.model_info.is_info_v2:
return self.model_info.data_root(course_key).get(course_id)
return self.model_info.value(course_key).reference.get(course_id)

def _update_course_info(self, data, course_id=None):
"""Save information in the data payload for a specific course
or default course if not already available.
"""
ret_data = data.copy()
if self.model_info.is_info_v2:
n_course_key = self.model_info.config_value("courseType")
s_course_key = self.model_info.config_value("smartCourseType")
def_course_id = self.model_info.config_value("defaultCourse")
else:
n_course_key = "APCourse" if self.model_info.value_exist("APCourse") else "Course"
s_course_key = "SmartCourse"
def_course_id = str(self.model_info.config_value("defaultCourseId"))
if course_id is None:
# check if course is defined in data payload
for course_key in [n_course_key, s_course_key]:
course_id = str(data.get(course_key))
if self._get_course_info(course_key, course_id):
return ret_data
course_id = def_course_id

# save information for specific or default course
course_info = self._get_course_info(n_course_key, course_id)
if course_info:
ret_data[n_course_key] = course_id
for func_key in course_info["function"]:
key = func_key.get("value")
data = func_key.get("default")
if key and data:
ret_data[key] = data

return ret_data

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._remote_start_status
status_data = self._update_course_info(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 @@ -101,7 +142,7 @@ def _prepare_command_v2(self, cmd, key, value):
return cmd

if key and key == "WMStart":
status_data = self._remote_start_status
status_data = self._update_course_info(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 = {}
Expand Down Expand Up @@ -186,8 +227,8 @@ def poll(self) -> Optional["WMStatus"]:
if not res:
return None

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


Expand Down

0 comments on commit 683efa7

Please sign in to comment.