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