Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BRP072C devices not working #13

Merged
merged 3 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pydaikin/daikin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timedelta
import logging
import socket
from ssl import SSLContext
from typing import Optional
from urllib.parse import unquote

Expand All @@ -31,7 +32,9 @@ class Appliance(DaikinPowerMixin): # pylint: disable=too-many-public-methods
"""Daikin main appliance class."""

base_url: str
headers: Optional[dict]
session: Optional[ClientSession]
ssl_context: Optional[SSLContext]

TRANSLATIONS = {}

Expand Down Expand Up @@ -132,13 +135,20 @@ async def _get_resource(self, path: str, params: Optional[dict] = None):
if params is None:
params = {}

_LOGGER.debug("Calling: %s/%s %s", self.base_url, path, params)
headers = self.headers
if headers is None:
headers = {}

_LOGGER.debug("Calling: %s/%s %s [%s]", self.base_url, path, params, headers)

# cannot manage session on outer async with or this will close the session
# passed to pydaikin (homeassistant for instance)
async with self.request_semaphore:
async with self.session.get(
f'{self.base_url}/{path}', params=params
f'{self.base_url}/{path}',
params=params,
headers=headers,
ssl_context=self.ssl_context,
) as response:
if response.status == 403:
raise HTTPForbidden(reason=f"HTTP 403 Forbidden for {response.url}")
Expand Down
10 changes: 5 additions & 5 deletions pydaikin/daikin_brp072c.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def __init__(self, device_id, session=None, key=None, uuid=None) -> None:
if uuid is None:
uuid = uuid3(NAMESPACE_OID, 'pydaikin')
self._uuid = str(uuid).replace('-', '')
self._headers = {"X-Daikin-uuid": self._uuid}
self._ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
self.headers = {"X-Daikin-uuid": self._uuid}
self.ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
# SSL_OP_LEGACY_SERVER_CONNECT, https://github.com/python/cpython/issues/89051
self._ssl_context.options |= 0x4
self._ssl_context.check_hostname = False
self._ssl_context.verify_mode = ssl.CERT_NONE
self.ssl_context.options |= 0x4
self.ssl_context.check_hostname = False
self.ssl_context.verify_mode = ssl.CERT_NONE
self.base_url = f"https://{self.device_ip}"

async def init(self):
Expand Down
Loading