4 Commits

Author SHA1 Message Date
Gilles MOREL
952cf74b8e Passage à la version 1.1 2019-11-23 21:41:27 +01:00
Gilles MOREL
aff562b61b Mise à jour du point d'entrée d'authentification 2019-11-23 21:38:36 +01:00
Gilles MOREL
3f4b3cd1aa Correction du style
Oublis de la validation précédente
2019-01-15 23:02:35 +01:00
Gilles MOREL
92d0f18f3a Correction du style
Le style a été un peu corrigé à l'aide de pycodestyle
2018-02-22 21:29:53 +01:00

View File

@@ -10,11 +10,18 @@ This is a wrap aroud website, this could stop working without prior notice
## Manage cameras ## Manage cameras
### Get video ### Get video
from urllib import request
from http.cookiejar import CookieJar
from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from urllib.error import HTTPError
from datetime import datetime
authors = ( authors = (
'Gilles "Almtesh" Émilien MOREL', 'Gilles "Almtesh" Émilien MOREL',
) )
name = 'homesfr for Python 3' name = 'homesfr for Python 3'
version = '1.0' version = '1.1'
# Settable modes # Settable modes
MODE_OFF = 0 MODE_OFF = 0
@@ -30,12 +37,6 @@ REMOTE_CONTROLER = 'REMOTE'
KEYPAD_CONTROLER = 'KEYPAD' KEYPAD_CONTROLER = 'KEYPAD'
PRESENCE_CAMERA_DETECTOR = 'PIR_CAMERA' PRESENCE_CAMERA_DETECTOR = 'PIR_CAMERA'
from urllib import request
from http.cookiejar import CookieJar
from urllib.parse import urlencode
from xml.etree import ElementTree as ET
from urllib.error import HTTPError
from datetime import datetime
class Common (): class Common ():
''' '''
@@ -51,11 +52,11 @@ class Common ():
# path to login test # path to login test
self.auth_path = '/mysensors' self.auth_path = '/mysensors'
self.auth_ok = '/accueil' # if logged self.auth_ok = '/accueil' # if logged
self.auth_post_url = 'https://boutique.home.sfr.fr/authentification' self.auth_post_url = 'https://cas.home.sfr.fr/authentification'
self.auth_referer = 'https://boutique.home.sfr.fr/authentification?back=service' self.auth_referer = 'https://cas.home.sfr.fr/authentification'
self.auth_user_field = 'email' self.auth_user_field = 'username'
self.auth_pass_field = 'passwd' self.auth_pass_field = 'password'
self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'} self.auth_extra_fields = {}
self.auth_logout_path = '/deconnexion' self.auth_logout_path = '/deconnexion'
# Path to sensors and mode # Path to sensors and mode
@@ -154,7 +155,7 @@ class Common ():
a = self.bytes2file (self.opener.open (url).read ()) a = self.bytes2file (self.opener.open (url).read ())
a.seek (0) a.seek (0)
b = ET.parse (a) b = ET.parse (a)
if id_label == None: if id_label is None:
r = [] r = []
for i in b.findall (label): for i in b.findall (label):
r.append (build_tree (i)) r.append (build_tree (i))
@@ -165,6 +166,7 @@ class Common ():
r.update ({i.get (id_label): build_tree (i)}) r.update ({i.get (id_label): build_tree (i)})
return (r) return (r)
class HomeSFR (Common): class HomeSFR (Common):
def __init__ (self, username = None, password = None, cookies = None, debug = False, autologin = True): def __init__ (self, username = None, password = None, cookies = None, debug = False, autologin = True):
''' '''
@@ -181,22 +183,22 @@ class HomeSFR (Common):
print ('Authors:') print ('Authors:')
for i in authors: for i in authors:
print (' - ' + i) print (' - ' + i)
if username != None: if username is not None:
print ('init with username ' + username) print ('init with username ' + username)
if cookies != None: if cookies is not None:
print ('init with cookies') print ('init with cookies')
print ('debug = ' + str (debug)) print ('debug = ' + str (debug))
print ('autologin = ' + str (autologin)) print ('autologin = ' + str (autologin))
if (username == None or password == None) and cookies == None: if (username is None or password is None) and cookies is None:
raise TypeError ('You must define either username AND password or cookies') raise TypeError ('You must define either username AND password or cookies')
self.username = username self.username = username
self.password = password self.password = password
if self.username != None and self.password != None: if self.username is not None and self.password is not None:
self.autologin = autologin self.autologin = autologin
else: else:
self.autologin = False self.autologin = False
if cookies == None: if cookies is None:
self.cookies = CookieJar () self.cookies = CookieJar ()
elif type (cookies) == CookieJar: elif type (cookies) == CookieJar:
self.cookies = cookies self.cookies = cookies
@@ -208,7 +210,7 @@ class HomeSFR (Common):
''' '''
Shows name, version, defined user and debug state Shows name, version, defined user and debug state
''' '''
if self.username != None: if self.username is not None:
return (name + ' ' + version + '\nUser: ' + self.username + '\nDebug: ' + str (self.DEBUG)) return (name + ' ' + version + '\nUser: ' + self.username + '\nDebug: ' + str (self.DEBUG))
else: else:
return (name + ' ' + version + '\nUser: Unknown (auth from cookie class)\nDebug: ' + str (self.DEBUG)) return (name + ' ' + version + '\nUser: Unknown (auth from cookie class)\nDebug: ' + str (self.DEBUG))
@@ -237,7 +239,7 @@ class HomeSFR (Common):
Returns True if the login was a success, False either Returns True if the login was a success, False either
This method will always return False if no username and password are defined This method will always return False if no username and password are defined
''' '''
if self.username != None and self.password != None: if self.username is not None and self.password is not None:
self.opener.open (self.auth_referer) self.opener.open (self.auth_referer)
data = self.auth_extra_fields data = self.auth_extra_fields
data [self.auth_user_field] = self.username data [self.auth_user_field] = self.username
@@ -257,7 +259,7 @@ class HomeSFR (Common):
''' '''
Trigger the autologin Trigger the autologin
''' '''
if (self.autologin and self.test_login () == False): if (self.autologin and not self.test_login ()):
self.login () self.login ()
def logout (self): def logout (self):
@@ -362,7 +364,7 @@ class HomeSFR (Common):
Get a Camera object from the sensor's id Get a Camera object from the sensor's id
''' '''
self.do_autologin () self.do_autologin ()
if (self.autologin and self.test_login () == False): if (self.autologin and not self.test_login ()):
self.login () self.login ()
r = Camera (id, self.opener) r = Camera (id, self.opener)
r.refresh () r.refresh ()
@@ -376,6 +378,7 @@ class HomeSFR (Common):
a = self.base_url + self.logs_path a = self.base_url + self.logs_path
return (self.get_xml_elements (a, self.logs_labels)) return (self.get_xml_elements (a, self.logs_labels))
class Sensor (Common): class Sensor (Common):
''' '''
Class used to read easily the sensors Class used to read easily the sensors
@@ -481,6 +484,7 @@ class Sensor (Common):
''' '''
return (self.sensor_dict [self.sensors_status_field] == self.sensors_status_value_ok) return (self.sensor_dict [self.sensors_status_field] == self.sensors_status_value_ok)
class Camera (Sensor): class Camera (Sensor):
''' '''
Class used to manipulate easily cameras Class used to manipulate easily cameras