Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for api v5.1 #35

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pymyq/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from aiohttp import ClientSession
from aiohttp.client_exceptions import ClientError

from .const import DEVICES_API_VERSION
from .device import MyQDevice
from .errors import InvalidCredentialsError, RequestError

_LOGGER = logging.getLogger(__name__)

API_VERSION = 5
API_BASE = "https://api.myqdevice.com/api/v{0}".format(API_VERSION)
BASE_API_VERSION = 5
API_BASE = "https://api.myqdevice.com/api/v{0}"

DEFAULT_APP_ID = "JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu"
DEFAULT_REQUEST_RETRIES = 5
Expand Down Expand Up @@ -56,10 +57,12 @@ async def request(
params: dict = None,
json: dict = None,
login_request: bool = False,
api_version: str = BASE_API_VERSION,
**kwargs
) -> dict:
"""Make a request."""
url = "{0}/{1}".format(API_BASE, endpoint)
api_base = API_BASE.format(api_version)
url = "{0}/{1}".format(api_base, endpoint)

if not headers:
headers = {}
Expand Down Expand Up @@ -137,7 +140,7 @@ async def update_device_info(self) -> dict:
return

devices_resp = await self.request(
"get", "Accounts/{0}/Devices".format(self.account_id)
"get", "Accounts/{0}/Devices".format(self.account_id), api_version=DEVICES_API_VERSION
)

if devices_resp is None or devices_resp.get("items") is None:
Expand Down
43 changes: 43 additions & 0 deletions pymyq/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""The myq constants."""

DEVICES_API_VERSION = 5.1

DEVICE_TYPE = "device_type"
DEVICE_TYPE_GATE = "gate"
DEVICE_FAMILY = "device_family"
DEVICE_FAMILY_GATEWAY = "gateway"
DEVICE_STATE = "state"
DEVICE_STATE_ONLINE = "online"

MANUFACTURER = "The Chamberlain Group Inc."

KNOWN_MODELS = {
"00": "Chamberlain Ethernet Gateway",
"01": "LiftMaster Ethernet Gateway",
"02": "Craftsman Ethernet Gateway",
"03": "Chamberlain Wi-Fi hub",
"04": "LiftMaster Wi-Fi hub",
"05": "Craftsman Wi-Fi hub",
"08": "LiftMaster Wi-Fi GDO DC w/Battery Backup",
"09": "Chamberlain Wi-Fi GDO DC w/Battery Backup",
"10": "Craftsman Wi-Fi GDO DC 3/4HP",
"11": "MyQ Replacement Logic Board Wi-Fi GDO DC 3/4HP",
"12": "Chamberlain Wi-Fi GDO DC 1.25HP",
"13": "LiftMaster Wi-Fi GDO DC 1.25HP",
"14": "Craftsman Wi-Fi GDO DC 1.25HP",
"15": "MyQ Replacement Logic Board Wi-Fi GDO DC 1.25HP",
"0A": "Chamberlain Wi-Fi GDO or Gate Operator AC",
"0B": "LiftMaster Wi-Fi GDO or Gate Operator AC",
"0C": "Craftsman Wi-Fi GDO or Gate Operator AC",
"0D": "MyQ Replacement Logic Board Wi-Fi GDO or Gate Operator AC",
"0E": "Chamberlain Wi-Fi GDO DC 3/4HP",
"0F": "LiftMaster Wi-Fi GDO DC 3/4HP",
"20": "Chamberlain MyQ Home Bridge",
"21": "LiftMaster MyQ Home Bridge",
"23": "Chamberlain Smart Garage Hub",
"24": "LiftMaster Smart Garage Hub",
"27": "LiftMaster Wi-Fi Wall Mount opener",
"28": "LiftMaster Commercial Wi-Fi Wall Mount operator",
"80": "EU LiftMaster Ethernet Gateway",
"81": "EU Chamberlain Ethernet Gateway",
}
5 changes: 4 additions & 1 deletion pymyq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .errors import RequestError

from .const import DEVICE_TYPE, DEVICES_API_VERSION

if TYPE_CHECKING:
from .api import API

Expand Down Expand Up @@ -52,7 +54,7 @@ def device_platform(self) -> str:
@property
def device_type(self) -> str:
"""Return the device type."""
return self.device_json["device_type"]
return self.device_json[DEVICE_TYPE]

@property
def firmware_version(self) -> Optional[str]:
Expand Down Expand Up @@ -105,6 +107,7 @@ async def _send_state_command(self, state_command: str) -> None:
self._api.account_id, self.device_id
),
json={"action_type": state_command},
api_version=DEVICES_API_VERSION
)

async def close(self) -> None:
Expand Down