Skip to content

Commit

Permalink
Fix hassio warnings and false True (positive) for DisableLinkage feat…
Browse files Browse the repository at this point in the history
…ure (#394)

* Fix hassio warnings

setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1

Detected blocking call to load_default_certs

Signed-off-by: Jan Dušek <[email protected]>

* Changing query for DisableLinkage

Unify the way it is done elsewhere to prevent excesive false positive retun of True when DisableLinkage is actually available and returns error from camera. After thsi fix, it is queried twice and then the integration knows it is unavailable.

Signed-off-by: Jan Dušek <[email protected]>

---------

Signed-off-by: Jan Dušek <[email protected]>
  • Loading branch information
jandusek4 authored Oct 12, 2024
1 parent 0fbf55e commit 6522072
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
16 changes: 8 additions & 8 deletions custom_components/dahua/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from homeassistant.core import CALLBACK_TYPE, Config, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, PlatformNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.const import EVENT_HOMEASSISTANT_STOP

from custom_components.dahua.thread import DahuaEventThread, DahuaVtoEventThread
Expand All @@ -41,6 +42,11 @@

SCAN_INTERVAL_SECONDS = timedelta(seconds=30)

SSL_CONTEXT = ssl.create_default_context()
SSL_CONTEXT.set_ciphers("DEFAULT")
SSL_CONTEXT.check_hostname = False
SSL_CONTEXT.verify_mode = ssl.CERT_NONE

_LOGGER: logging.Logger = logging.getLogger(__package__)


Expand Down Expand Up @@ -82,9 +88,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
for platform in PLATFORMS:
if entry.options.get(platform, True):
coordinator.platforms.append(platform)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
await hass.config_entries.async_forward_entry_setups(entry, [platform])

entry.add_update_listener(async_reload_entry)

Expand All @@ -102,11 +106,7 @@ def __init__(self, hass: HomeAssistant, events: list, address: str, port: int, r
password: str, name: str, channel: int) -> None:
"""Initialize the coordinator."""
# Self signed certs are used over HTTPS so we'll disable SSL verification
ssl_context = ssl.create_default_context()
ssl_context.set_ciphers("DEFAULT")
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
connector = TCPConnector(enable_cleanup_closed=True, ssl=ssl_context)
connector = TCPConnector(enable_cleanup_closed=True, ssl=SSL_CONTEXT)
self._session = ClientSession(connector=connector)

# The client used to communicate with Dahua devices
Expand Down
5 changes: 1 addition & 4 deletions custom_components/dahua/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,7 @@ async def async_get_disarming_linkage(self) -> dict:
"""

url = "/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage"
try:
return await self.get(url)
except aiohttp.ClientResponseError as e:
return {"table.DisableLinkage.Enable": "false"}
return await self.get(url)

async def async_access_control_open_door(self, door_id: int = 1) -> dict:
"""
Expand Down
12 changes: 7 additions & 5 deletions custom_components/dahua/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
https://developers.home-assistant.io/docs/data_entry_flow_index/
"""

SSL_CONTEXT = ssl.create_default_context()
#SSL_CONTEXT.minimum_version = ssl.TLSVersion.TLSv1_2
SSL_CONTEXT.set_ciphers("DEFAULT")
SSL_CONTEXT.check_hostname = False
SSL_CONTEXT.verify_mode = ssl.CERT_NONE

_LOGGER: logging.Logger = logging.getLogger(__package__)

DEFAULT_EVENTS = ["VideoMotion", "CrossLineDetection", "AlarmLocal", "VideoLoss", "VideoBlind", "AudioMutation",
Expand Down Expand Up @@ -177,11 +183,7 @@ async def _show_config_form_name(self, user_input): # pylint: disable=unused-ar
async def _test_credentials(self, username, password, address, port, rtsp_port, channel):
"""Return name and serialNumber if credentials is valid."""
# Self signed certs are used over HTTPS so we'll disable SSL verification
ssl_context = ssl.create_default_context()
ssl_context.set_ciphers("DEFAULT")
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
connector = TCPConnector(enable_cleanup_closed=True, ssl=ssl_context)
connector = TCPConnector(enable_cleanup_closed=True, ssl=SSL_CONTEXT)
session = ClientSession(connector=connector)
try:
client = DahuaClient(username, password, address, port, rtsp_port, session)
Expand Down

0 comments on commit 6522072

Please sign in to comment.