Compare commits
34
Commits
1.6
..
983e4adee6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
983e4adee6
|
||
|
|
5cc3b483ed
|
||
|
|
b4540504f8
|
||
|
|
b62c6c36ea
|
||
|
|
72e1c94a80 | ||
|
|
8fb1eac749 | ||
|
|
b338230b37 | ||
|
|
f5e8e4bdf0
|
||
|
|
952cf74b8e | ||
|
|
aff562b61b | ||
|
|
3f4b3cd1aa | ||
|
|
92d0f18f3a | ||
|
|
efd3144d9f | ||
|
|
3df38d59bb | ||
|
|
b969b8fb81 | ||
|
|
fd58a374cd | ||
|
|
ee892b9d2c | ||
|
|
46933a8156 | ||
|
|
9f2f4a06d1 | ||
|
|
6facbe84f8 | ||
|
|
d68e3ceb3c | ||
|
|
f60d528ed0 | ||
|
|
9dd904b4ea | ||
|
|
beae1f2b97 | ||
|
|
15bc8e86bd | ||
|
|
9af3dc69ab | ||
|
|
60974181fa | ||
|
|
11050152c3 | ||
|
|
fe41141672 | ||
|
|
651fa470f7 | ||
|
|
a2afd83117 | ||
|
|
61ce155e2b | ||
|
|
516734b611 | ||
|
|
8224cd1594 |
+12
-38
@@ -9,13 +9,12 @@ from http.cookiejar import CookieJar
|
||||
from urllib.parse import urlencode
|
||||
from urllib.error import HTTPError
|
||||
from time import time
|
||||
from json import loads as json_read
|
||||
|
||||
authors = (
|
||||
'Sasha "Almtesh" Évan MOREL',
|
||||
'Gilles "Almtesh" Émilien MOREL',
|
||||
)
|
||||
name = 'homesfr pour Python 3'
|
||||
version = '1.6'
|
||||
version = '1.4'
|
||||
|
||||
# Modes utilisables
|
||||
MODE_OFF = 0
|
||||
@@ -38,15 +37,11 @@ base_url = 'https://home.sfr.fr'
|
||||
# Authentification
|
||||
auth_path = '/mysensors'
|
||||
auth_ok_url = 'https://home.sfr.fr/logged'
|
||||
auth_post_url = 'https://home.sfr.fr/login'
|
||||
auth_referer = 'https://home.sfr.fr/login'
|
||||
auth_post_url = 'https://boutique.home.sfr.fr/authentification'
|
||||
auth_referer = 'https://boutique.home.sfr.fr/authentification?back=service'
|
||||
auth_user_field = 'email'
|
||||
auth_pass_field = 'passwd'
|
||||
auth_extra_fields = {'back': 'service', 'error_sso': '', 'SubmitLogin': 'OK'}
|
||||
auth_sso_post_url = 'https://home.sfr.fr/sso-connector.php'
|
||||
auth_sso_user_field = 'connectionSFR'
|
||||
auth_sso_pass_field = 'passSFR'
|
||||
auth_sso_get_field = 'token_sso'
|
||||
auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'}
|
||||
auth_logout_path = '/deconnexion'
|
||||
|
||||
# Chemin pour la liste des capteurs
|
||||
@@ -118,11 +113,6 @@ sensors_hum_text = 'Humidity'
|
||||
sensors_oop_stateroot = 'automation'
|
||||
sensors_oop_state = 'on_off'
|
||||
sensors_oop_power = 'power_level'
|
||||
sensors_oop_control = '/plugcontrol'
|
||||
sensors_oop_control_sensors_id_field = 'uid'
|
||||
sensors_oop_control_action_field = 'action'
|
||||
sensors_oop_control_action_value_on = 'on'
|
||||
sensors_oop_control_action_value_off = 'off'
|
||||
|
||||
# Fil d'événements
|
||||
logs_path = '/getlog?page=1&nbparpage=10000' # je pense qu'on récupère tous les événements avec cette valeur
|
||||
@@ -277,7 +267,6 @@ class HomeSFR ():
|
||||
print ('initalisé avec l\'identifiant ' + username)
|
||||
if cookies is not None:
|
||||
print ('initialisé avec des cookies')
|
||||
print ('Cookies ' + str (len (cookies)))
|
||||
print ('debug = ' + str (debug))
|
||||
print ('autologin = ' + str (autologin))
|
||||
|
||||
@@ -291,8 +280,10 @@ class HomeSFR ():
|
||||
self.autologin = False
|
||||
if cookies is None:
|
||||
self.cookies = CookieJar ()
|
||||
else:
|
||||
elif type (cookies) == CookieJar:
|
||||
self.cookies = cookies
|
||||
else:
|
||||
raise TypeError ('Les cookies doivent être de type CookieJar !')
|
||||
self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
|
||||
self.mysensors = self.MySensors (self)
|
||||
|
||||
@@ -329,19 +320,7 @@ class HomeSFR ():
|
||||
'''
|
||||
if self.username is not None and self.password is not None:
|
||||
self.opener.open (auth_referer)
|
||||
# SSO
|
||||
data = {}
|
||||
data [auth_sso_user_field] = self.username
|
||||
data [auth_sso_pass_field] = self.password
|
||||
data = bytes (urlencode (data), 'UTF8')
|
||||
if self.DEBUG:
|
||||
print ('Cookies ' + str (len (self.cookies)))
|
||||
print ('Envoi de ' + str (data))
|
||||
a = self.opener.open (auth_sso_post_url, data = data)
|
||||
sso = json_read (a.read ().decode ('UTF8')) ['result']
|
||||
# Authenfication
|
||||
data = dict (auth_extra_fields)
|
||||
data [auth_sso_get_field] = sso [auth_sso_get_field]
|
||||
data = auth_extra_fields
|
||||
data [auth_user_field] = self.username
|
||||
data [auth_pass_field] = self.password
|
||||
data = bytes (urlencode (data), 'UTF8')
|
||||
@@ -410,6 +389,8 @@ class HomeSFR ():
|
||||
print ('Vous devriez utiliser les constantes MODE_OFF, MODE_ON et MODE_CUSTOM.')
|
||||
raise ValueError
|
||||
r = base_url + mode_set_path + '?' + mode_set_field + '=' + m
|
||||
if self.DEBUG:
|
||||
print ('Demande ' + r)
|
||||
self.get_or_autologin (r)
|
||||
return (True)
|
||||
|
||||
@@ -600,7 +581,7 @@ class Sensor ():
|
||||
a = self.get_value (self.get_raw (), sensors_temphum_root_field)
|
||||
for i in a:
|
||||
if i [1] [sensors_hum_name] == sensors_hum_text:
|
||||
return (float (i [2].replace ('%', '')))
|
||||
return (int (i [2].replace ('%', '')))
|
||||
|
||||
def get_on_off_state (self):
|
||||
'''
|
||||
@@ -609,13 +590,6 @@ class Sensor ():
|
||||
a = self.get_attributes (self.get_raw (), sensors_oop_stateroot)
|
||||
return (True if a [sensors_oop_state] == '1' else False)
|
||||
|
||||
def set_on_off_state (self, state):
|
||||
'''
|
||||
Défini l'état d'une prise connectée, True pour fermer la prise
|
||||
'''
|
||||
r = base_url + sensors_oop_control + '?' + sensors_oop_control_sensors_id_field + '=' + self.id + '&' + sensors_oop_control_action_field + '=' + (sensors_oop_control_action_value_on if state else sensors_oop_control_action_value_off)
|
||||
self.get_or_autologin (r)
|
||||
|
||||
def get_on_off_power (self):
|
||||
'''
|
||||
Retourne la puissance active qui traverse la prise, en watts
|
||||
|
||||
Reference in new issue
Block a user