From 5cc3b483edd9d4313e8a07e0e6e1a94f9ff6787f Mon Sep 17 00:00:00 2001 From: Gilles MOREL Date: Tue, 20 Oct 2020 10:28:22 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9cup=C3=A9ration=20de=20l'=C3=A9tat=20et?= =?UTF-8?q?=20la=20puissance=20des=20prises?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homesfr.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/homesfr.py b/homesfr.py index 6566985..d9b47a4 100644 --- a/homesfr.py +++ b/homesfr.py @@ -28,6 +28,8 @@ SIREN = 'SIREN' # https://boutique.home.sfr.fr/sirene-interieure (et peut- REMOTE_CONTROLER = 'REMOTE' # https://boutique.home.sfr.fr/telecommande KEYPAD_CONTROLER = 'KEYPAD' # https://boutique.home.sfr.fr/clavier-de-commande PRESENCE_CAMERA_DETECTOR = 'PIR_CAMERA' # https://boutique.home.sfr.fr/camera +TEMPHUM_SENSOR = 'TEMP_HUM' # https://boutique.home.sfr.fr/thermometre +ONOFF_PLUG = 'ON_OFF_PLUG' # https://boutique.home.sfr.fr/prise-commandee-connectee-legrand base_url = 'https://home.sfr.fr' @@ -56,7 +58,7 @@ mode_off = 'OFF' # Value for off mode_custom = 'CUSTOM' # Value for custom mode_on = 'ON' # Value for on -# Cémera +# Caméra cameras_list = '/homescope/mycams' camera_snapshot = '/homescope/snapshot?size=4' camera_snapshot_mac = 'mac' @@ -107,6 +109,11 @@ sensors_temp_text = 'Temperature' sensors_hum_name = 'name' sensors_hum_text = 'Humidity' +# Prise connectée (ON_OFF_PLUG) +sensors_oop_stateroot = 'automation' +sensors_oop_state = 'on_off' +sensors_oop_power = 'power_level' + # 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 logs_labels = 'LOG' @@ -366,11 +373,17 @@ class Sensor (): ''' return (self.sensor_dict) + def get_attributes (self, lst, key): + for i in lst: + if i [0] == key: + return (i [1]) + raise KeyError ('no key ' + key) + def get_value (self, lst, key): for i in lst: if i [0] == key: return (i [2]) - raise KeyError ('no value ' + key) + raise KeyError ('no key ' + key) def get_mac (self): ''' @@ -479,4 +492,18 @@ class Sensor (): a = self.get_value (self.sensor_dict, sensors_temphum_root_field) for i in a: if i [1] [sensors_hum_name] == sensors_hum_text: - return (int (i [2].replace ('%', ''))) \ No newline at end of file + return (int (i [2].replace ('%', ''))) + + def get_on_off_state (self): + ''' + Retourne l'état d'une prise connectée, True sur la prise est fermée + ''' + a = self.get_attributes (self.sensor_dict, sensors_oop_stateroot) + return (True if a [sensors_oop_state] == '1' else False) + + def get_on_off_power (self): + ''' + Retourne la puissance active qui traverse la prise, en watts + ''' + a = self.get_attributes (self.sensor_dict, sensors_oop_stateroot) + return (int (a [sensors_oop_power])) \ No newline at end of file