mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 22:50:44 +00:00
Attempt to make the camera's use different API instances
This commit is contained in:
parent
77bd36b4bd
commit
51efa759e8
@ -356,18 +356,26 @@ class NestTemperatureSensorAPI(NestAPI):
|
|||||||
|
|
||||||
|
|
||||||
class NestCameraAPI(NestAPI):
|
class NestCameraAPI(NestAPI):
|
||||||
def __init__(self, email, password, issue_token, cookie, api_key):
|
def __init__(self,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
issue_token,
|
||||||
|
cookie,
|
||||||
|
api_key,
|
||||||
|
device_id=None):
|
||||||
super(NestCameraAPI, self).__init__(
|
super(NestCameraAPI, self).__init__(
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
issue_token,
|
issue_token,
|
||||||
cookie,
|
cookie,
|
||||||
api_key)
|
api_key,
|
||||||
|
device_id)
|
||||||
# log into dropcam
|
# log into dropcam
|
||||||
self._session.post(
|
self._session.post(
|
||||||
f"{API_URL}/dropcam/api/login",
|
f"{API_URL}/dropcam/api/login",
|
||||||
data={"access_token": self._access_token}
|
data={"access_token": self._access_token}
|
||||||
)
|
)
|
||||||
|
self._device_id = device_id
|
||||||
self.location = None
|
self.location = None
|
||||||
self.name = "Nest Camera"
|
self.name = "Nest Camera"
|
||||||
self.online = None
|
self.online = None
|
||||||
@ -377,10 +385,6 @@ class NestCameraAPI(NestAPI):
|
|||||||
self.data_tier = None
|
self.data_tier = None
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def set_device(self, uuid):
|
|
||||||
self._device_id = uuid
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self._device_id:
|
if self._device_id:
|
||||||
props = self.get_properties()
|
props = self.get_properties()
|
||||||
|
@ -13,7 +13,6 @@ from .const import DOMAIN, CONF_ISSUE_TOKEN, CONF_COOKIE, CONF_APIKEY
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = "Nest Camera"
|
DEFAULT_NAME = "Nest Camera"
|
||||||
DATA_KEY = "camera.badnest"
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass,
|
async def async_setup_platform(hass,
|
||||||
@ -21,8 +20,6 @@ async def async_setup_platform(hass,
|
|||||||
async_add_entities,
|
async_add_entities,
|
||||||
discovery_info=None):
|
discovery_info=None):
|
||||||
"""Set up a Nest Camera."""
|
"""Set up a Nest Camera."""
|
||||||
hass.data[DATA_KEY] = dict()
|
|
||||||
|
|
||||||
api = NestCameraAPI(
|
api = NestCameraAPI(
|
||||||
hass.data[DOMAIN][CONF_EMAIL],
|
hass.data[DOMAIN][CONF_EMAIL],
|
||||||
hass.data[DOMAIN][CONF_PASSWORD],
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
@ -36,9 +33,15 @@ async def async_setup_platform(hass,
|
|||||||
_LOGGER.info("Adding cameras")
|
_LOGGER.info("Adding cameras")
|
||||||
for camera in api.get_cameras():
|
for camera in api.get_cameras():
|
||||||
_LOGGER.info("Adding nest cam uuid: %s", camera["uuid"])
|
_LOGGER.info("Adding nest cam uuid: %s", camera["uuid"])
|
||||||
device = NestCamera(camera["uuid"], api)
|
device = NestCamera(camera["uuid"], NestCameraAPI(
|
||||||
|
hass.data[DOMAIN][CONF_EMAIL],
|
||||||
|
hass.data[DOMAIN][CONF_PASSWORD],
|
||||||
|
hass.data[DOMAIN][CONF_ISSUE_TOKEN],
|
||||||
|
hass.data[DOMAIN][CONF_COOKIE],
|
||||||
|
hass.data[DOMAIN][CONF_APIKEY],
|
||||||
|
camera["uuid"]
|
||||||
|
))
|
||||||
cameras.append(device)
|
cameras.append(device)
|
||||||
hass.data[DATA_KEY][camera["uuid"]] = device
|
|
||||||
|
|
||||||
async_add_entities(cameras)
|
async_add_entities(cameras)
|
||||||
|
|
||||||
@ -50,7 +53,6 @@ class NestCamera(Camera):
|
|||||||
"""Initialize a Nest camera."""
|
"""Initialize a Nest camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._uuid = uuid
|
self._uuid = uuid
|
||||||
api.set_device(self._uuid)
|
|
||||||
self._device = api
|
self._device = api
|
||||||
self._time_between_snapshots = timedelta(seconds=30)
|
self._time_between_snapshots = timedelta(seconds=30)
|
||||||
self._last_image = None
|
self._last_image = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user