Skip to content

Commit

Permalink
Released Dryer support (beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 committed Apr 13, 2020
1 parent c5ba12b commit 35bf49a
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 21 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
[![](https://img.shields.io/badge/MAINTAINER-%40ollo69-red?style=for-the-badge)](https://github.com/ollo69)
[![](https://img.shields.io/badge/COMMUNITY-FORUM-success?style=for-the-badge)](https://community.home-assistant.io)

# SmartThinQ LG Washer integration for HomeAssistant
A Homeassistant custom component to monitor LG Washer using SmartThinQ API (extension to other device will be managed with future development).<br/>
# LG ThinQ Washer and Dryer integration for HomeAssistant
A Homeassistant custom component to monitor LG Washer and Dryer using ThinQ API (extension to other device will be managed with future development).<br/>

**Version note:** If you are upgrading to version 0.2.x from 0.1.x, it is better to remove component configured integration
from Home Assistant before upgrade. Due to some change, if you don't remove and reconfigure, some device should result duplicated.
**Important Version note:** If you are upgrading to version 0.2.x from 0.1.x, it is suggested to remove component configuration
from Home Assistant before upgrade. Due to some change, if you don't remove and reconfigure, existing device will be duplicated.<br/>
***Dryer support start from version 0.2.1 and is under testing. If you have problem rollback to version 0.2.0 and wait for new release.***

**Important**: The component will **not work if you have logged into the ThinQ application and registered your devices using a social network account** (google, facebook or amazon). In order to use the component you need to create a new independent LG account and make sure you log into the ThinQ app and associate your devices with it.
If during configuration you receive the message "No SmartThinQ devices found", probably your devices are still associated with the social network account. To solve the problem perform the following step:
Expand Down
206 changes: 193 additions & 13 deletions custom_components/smartthinq_washer/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DeviceType,
)

from .wideq.dryer import DryerDevice
from .wideq.washer import WasherDevice

from homeassistant.components import sensor
Expand Down Expand Up @@ -47,6 +48,11 @@
ATTR_TURBOWASH_MODE = "turbowash_mode"
ATTR_TUBCLEAN_COUNT = "tubclean_count"

# Dryer attributes
ATTR_TEMPCONTROL_OPTION_STATE = "tempcontrol_option_state"
ATTR_DRYLEVEL_OPTION_STATE = "drylevel_option_state"
ATTR_TIMEDRY_OPTION_STATE = "timedry_option_state"

SENSORMODES = {
"ON": STATE_ON,
"OFF": STATE_OFF,
Expand All @@ -61,37 +67,46 @@ def setup_platform(hass, config, async_add_entities, discovery_info=None):


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the LGE Washer components."""
_LOGGER.info("Starting smartthinq sensors...")
"""Set up the LGE components."""
_LOGGER.info("Starting LGE ThinQ sensors...")

client = hass.data[DOMAIN][CLIENT]
lge_sensors = []
device_count = 0

for device in client.devices:
device_id = device.id
device_name = device.name
device_mac = device.macaddress
model_name = device.model_name
device_count += 1

if device.type == DeviceType.WASHER:

base_name = device_name
dev = LGEWasherDevice(client, device, base_name)
elif device.type == DeviceType.DRYER:
base_name = device_name
dev = LGEDryerDevice(client, device, base_name)
else:
_LOGGER.info("Found unsupported LGE Device %s of type %s", device_name, device.type.name)
continue

w = LGEWasherDevice(client, device, base_name)
lge_sensors.append(w)
hass.data[DOMAIN][LGE_DEVICES][w.unique_id] = w
lge_sensors.append(dev)
hass.data[DOMAIN][LGE_DEVICES][dev.unique_id] = dev

_LOGGER.info(
"LGE Washer added. Name: %s - Model: %s - Mac: %s - ID: %s",
base_name,
model_name,
device_mac,
device_id,
)
_LOGGER.info(
"LGE Device added. Name: %s - Model: %s - Mac: %s - ID: %s",
base_name,
model_name,
device_mac,
device_id,
)

if lge_sensors:
async_add_entities(lge_sensors)

_LOGGER.info("Founds %s LGE device(s)", str(device_count))

return True


Expand Down Expand Up @@ -335,3 +350,168 @@ def _tubclean_count(self):
return self._state.tubclean_count

return "N/A"


class LGEDryerDevice(LGEDevice):
"""A sensor to monitor LGE Dryer devices"""

def __init__(self, client, device, name):

"""initialize a LGE Washer Device."""
super().__init__(DryerDevice(client, device), name)

@property
def icon(self):
return "mdi:tumble-dryer"

@property
def device_state_attributes(self):
"""Return the optional state attributes."""
data = {
ATTR_RUN_COMPLETED: self._run_completed,
ATTR_ERROR_STATE: self._error_state,
ATTR_ERROR_MSG: self._error_msg,
ATTR_RUN_STATE: self._current_run_state,
ATTR_PRE_STATE: self._pre_state,
ATTR_CURRENT_COURSE: self._current_course,
ATTR_TEMPCONTROL_OPTION_STATE: self._tempcontrol_option_state,
ATTR_DRYLEVEL_OPTION_STATE: self._drylevel_option_state,
ATTR_TIMEDRY_OPTION_STATE: self._timedry_option_state,
ATTR_REMAIN_TIME: self._remain_time,
ATTR_INITIAL_TIME: self._initial_time,
ATTR_RESERVE_TIME: self._reserve_time,
}
return data

@property
def _run_completed(self):
if self._state:
if self._state.is_run_completed:
return SENSORMODES["ON"]

return SENSORMODES["OFF"]

@property
def _current_run_state(self):
if self._state:
if self._state.is_on:
run_state = self._state.run_state
return run_state

return "-"

@property
def _pre_state(self):
if self._state:
pre_state = self._state.pre_state
if pre_state == STATE_OPTIONITEM_OFF:
return "-"
else:
return pre_state

return "-"

@property
def _remain_time(self):
if self._state:
if self._state.is_on:
remain_hour = self._state.remaintime_hour
remain_min = self._state.remaintime_min
remaintime = [remain_hour, remain_min]
if int(remain_min) < 10:
return ":0".join(remaintime)
else:
return ":".join(remaintime)
return "0:00"

@property
def _initial_time(self):
if self._state:
if self._state.is_on:
initial_hour = self._state.initialtime_hour
initial_min = self._state.initialtime_min
initialtime = [initial_hour, initial_min]
if int(initial_min) < 10:
return ":0".join(initialtime)
else:
return ":".join(initialtime)
return "0:00"

@property
def _reserve_time(self):
if self._state:
if self._state.is_on:
reserve_hour = self._state.reservetime_hour
reserve_min = self._state.reservetime_min
reservetime = [reserve_hour, reserve_min]
if int(reserve_min) < 10:
return ":0".join(reservetime)
else:
return ":".join(reservetime)
return "0:00"

@property
def _current_course(self):
if self._state:
course = self._state.current_course
smartcourse = self._state.current_smartcourse
if self._state.is_on:
if course == "Download course":
return smartcourse
elif course == "OFF":
return "-"
else:
return course

return "-"

@property
def _error_state(self):
if self._state:
if self._state.is_on:
if self._state.is_error:
return SENSORMODES["ON"]

return SENSORMODES["OFF"]

@property
def _error_msg(self):
if self._state:
if self._state.is_on:
error = self._state.error_state
return error

return "-"

@property
def _tempcontrol_option_state(self):
if self._state:
temp_option = self._state.temp_control_option_state
if temp_option == "OFF":
return "-"
else:
return temp_option
else:
return "-"

@property
def _drylevel_option_state(self):
if self._state:
drylevel_option = self._state.dry_level_option_state
if drylevel_option == "OFF":
return "-"
else:
return drylevel_option
else:
return "-"

@property
def _timedry_option_state(self):
if self._state:
timedry_option = self._state.time_dry_option_state
if timedry_option == "OFF":
return "-"
else:
return timedry_option
else:
return "-"
Loading

0 comments on commit 35bf49a

Please sign in to comment.