forked from sampsyo/hass-smartthinq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
94 lines (73 loc) · 2.66 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Support for LG Smartthinq devices.
"""
import logging
import wideq
import voluptuous as vol
from homeassistant.const import CONF_REGION, CONF_TOKEN
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import discovery
from homeassistant.helpers.entity import Entity
DOMAIN = 'smartthinq'
CONF_LANGUAGE = 'language'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_TOKEN): cv.string,
CONF_REGION: cv.string,
CONF_LANGUAGE: cv.string,
})
}, extra=vol.ALLOW_EXTRA)
LOGGER = logging.getLogger(__name__)
SMARTTHINQ_COMPONENTS = [
'sensor',
'climate',
]
KEY_SMARTTHINQ_DEVICES = 'smartthinq_devices'
README_URL = 'https://github.com/sampsyo/hass-smartthinq/blob/master/README.md'
KEY_DEPRECATED_REFRESH_TOKEN = 'refresh_token'
KEY_DEPRECATED_COUNTRY = 'country'
KEY_DEPRECATED_LANGUAGE = 'language'
DEPRECATION_WARNING = (
'Direct use of the smartthinq components without a toplevel '
'smartthinq platform configuration is deprecated. Please use '
'a top-level smartthinq platform instead. Please see {readme_url} . '
'Configuration mapping:\n '
'\tclimate.{key_deprecated_token} -> {domain}.{key_token}\n'
'\tclimate.{key_deprecated_country} -> {domain}.{key_region}\n'
'\tclimate.{key_deprecated_language} -> {domain}.{key_language}').format(
readme_url=README_URL,
key_deprecated_token=KEY_DEPRECATED_REFRESH_TOKEN,
key_token=CONF_TOKEN,
key_deprecated_country=KEY_DEPRECATED_COUNTRY,
key_region=CONF_REGION,
key_deprecated_language=KEY_DEPRECATED_LANGUAGE,
key_language=CONF_LANGUAGE,
domain=DOMAIN)
def setup(hass, config):
if DOMAIN not in config:
LOGGER.warning(DEPRECATION_WARNING)
return True
if KEY_SMARTTHINQ_DEVICES not in hass.data:
hass.data[KEY_SMARTTHINQ_DEVICES] = []
refresh_token = config[DOMAIN].get(CONF_TOKEN)
region = config[DOMAIN].get(CONF_REGION)
language = config[DOMAIN].get(CONF_LANGUAGE)
client = wideq.Client.from_token(refresh_token, region, language)
hass.data[CONF_TOKEN] = refresh_token
hass.data[CONF_REGION] = region
hass.data[CONF_LANGUAGE] = language
for device in client.devices:
hass.data[KEY_SMARTTHINQ_DEVICES].append(device.id)
for component in SMARTTHINQ_COMPONENTS:
discovery.load_platform(hass, component, DOMAIN, {}, config)
return True
class LGDevice(Entity):
def __init__(self, client, device):
self._client = client
self._device = device
@property
def name(self):
return self._device.name
@property
def available(self):
return True