Exemple #1
0
def put_status(air_purifier_host, status):
    status_url = comms.get_api_url(air_purifier_host, "1/air")
    status = comms.dh_encrypt(json.dumps(status),
                              comms.get_key(air_purifier_host))
    response = requests.put(status_url, data=status)
    response.raise_for_status()
    status = comms.dh_decrypt(response.text, comms.get_key(air_purifier_host))
    return json.loads(status)
Exemple #2
0
def put_wifi(air_purifier_host, ssid=None, pwd=None):
    wifi_settings = {}
    if ssid is not None:
        wifi_settings["ssid"] = ssid
    if pwd is not None:
        wifi_settings["password"] = pwd
    session_key = comms.get_key(air_purifier_host)
    wifi_url = comms.get_api_url(air_purifier_host, "0/wifi")
    encrypted_wifi_settings = comms.dh_encrypt(json.dumps(wifi_settings),
                                               session_key)
    response = requests.put(wifi_url, data=encrypted_wifi_settings)
    response.raise_for_status()
    wifi_response = comms.dh_decrypt(response.text, session_key)
    return json.loads(wifi_response)
 def _status_put_handler(self, url, request):
     new_status = json.loads(comms.dh_decrypt(request.body, self.session_key))
     self.status.update(new_status)
     return comms.dh_encrypt(json.dumps(self.status), self.session_key)
 def _status_get_handler(self, url, request):
     return comms.dh_encrypt(json.dumps(self.status), self.session_key)
 def _wifi_put_handler(self, url, request):
     new_wifi = json.loads(comms.dh_decrypt(request.body, self.session_key))
     self.wifi = wifi_responses.configured_wifi(new_wifi["ssid"])
     return comms.dh_encrypt(json.dumps(self.wifi), self.session_key)
 def _wifi_get_handler(self, url, request):
     return comms.dh_encrypt(json.dumps(self.wifi), self.session_key)