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 hassio warnings and false True (positive) for DisableLinkage feature #394

Merged
merged 2 commits into from
Oct 12, 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
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
Loading