Skip to content

Commit

Permalink
Fix login error coming from bad language field
Browse files Browse the repository at this point in the history
  • Loading branch information
slvwolf committed Dec 14, 2023
1 parent 1338613 commit 08d9c7a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pcfmqtt/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
import time
import types
import logging
import requests
import json
from pcfmqtt.device import Device
from pcfmqtt.events import discovery_event, state_event

# Pached version of pcomfortcloud.Session to fix compatibility issues with latest version of Panasonic Comfort Cloud
def _validate_response(response):
""" Verify that response is OK """
if response.status_code == 200:
return
raise pcomfortcloud.ResponseError(response.status_code, response.text)

class SessionWrapper(pcomfortcloud.Session):
"""
Expand All @@ -24,6 +32,29 @@ def _headers(self):
"Content-Type": "application/json; charset=utf-8"
}

def _create_token(self):
response = None
payload = {
"language": 0,
"loginId": self._username,
"password": self._password
}
if self._raw:
print("--- creating token by authenticating")
try:
response = requests.post(
pcomfortcloud.urls.login(), json=payload, headers=self._headers(), verify=self._verifySsl)
if 2 != response.status_code // 100:
raise pcomfortcloud.ResponseError(response.status_code, response.text)
except requests.exceptions.RequestException as ex:
raise pcomfortcloud.LoginError(ex)
_validate_response(response)
if (self._raw is True):
print("--- raw beginning ---")
print(response.text)
print("--- raw ending ---\n")
self._vid = json.loads(response.text)['uToken']


class Service:
"""
Expand Down

0 comments on commit 08d9c7a

Please sign in to comment.