From ff86bb8f02084120fdd441429bff43328b6d801c Mon Sep 17 00:00:00 2001 From: Jimmy Everling Date: Thu, 3 Oct 2024 11:43:18 +0200 Subject: [PATCH] Fixed heat/cool mode and added some test data --- custom_components/panasonic_cc/climate.py | 4 +++- custom_components/panasonic_cc/manifest.json | 2 +- .../panasonic_cc/pcomfortcloud/apiclient.py | 7 +++++-- .../panasonic_cc/pcomfortcloud/panasonicsession.py | 14 ++++++++++++-- .../panasonic_cc/pcomfortcloud/testdata.py | 7 ++++++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/custom_components/panasonic_cc/climate.py b/custom_components/panasonic_cc/climate.py index 6b87e97..cf747a9 100644 --- a/custom_components/panasonic_cc/climate.py +++ b/custom_components/panasonic_cc/climate.py @@ -164,7 +164,9 @@ def _async_update_attrs(self) -> None: state = self.coordinator.device.parameters self._attr_hvac_mode = (HVACMode.OFF if state.power == constants.Power.Off - else convert_operation_mode_to_hvac_mode(state.mode, state.iautox_mode)) + else convert_operation_mode_to_hvac_mode( + state.mode, + state.iautox_mode == constants.IAutoXMode.On)) self._set_temp_range() diff --git a/custom_components/panasonic_cc/manifest.json b/custom_components/panasonic_cc/manifest.json index 0bd7c3d..0873a50 100644 --- a/custom_components/panasonic_cc/manifest.json +++ b/custom_components/panasonic_cc/manifest.json @@ -2,7 +2,7 @@ "domain": "panasonic_cc", "name": "Panasonic Comfort Cloud", "after_dependencies": ["http"], - "version": "2024.9.3", + "version": "2024.10.0", "config_flow": true, "documentation": "https://github.com/sockless-coding/panasonic_cc/", "dependencies": [], diff --git a/custom_components/panasonic_cc/pcomfortcloud/apiclient.py b/custom_components/panasonic_cc/pcomfortcloud/apiclient.py index f894b46..9cfef14 100644 --- a/custom_components/panasonic_cc/pcomfortcloud/apiclient.py +++ b/custom_components/panasonic_cc/pcomfortcloud/apiclient.py @@ -10,10 +10,11 @@ import json -from . import constants +from . import constants, testdata from . import panasonicsession from .panasonicdevice import PanasonicDevice, PanasonicDeviceInfo, PanasonicDeviceEnergy + _LOGGER = logging.getLogger(__name__) _current_time_zone = None @@ -101,6 +102,8 @@ def get_devices(self): self._devices.append(device_info) else: self._unknown_devices.append(device_info) + + #self._unknown_devices.append(PanasonicDeviceInfo(get_dummy_aquarea_device_json())) return self._devices def dump(self, device_id): @@ -184,7 +187,7 @@ async def get_aquarea_device(self, device_info: PanasonicDeviceInfo): cookies=id_cookies, ) device_id = id_response.cookies.get("selectedDeviceId").value - _LOGGER.debug("Aquarea Device ID fro {} is {}".format(device_info.guid, device_id)) + _LOGGER.debug("Aquarea Device ID for {} is {}".format(device_info.guid, device_id)) status_response = await self.execute_aqua_get( self._get_aquarea_device_info_url(device_id), "Get Aquarea device info", 200) diff --git a/custom_components/panasonic_cc/pcomfortcloud/panasonicsession.py b/custom_components/panasonic_cc/pcomfortcloud/panasonicsession.py index 5760192..f927730 100644 --- a/custom_components/panasonic_cc/pcomfortcloud/panasonicsession.py +++ b/custom_components/panasonic_cc/pcomfortcloud/panasonicsession.py @@ -42,6 +42,7 @@ def __init__(self, username, password, client: aiohttp.ClientSession, settingsFi self._authentication = PanasonicAuthentication(client, self._settings, self._app_version) self._raw = raw self._request_semaphore = asyncio.Semaphore(1) + self._aqua_cookies = aiohttp.CookieJar() async def start_session(self): _LOGGER.debug("Starting Session") @@ -155,8 +156,9 @@ async def execute_aqua_get( cookies: dict = {}): async with self._request_semaphore: await self._ensure_valid_token() - + old_cookie_jar = self._client.cookie_jar try: + self._client._cookie_jar = self._aqua_cookies cookies["accessToken"] = self._settings.access_token response = await self._client.get( url, @@ -167,6 +169,8 @@ async def execute_aqua_get( aiohttp.http_exceptions.HttpProcessingError, aiohttp.web_exceptions.HTTPError) as ex: raise exceptions.RequestError(ex) + finally: + self._client._cookie_jar = old_cookie_jar self._print_response_if_raw_is_set(response, function_description) await check_response(response, function_description, expected_status_code) @@ -181,18 +185,24 @@ async def execute_aqua_post( cookies: dict = {}): async with self._request_semaphore: await self._ensure_valid_token() - + old_cookie_jar = self._client.cookie_jar try: + self._client._cookie_jar = self._aqua_cookies + _LOGGER.debug(f"Aqua access token: {self._settings.access_token}") cookies["accessToken"] = self._settings.access_token + response = await self._client.post( url, headers = PanasonicRequestHeader.get_aqua_headers(content_type=content_type), cookies=cookies ) + except (aiohttp.client_exceptions.ClientError, aiohttp.http_exceptions.HttpProcessingError, aiohttp.web_exceptions.HTTPError) as ex: raise exceptions.RequestError(ex) + finally: + self._client._cookie_jar = old_cookie_jar self._print_response_if_raw_is_set(response, function_description) await check_response(response, function_description, expected_status_code) diff --git a/custom_components/panasonic_cc/pcomfortcloud/testdata.py b/custom_components/panasonic_cc/pcomfortcloud/testdata.py index 5acdc40..b2fc7d7 100644 --- a/custom_components/panasonic_cc/pcomfortcloud/testdata.py +++ b/custom_components/panasonic_cc/pcomfortcloud/testdata.py @@ -25,4 +25,9 @@ def inject_zone_data(json): "zoneSpill": 0, "zoneId": 3, "zoneName": "Zone 3" - }) \ No newline at end of file + }) +def get_dummy_aquarea_device_json(): + return {"deviceGuid": "000007340331", "deviceType": "2", "deviceName": "Demo", "connectionStatus": 0, "operationMode": 1, "zoneStatus": [{"zoneId": 1, "operationStatus": 0, "temperature": 0}, {"zoneId": 2}], "tankStatus": {"operationStatus": 1, "temperature": 50}} + +def return_data(): + return {"timestamp":1727898629466,"permission":3,"summerHouse":2,"iAutoX":False,"nanoe":False,"nanoeStandAlone":False,"autoMode":True,"heatMode":True,"fanMode":True,"dryMode":True,"coolMode":True,"ecoNavi":False,"powerfulMode":True,"quietMode":True,"airSwingLR":True,"autoSwingUD":False,"ecoFunction":0,"temperatureUnit":0,"modeAvlList":{"autoMode":1},"nanoeList":{"visualizationShow":0},"clothesDrying":False,"insideCleaning":False,"fireplace":False,"pairedFlg":False,"parameters":{"ecoFunctionData":0,"insideCleaning":0,"fireplace":0,"lastSettingMode":0,"operate":1,"operationMode":0,"temperatureSet":22.5,"fanSpeed":0,"fanAutoMode":0,"airSwingLR":2,"airSwingUD":2,"ecoMode":2,"ecoNavi":0,"nanoe":0,"iAuto":0,"airDirection":1,"insideTemperature":21,"outTemperature":5,"airQuality":0}} \ No newline at end of file