Skip to content

Commit 0257a67

Browse files
committed
Minor changes related to camera usage
1 parent 07034ec commit 0257a67

5 files changed

Lines changed: 81 additions & 21 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ To install lnetatmo simply run:
1313

1414
python setup.py install
1515

16+
or
17+
18+
pip install lnetatmo
19+
1620
Depending on your permissions you might be required to use sudo.
17-
Once installed you can simple add latmo to your python scripts by including:
21+
Once installed you can simple add lnetatmo to your python scripts by including:
1822

1923
import lnetatmo

lnetatmo.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, clientId=_CLIENT_ID,
105105
clientSecret=_CLIENT_SECRET,
106106
username=_USERNAME,
107107
password=_PASSWORD,
108-
scope="read_station"):
108+
scope="read_station read_camera access_camera read_presence access_presence"):
109109

110110
postParams = {
111111
"grant_type" : "password",
@@ -308,9 +308,9 @@ class DeviceList(WeatherStationData):
308308
DeprecationWarning )
309309
pass
310310

311-
class WelcomeData:
311+
class HomeData:
312312
"""
313-
List the Netatmo Welcome cameras informations (Homes, cameras, events, persons)
313+
List the Netatmo home informations (Homes, cameras, events, persons)
314314
315315
Args:
316316
authData (ClientAuth): Authentication information with a working access Token
@@ -323,7 +323,7 @@ def __init__(self, authData):
323323
resp = postRequest(_GETHOMEDATA_REQ, postParams)
324324
self.rawData = resp['body']
325325
self.homes = { d['id'] : d for d in self.rawData['homes'] }
326-
if not self.homes : raise NoDevice("No camera available")
326+
if not self.homes : raise NoDevice("No home available")
327327
self.persons = dict()
328328
self.events = dict()
329329
self.cameras = dict()
@@ -343,7 +343,7 @@ def __init__(self, authData):
343343
for camera in self.events:
344344
self.lastEvent[camera]=self.events[camera][sorted(self.events[camera])[-1]]
345345
self.default_home = list(self.homes.values())[0]['name']
346-
if not self.cameras[self.default_home] : raise NoDevice("No camera available")
346+
if not self.cameras[self.default_home] : raise NoDevice("No camera available in default home")
347347
self.default_camera = list(self.cameras[self.default_home].values())[0]
348348

349349
def homeById(self, hid):
@@ -392,12 +392,11 @@ def cameraUrls(self, camera=None, home=None, cid=None):
392392
camera_data=self.cameraByName(camera=camera, home=home)
393393
if camera_data:
394394
vpn_url = camera_data['vpn_url']
395-
if camera_data['is_local']:
396-
resp = postRequest('{0}/command/ping'.format(camera_data['vpn_url']),dict())
397-
temp_local_url=resp['local_url']
398-
resp = postRequest('{0}/command/ping'.format(temp_local_url),dict())
399-
if temp_local_url == resp['local_url']:
400-
local_url = temp_local_url
395+
resp = postRequest('{0}/command/ping'.format(camera_data['vpn_url']),dict())
396+
temp_local_url=resp['local_url']
397+
resp = postRequest('{0}/command/ping'.format(temp_local_url),dict())
398+
if temp_local_url == resp['local_url']:
399+
local_url = temp_local_url
401400
return vpn_url, local_url
402401

403402
def personsAtHome(self, home=None):
@@ -531,6 +530,15 @@ def motionDetected(self, home=None, camera=None):
531530
return True
532531
return False
533532

533+
class WelcomeData(HomeData):
534+
"""
535+
This class is now deprecated. Use HomeData instead
536+
Home can handle many devices, not only Welcome cameras
537+
"""
538+
warnings.warn("The 'WelcomeData' class was renamed 'HomeData' to handle new Netatmo Home capabilities",
539+
DeprecationWarning )
540+
pass
541+
534542
# Utilities routines
535543

536544
def postRequest(url, params, json_resp=True, body_size=65535):
@@ -595,22 +603,22 @@ def getStationMinMaxTH(station=None, module=None):
595603
stderr.write("Library source missing identification arguments to check lnetatmo.py (user/password/etc...)")
596604
exit(1)
597605

598-
authorization = ClientAuth(scope="read_station read_camera access_camera") # Test authentication method
606+
authorization = ClientAuth() # Test authentication method
599607

600608
try:
601-
devList = DeviceList(authorization) # Test DEVICELIST
609+
weatherStation = WeatherStationData(authorization) # Test DEVICELIST
602610
except NoDevice:
603611
if stdout.isatty():
604612
print("lnetatmo.py : warning, no weather station available for testing")
605613
else:
606-
devList.MinMaxTH() # Test GETMEASUR
614+
weatherStation.MinMaxTH() # Test GETMEASUR
607615

608616

609617
try:
610-
Camera = WelcomeData(authorization)
618+
Homes = HomeData(authorization)
611619
except NoDevice :
612620
if stdout.isatty():
613-
print("lnetatmo.py : warning, no Welcome camera available for testing")
621+
print("lnetatmo.py : warning, no home available for testing")
614622

615623
# If we reach this line, all is OK
616624

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Locate the camera name "MyCam" IP on the local LAN
2+
# to collect a snapshot of what the camera sees without
3+
# bandwith constraints of the Internet connexion
4+
5+
6+
# You will need the "requests" library : pip install requests
7+
8+
from sys import exit
9+
import lnetatmo
10+
import requests
11+
12+
13+
# The name I gave the camera in the Netatmo Security App
14+
MY_CAMERA = "MyCam"
15+
# From the netatmo camera API documentation
16+
SNAPSHOT_REQUEST = "/live/snapshot_720.jpg"
17+
18+
19+
# Authenticate (see authentication in documentation)
20+
# Note you will need the appropriate scope (read_welcome access_welcome or read_presence access_presence)
21+
# depending of the camera you are trying to reach
22+
# The default library scope ask for all aceess to all cameras
23+
authorization = lnetatmo.ClientAuth()
24+
25+
# Gather Home information (available cameras and other infos)
26+
homeData = lnetatmo.HomeData(authorization)
27+
28+
# Ask for Url giving local access to the camera I am looking for
29+
# Or remote VPN access through Netatmo server if the camera can't be reach locally
30+
vpnUrl, localUrl = homeData.cameraUrls(MY_CAMERA)
31+
camUrl = localUrl if localUrl else vpnUrl
32+
33+
# Request a snapshot from the camera
34+
r = requests.get(camUrl + SNAPSHOT_REQUEST)
35+
36+
# If all was Ok, I should have a returned HTTP status of 200, else something goes wrong
37+
if r.status_code != 200 :
38+
# Decide what to do with an error situation (alert, log, ...)
39+
exit(1)
40+
41+
# Save the snapshot in a file
42+
with open("MyCamSnap.jpg", "wb") as f: f.write(r.content)
43+
44+
# You can then archive the file, send it by mail, message App, ...
45+
46+
exit(0)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lnetatmo',
7-
version='1.2.2',
7+
version='1.3.2',
88
classifiers=[
99
'Development Status :: 5 - Production/Stable',
1010
'Intended Audience :: Developers',

usage.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,24 +332,26 @@ for m in weatherData.checkNotUpdated("<optional station name>"):
332332
at all if you slip over two days as required in a shifting 24 hours window.
333333

334334

335-
#### 4-5 WelcomeData class ####
335+
#### 4-5 HomeData class ####
336336

337337

338338

339339
Constructor
340340

341341
```python
342-
welcomeData = lnetatmo.WelcomeData( authorization )
342+
homeData = lnetatmo.HomeData( authorization )
343343
```
344344

345345

346346
Requires : an authorization object (ClientAuth instance)
347347

348348

349-
Return : a WelcomeData object. This object contains most administration properties of Welcome cameras accessible to the user and the last data pushed by the cameras to the Netatmo servers.
349+
Return : a homeData object. This object contains most administration properties of home security products and notably Welcome & Presence cameras.
350350

351351
Raise a lnetatmo.NoDevice exception if no camera is available for the given account.
352352

353+
Note : the is_local property of camera is most of the time unusable if your IP changes, use cameraUrls to try to get a local IP as a replacement.
354+
353355
Properties, all properties are read-only unless specified:
354356

355357

0 commit comments

Comments
 (0)