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

Allow selfsigned certs #286

Merged
merged 8 commits into from
May 8, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To have a Lovelace card for the UI, [opensprinkler-card](https://github.com/rian
3. In the Home Assistant UI, navigate to `Configuration` then `Integrations`. Click on the add integration button at the bottom right and select `OpenSprinkler`. Fill out the options and save.
- URL - Should be in the form of `http://<ip or host>:<port>`. The port can be omitted unless you have changed it, as the default port for OpenSprinkler is `80`. SSL (HTTPS) is also supported.
- Password - The OpenSprinkler controller password.
- Verify SSL Certificate - If the integration should verify the certificate from an HTTPS server. Generally, this should be left checked.
- MAC Address - MAC address of the device. This is only required for firmware below 2.1.9 (4), otherwise it can be left blank.
- Controller Name - The name of the device that appears in Home Assistant.

Expand Down
10 changes: 8 additions & 2 deletions custom_components/opensprinkler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import async_timeout
from aiohttp.client_exceptions import InvalidURL
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_URL
from homeassistant.const import (
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_URL,
CONF_VERIFY_SSL,
)
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -58,8 +63,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

url = entry.data.get(CONF_URL)
password = entry.data.get(CONF_PASSWORD)
verify_ssl = entry.data.get(CONF_VERIFY_SSL)
try:
opts = {"session": async_get_clientsession(hass)}
opts = {"session": async_get_clientsession(hass), "verify_ssl": verify_ssl}
controller = OpenSprinkler(url, password, opts)
controller.refresh_on_update = False

Expand Down
24 changes: 20 additions & 4 deletions custom_components/opensprinkler/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
import voluptuous as vol
from aiohttp.client_exceptions import InvalidURL
from homeassistant import config_entries
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_URL
from homeassistant.const import (
CONF_MAC,
CONF_NAME,
CONF_PASSWORD,
CONF_URL,
CONF_VERIFY_SSL,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util import slugify
from pyopensprinkler import Controller as OpenSprinkler
from pyopensprinkler import OpenSprinklerAuthError, OpenSprinklerConnectionError

from .const import DEFAULT_NAME, DOMAIN
from .const import DEFAULT_NAME, DEFAULT_VERIFY_SSL, DOMAIN

_LOGGER = logging.getLogger(__name__)

DEVICE_SCHEMA = vol.Schema(
{
vol.Required(CONF_URL): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): bool,
vol.Optional(CONF_MAC): str,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): str,
}
Expand All @@ -37,10 +44,14 @@ async def async_step_user(self, user_input=None):
try:
url = user_input[CONF_URL]
password = user_input[CONF_PASSWORD]
verify_ssl = user_input[CONF_VERIFY_SSL]
name = user_input.get(CONF_NAME, DEFAULT_NAME)
mac_address = user_input.get(CONF_MAC)

opts = {"session": async_get_clientsession(self.hass)}
opts = {
"session": async_get_clientsession(self.hass),
"verify_ssl": verify_ssl,
}
controller = OpenSprinkler(url, password, opts)
await controller.refresh()

Expand All @@ -54,7 +65,12 @@ async def async_step_user(self, user_input=None):

return self.async_create_entry(
title=name,
data={CONF_URL: url, CONF_PASSWORD: password, CONF_NAME: name},
data={
CONF_URL: url,
CONF_PASSWORD: password,
CONF_NAME: name,
CONF_VERIFY_SSL: verify_ssl,
},
)
except InvalidURL:
errors["base"] = "invalid_url"
Expand Down
1 change: 1 addition & 0 deletions custom_components/opensprinkler/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DOMAIN = "opensprinkler"

DEFAULT_NAME = "OpenSprinkler"
DEFAULT_VERIFY_SSL = True

DEFAULT_SCAN_INTERVAL = 5

Expand Down
1 change: 1 addition & 0 deletions custom_components/opensprinkler/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"url": "URL",
"password": "Password",
"verify_ssl": "Verify SSL Certificate (Safer when checked)",
"mac": "MAC Address",
"name": "Controller Name"
},
Expand Down
1 change: 1 addition & 0 deletions custom_components/opensprinkler/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"url": "URL",
"password": "Password",
"verify_ssl": "Verify SSL Certificate (Safer when checked)",
"mac": "MAC Address",
"name": "Controller Name"
},
Expand Down
Loading