mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 18:30:43 +00:00
Add region config and use it to use correct camera URL
This commit is contained in:
parent
3d49b85c50
commit
b1447a4e6e
@ -3,7 +3,8 @@ import logging
|
||||
|
||||
API_URL = "https://home.nest.com"
|
||||
CAMERA_WEBAPI_BASE = "https://webapi.camera.home.nest.com"
|
||||
CAMERA_URL = "https://nexusapi-us1.camera.home.nest.com"
|
||||
CAMERA_US_URL = "https://nexusapi-us1.camera.home.nest.com"
|
||||
CAMERA_EU_URL = "https://nexusapi-eu1.camera.home.nest.com"
|
||||
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||
"Chrome/75.0.3770.100 Safari/537.36"
|
||||
@ -362,6 +363,7 @@ class NestCameraAPI(NestAPI):
|
||||
issue_token,
|
||||
cookie,
|
||||
api_key,
|
||||
region,
|
||||
device_id=None):
|
||||
super(NestCameraAPI, self).__init__(
|
||||
email,
|
||||
@ -383,6 +385,14 @@ class NestCameraAPI(NestAPI):
|
||||
self.battery_voltage = None
|
||||
self.ac_voltge = None
|
||||
self.data_tier = None
|
||||
if region.lower() == 'eu':
|
||||
self._camera_url = CAMERA_EU_URL
|
||||
elif region.lower() == 'us':
|
||||
self._camera_url = CAMERA_US_URL
|
||||
else:
|
||||
lower_region = region.lower()
|
||||
self._camera_url = \
|
||||
f'https://nexusapi-{lower_region}1.camera.home.nest.com'
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
@ -430,7 +440,8 @@ class NestCameraAPI(NestAPI):
|
||||
|
||||
def get_image(self, now):
|
||||
r = self._session.get(
|
||||
f"{CAMERA_URL}/get_image?uuid={self._device_id}&cachebuster={now}"
|
||||
f'{self._camera_url}/get_image?uuid={self._device_id}' +
|
||||
f'&cachebuster={now}'
|
||||
)
|
||||
|
||||
return r.content
|
||||
|
@ -1,18 +1,34 @@
|
||||
"""This component provides basic support for Foscam IP cameras."""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import (
|
||||
Camera,
|
||||
SUPPORT_ON_OFF,
|
||||
PLATFORM_SCHEMA
|
||||
)
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from homeassistant.components.camera import Camera, SUPPORT_ON_OFF
|
||||
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from .api import NestCameraAPI
|
||||
from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
||||
|
||||
from .const import (
|
||||
CONF_APIKEY,
|
||||
CONF_COOKIE,
|
||||
CONF_ISSUE_TOKEN,
|
||||
CONF_REGION,
|
||||
DOMAIN
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = "Nest Camera"
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_REGION, default="us"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass,
|
||||
@ -25,7 +41,8 @@ async def async_setup_platform(hass,
|
||||
hass.data[DOMAIN][CONF_PASSWORD],
|
||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||
hass.data[DOMAIN][CONF_COOKIE],
|
||||
hass.data[DOMAIN][CONF_APIKEY]
|
||||
hass.data[DOMAIN][CONF_APIKEY],
|
||||
config.get(CONF_REGION)
|
||||
)
|
||||
|
||||
# cameras = await hass.async_add_executor_job(nest.get_cameras())
|
||||
@ -39,6 +56,7 @@ async def async_setup_platform(hass,
|
||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||
hass.data[DOMAIN][CONF_COOKIE],
|
||||
hass.data[DOMAIN][CONF_APIKEY],
|
||||
config.get(CONF_REGION),
|
||||
camera["uuid"]
|
||||
))
|
||||
cameras.append(device)
|
||||
|
@ -2,3 +2,4 @@ DOMAIN = 'badnest'
|
||||
CONF_ISSUE_TOKEN = 'issue_token'
|
||||
CONF_COOKIE = 'cookie'
|
||||
CONF_APIKEY = 'api_key'
|
||||
CONF_REGION = 'region'
|
||||
|
Loading…
x
Reference in New Issue
Block a user