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

Add option to enable SSL connections. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions konnected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
class Client:
"""API wrapper for Konnected Alarm Panels."""

def __init__(self, host, port, websession):
def __init__(self, host, port, websession, use_ssl=False):
"""Initialize the client connection."""
self.throttle = asyncio.Semaphore(3) # allow for 3 simultaneous reqs
self.host = host
self.port = port
self.websession = websession
self.base_url = "http://" + host + ":" + port
if use_ssl:
self.base_url = "https://" + host + ":" + port
else:
self.base_url = "http://" + host + ":" + port

async def get_status(self, retries=2):
"""Query the device status."""
Expand Down Expand Up @@ -126,6 +129,7 @@ async def put_settings(
endpoint=None,
blink=None,
discovery=None,
use_ssl=None,
dht_sensors=[],
ds18b20_sensors=[],
retries=2,
Expand All @@ -148,6 +152,9 @@ async def put_settings(
if discovery is not None:
payload["discovery"] = discovery

if use_ssl is not None:
payload["use_ssl"] = use_ssl

try:
async with self.throttle:
async with self.websession.put(url, json=payload, timeout=3) as resp:
Expand All @@ -161,6 +168,7 @@ async def put_settings(
endpoint,
blink,
discovery,
use_ssl,
dht_sensors,
ds18b20_sensors,
retries - 1,
Expand Down