mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 18:30:43 +00:00
Merge pull request #28 from USA-RedDragon/multi-region-cameras
Add region config and use it to use correct camera URL
This commit is contained in:
commit
fa1a632d2b
@ -3,7 +3,8 @@ import logging
|
|||||||
|
|
||||||
API_URL = "https://home.nest.com"
|
API_URL = "https://home.nest.com"
|
||||||
CAMERA_WEBAPI_BASE = "https://webapi.camera.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) " \
|
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) " \
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) " \
|
"AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||||
"Chrome/75.0.3770.100 Safari/537.36"
|
"Chrome/75.0.3770.100 Safari/537.36"
|
||||||
@ -362,6 +363,7 @@ class NestCameraAPI(NestAPI):
|
|||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key,
|
api_key,
|
||||||
|
region,
|
||||||
device_id=None):
|
device_id=None):
|
||||||
super(NestCameraAPI, self).__init__(
|
super(NestCameraAPI, self).__init__(
|
||||||
email,
|
email,
|
||||||
@ -383,6 +385,14 @@ class NestCameraAPI(NestAPI):
|
|||||||
self.battery_voltage = None
|
self.battery_voltage = None
|
||||||
self.ac_voltge = None
|
self.ac_voltge = None
|
||||||
self.data_tier = 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()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -430,7 +440,8 @@ class NestCameraAPI(NestAPI):
|
|||||||
|
|
||||||
def get_image(self, now):
|
def get_image(self, now):
|
||||||
r = self._session.get(
|
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
|
return r.content
|
||||||
|
@ -1,18 +1,34 @@
|
|||||||
"""This component provides basic support for Foscam IP cameras."""
|
"""This component provides basic support for Foscam IP cameras."""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
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.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 .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__)
|
_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,
|
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_PASSWORD],
|
||||||
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
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())
|
# 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_ISSUE_TOKEN],
|
||||||
hass.data[DOMAIN][CONF_COOKIE],
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
hass.data[DOMAIN][CONF_APIKEY],
|
hass.data[DOMAIN][CONF_APIKEY],
|
||||||
|
config.get(CONF_REGION),
|
||||||
camera["uuid"]
|
camera["uuid"]
|
||||||
))
|
))
|
||||||
cameras.append(device)
|
cameras.append(device)
|
||||||
|
@ -2,3 +2,4 @@ DOMAIN = 'badnest'
|
|||||||
CONF_ISSUE_TOKEN = 'issue_token'
|
CONF_ISSUE_TOKEN = 'issue_token'
|
||||||
CONF_COOKIE = 'cookie'
|
CONF_COOKIE = 'cookie'
|
||||||
CONF_APIKEY = 'api_key'
|
CONF_APIKEY = 'api_key'
|
||||||
|
CONF_REGION = 'region'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user