Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Removing unnecessary region config #8

Merged
merged 3 commits into from
May 31, 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
7 changes: 1 addition & 6 deletions custom_components/badnest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

from .api import NestAPI
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_USER_ID, \
CONF_ACCESS_TOKEN, CONF_REGION
CONF_ACCESS_TOKEN

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
{
vol.Required(CONF_USER_ID, default=""): cv.string,
vol.Required(CONF_ACCESS_TOKEN, default=""): cv.string,
vol.Optional(CONF_REGION, default="us"): cv.string,
},
{
vol.Required(CONF_ISSUE_TOKEN, default=""): cv.string,
vol.Required(CONF_COOKIE, default=""): cv.string,
vol.Optional(CONF_REGION, default="us"): cv.string,
}
)
},
Expand All @@ -32,19 +30,16 @@ def setup(hass, config):
access_token = config[DOMAIN].get(CONF_ACCESS_TOKEN)
issue_token = config[DOMAIN].get(CONF_ISSUE_TOKEN)
cookie = config[DOMAIN].get(CONF_COOKIE)
region = config[DOMAIN].get(CONF_REGION)
else:
issue_token = None
cookie = None
region = None

hass.data[DOMAIN] = {
'api': NestAPI(
user_id,
access_token,
issue_token,
cookie,
region,
),
}

Expand Down
11 changes: 6 additions & 5 deletions custom_components/badnest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def __init__(self,
user_id,
access_token,
issue_token,
cookie,
region):
cookie):
self.device_data = {}
self._wheres = {}
self._user_id = user_id
Expand All @@ -110,7 +109,6 @@ def __init__(self,
self._issue_token = issue_token
self._cookie = cookie
self._czfe_url = None
self._camera_url = f'https://nexusapi-{region}1.camera.home.nest.com'
self.cameras = []
self.thermostats = set()
self.temperature_sensors = set()
Expand Down Expand Up @@ -188,7 +186,8 @@ def _get_cameras(self):
for camera in r.json()["items"]:
cameras.append(camera['uuid'])
self.device_data[camera['uuid']] = {}

self.device_data[camera['uuid']]['camera_url'] = \
camera['nexus_api_nest_domain_host']
return cameras

@Decorators.refresh_login
Expand Down Expand Up @@ -531,8 +530,10 @@ def camera_get_image(self, device_id, now):
if device_id not in self.cameras:
return

camera_url = self.device_data[device_id]['camera_url']

r = self._session.get(
f'{self._camera_url}/get_image?uuid={device_id}' +
f'https://{camera_url}/get_image?uuid={device_id}' +
f'&cachebuster={now}',
)

Expand Down
1 change: 0 additions & 1 deletion custom_components/badnest/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
CONF_COOKIE = 'cookie'
CONF_USER_ID = 'user_id'
CONF_ACCESS_TOKEN = 'access_token'
CONF_REGION = 'region'