mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-16 07:10:09 -07:00
Add fallback to v1 API
This commit is contained in:
parent
6e38538d65
commit
6197fa42d1
20
example.py
20
example.py
@ -191,16 +191,16 @@ def turn(client, device_id, on_off):
|
|||||||
|
|
||||||
def ac_config(client, device_id):
|
def ac_config(client, device_id):
|
||||||
ac = wideq.ACDevice(client, _force_device(client, device_id))
|
ac = wideq.ACDevice(client, _force_device(client, device_id))
|
||||||
print(ac.supported_operations)
|
print(f"supported_operations: {ac.supported_operations}")
|
||||||
print(ac.supported_on_operation)
|
print(f"supported_on_operation: {ac.supported_on_operation}")
|
||||||
print(ac.get_filter_state())
|
print(f"get_filter_state: {ac.get_filter_state()}")
|
||||||
print(ac.get_mfilter_state())
|
print(f"get_mfilter_state: {ac.get_mfilter_state()}")
|
||||||
print(ac.get_energy_target())
|
print(f"get_energy_target: {ac.get_energy_target()}")
|
||||||
print(ac.get_power(), " watts")
|
print(f"get_power: {ac.get_power(), 'watts'}")
|
||||||
print(ac.get_outdoor_power(), " watts")
|
print(f"get_outdoor_power: {ac.get_outdoor_power(), 'watts'}")
|
||||||
print(ac.get_volume())
|
print(f"get_volume: {ac.get_volume()}")
|
||||||
print(ac.get_light())
|
print(f"get_light: {ac.get_light()}")
|
||||||
print(ac.get_zones())
|
print(f"get_zones: {ac.get_zones()}")
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE_COMMANDS = {
|
EXAMPLE_COMMANDS = {
|
||||||
|
@ -8,13 +8,13 @@ class SimpleTest(unittest.TestCase):
|
|||||||
@responses.activate
|
@responses.activate
|
||||||
def test_gateway_en_US(self):
|
def test_gateway_en_US(self):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.POST,
|
responses.GET,
|
||||||
"https://kic.lgthinq.com:46030/api/common/gatewayUriList",
|
"https://route.lgthinq.com:46030/v1/service/application/gateway-uri",
|
||||||
json={
|
json={
|
||||||
"lgedmRoot": {
|
"result": {
|
||||||
"thinqUri": "https://aic.lgthinq.com:46030/api",
|
"thinq1Uri": "https://aic.lgthinq.com:46030/api",
|
||||||
|
"thinq2Uri": "https://aic-service.lgthinq.com:46030/v1",
|
||||||
"empUri": "https://us.m.lgaccount.com",
|
"empUri": "https://us.m.lgaccount.com",
|
||||||
"oauthUri": "https://us.lgeapi.com",
|
|
||||||
"countryCode": "US",
|
"countryCode": "US",
|
||||||
"langCode": "en-US",
|
"langCode": "en-US",
|
||||||
}
|
}
|
||||||
@ -28,20 +28,21 @@ class SimpleTest(unittest.TestCase):
|
|||||||
gatewayInstance.auth_base, "https://us.m.lgaccount.com"
|
gatewayInstance.auth_base, "https://us.m.lgaccount.com"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
gatewayInstance.api_root, "https://aic.lgthinq.com:46030/api"
|
gatewayInstance.api_root,
|
||||||
|
"https://aic-service.lgthinq.com:46030/v1",
|
||||||
)
|
)
|
||||||
self.assertEqual(gatewayInstance.oauth_root, "https://us.lgeapi.com")
|
|
||||||
|
|
||||||
@responses.activate
|
@responses.activate
|
||||||
def test_gateway_en_NO(self):
|
def test_gateway_en_NO(self):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.POST,
|
responses.GET,
|
||||||
"https://kic.lgthinq.com:46030/api/common/gatewayUriList",
|
"https://route.lgthinq.com:46030/v1/service/application/gateway-uri",
|
||||||
json={
|
json={
|
||||||
"lgedmRoot": {
|
"result": {
|
||||||
"countryCode": "NO",
|
"countryCode": "NO",
|
||||||
"langCode": "en-NO",
|
"langCode": "en-NO",
|
||||||
"thinqUri": "https://eic.lgthinq.com:46030/api",
|
"thinq1Uri": "https://eic.lgthinq.com:46030/api",
|
||||||
|
"thinq2Uri": "https://eic-service.lgthinq.com:46030/v1",
|
||||||
"empUri": "https://no.m.lgaccount.com",
|
"empUri": "https://no.m.lgaccount.com",
|
||||||
"oauthUri": "https://no.lgeapi.com",
|
"oauthUri": "https://no.lgeapi.com",
|
||||||
}
|
}
|
||||||
@ -55,6 +56,6 @@ class SimpleTest(unittest.TestCase):
|
|||||||
gatewayInstance.auth_base, "https://no.m.lgaccount.com"
|
gatewayInstance.auth_base, "https://no.m.lgaccount.com"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
gatewayInstance.api_root, "https://eic.lgthinq.com:46030/api"
|
gatewayInstance.api_root,
|
||||||
|
"https://eic-service.lgthinq.com:46030/v1",
|
||||||
)
|
)
|
||||||
self.assertEqual(gatewayInstance.oauth_root, "https://no.lgeapi.com")
|
|
||||||
|
@ -345,26 +345,28 @@ class ModelInfo(object):
|
|||||||
:raises ValueError: If an unsupported type is encountered.
|
:raises ValueError: If an unsupported type is encountered.
|
||||||
"""
|
"""
|
||||||
d = self.data["Value"][name]
|
d = self.data["Value"][name]
|
||||||
if d["data_type"] in ("Enum", "enum"):
|
if d.get("data_type", d.get("type")) in ("Enum", "enum"):
|
||||||
return EnumValue(d["value_mapping"])
|
return EnumValue(d.get("value_mapping", d.get("option")))
|
||||||
elif d["data_type"] == "Range":
|
elif d.get("data_type", d.get("type")) == "Range":
|
||||||
return RangeValue(
|
return RangeValue(
|
||||||
d["option"]["min"],
|
d.get("option", d.get("value_validation"))["min"],
|
||||||
d["option"]["max"],
|
d.get("option", d.get("value_validation"))["max"],
|
||||||
d["option"].get("step", 1),
|
d.get("option", d.get("value_validation")).get("step", 1),
|
||||||
)
|
)
|
||||||
elif d["data_type"].lower() == "bit":
|
elif d.get("data_type", d.get("type")).lower() == "bit":
|
||||||
bit_values = {opt["startbit"]: opt["value"] for opt in d["option"]}
|
bit_values = {
|
||||||
|
opt["startbit"]: opt["value"]
|
||||||
|
for opt in d.get("option", d.get("value_validation"))
|
||||||
|
}
|
||||||
return BitValue(bit_values)
|
return BitValue(bit_values)
|
||||||
elif d["data_type"].lower() == "reference":
|
elif d.get("data_type", d.get("type")).lower() == "reference":
|
||||||
ref = d["option"][0]
|
ref = d.get("option", d.get("value_validation"))[0]
|
||||||
return ReferenceValue(self.data[ref])
|
return ReferenceValue(self.data[ref])
|
||||||
elif d["data_type"].lower() == "string":
|
elif d.get("data_type", d.get("type")).lower() == "string":
|
||||||
return StringValue(d.get("_comment", ""))
|
return StringValue(d.get("_comment", ""))
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"unsupported value name: '{name}'"
|
f"unsupported value name: '{name}'" f"data: '{str(d)}'"
|
||||||
f" type: '{str(d['type'])}' data: '{str(d)}'"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def default(self, name):
|
def default(self, name):
|
||||||
@ -387,7 +389,7 @@ class ModelInfo(object):
|
|||||||
str(int(value)),
|
str(int(value)),
|
||||||
key,
|
key,
|
||||||
options,
|
options,
|
||||||
self.data["Value"][key]["value_mapping"],
|
value.get("value_mapping", value.get("option")),
|
||||||
)
|
)
|
||||||
return _UNKNOWN
|
return _UNKNOWN
|
||||||
return options[str(int(value))]
|
return options[str(int(value))]
|
||||||
|
@ -9,6 +9,7 @@ import hmac
|
|||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple
|
||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
from requests.packages.urllib3.util.retry import Retry
|
from requests.packages.urllib3.util.retry import Retry
|
||||||
@ -224,7 +225,7 @@ def thinq_request(
|
|||||||
session_id=None,
|
session_id=None,
|
||||||
user_number=None,
|
user_number=None,
|
||||||
country=DEFAULT_COUNTRY,
|
country=DEFAULT_COUNTRY,
|
||||||
language=DEFAULT_LANGUAGE
|
language=DEFAULT_LANGUAGE,
|
||||||
):
|
):
|
||||||
"""Make an HTTP request in the format used by the API servers.
|
"""Make an HTTP request in the format used by the API servers.
|
||||||
|
|
||||||
@ -388,7 +389,10 @@ class Gateway(object):
|
|||||||
RequestMethod.GET,
|
RequestMethod.GET,
|
||||||
GATEWAY_URL,
|
GATEWAY_URL,
|
||||||
{"countryCode": country, "langCode": language},
|
{"countryCode": country, "langCode": language},
|
||||||
|
country=country,
|
||||||
|
language=language,
|
||||||
)
|
)
|
||||||
|
print(json.dumps(gw))
|
||||||
return cls(gw["empUri"], gw["thinq2Uri"], country, language)
|
return cls(gw["empUri"], gw["thinq2Uri"], country, language)
|
||||||
|
|
||||||
def oauth_url(self):
|
def oauth_url(self):
|
||||||
@ -484,10 +488,10 @@ class Session(object):
|
|||||||
RequestMethod.POST,
|
RequestMethod.POST,
|
||||||
url,
|
url,
|
||||||
data,
|
data,
|
||||||
self.auth.access_token,
|
access_token=self.auth.access_token,
|
||||||
user_number=self.auth.user_number,
|
user_number=self.auth.user_number,
|
||||||
country=self.auth.gateway.country,
|
country=self.auth.gateway.country,
|
||||||
language=self.auth.gateway.language
|
language=self.auth.gateway.language,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user