diff --git a/custom_components/dahua/__init__.py b/custom_components/dahua/__init__.py index 56a92c7..513c51f 100755 --- a/custom_components/dahua/__init__.py +++ b/custom_components/dahua/__init__.py @@ -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 @@ -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__) @@ -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) @@ -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 diff --git a/custom_components/dahua/client.py b/custom_components/dahua/client.py index bd2eefa..50c27ff 100755 --- a/custom_components/dahua/client.py +++ b/custom_components/dahua/client.py @@ -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: """ diff --git a/custom_components/dahua/config_flow.py b/custom_components/dahua/config_flow.py index c2ebd62..1fe1837 100755 --- a/custom_components/dahua/config_flow.py +++ b/custom_components/dahua/config_flow.py @@ -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", @@ -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)