Skip to content

Commit

Permalink
Small fixes for speedwire support
Browse files Browse the repository at this point in the history
  • Loading branch information
littleyoda committed May 1, 2024
1 parent cad58d9 commit 0c907ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions custom_components/pysmaplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up sma from a config entry."""
# Init the SMA interface
protocol = "https" if entry.data[CONF_SSL] else "http"
url = f"{protocol}://{entry.data[CONF_HOST]}"
verify_ssl = entry.data[CONF_VERIFY_SSL]
# group = entry.data[CONF_GROUP]
#password = entry.data[CONF_PASSWORD]

session = async_get_clientsession(hass, verify_ssl=verify_ssl)
session = None
if entry.data[CONF_ACCESS] == "speedwireinv":
url = entry.data[CONF_HOST]
elif CONF_SSL in entry.data and CONF_HOST in entry.data:
protocol = "https" if entry.data[CONF_SSL] else "http"
url = f"{protocol}://{entry.data[CONF_HOST]}"
session = async_get_clientsession(hass, verify_ssl=entry.data[CONF_VERIFY_SSL])
am = entry.data[CONF_ACCESS]
if (am == "speedwire"):
am = "speedwireem"

_LOGGER.debug(f"Setup Entry => URL: {url} User: {entry.data[CONF_GROUP]} Method: {am}")
sma = pysma.getDevice(session, url, password = entry.data[CONF_PASSWORD], groupuser = entry.data[CONF_GROUP], accessmethod = am)
# sma = pysma.SMA(session, url, password, group)
try:
Expand Down
5 changes: 4 additions & 1 deletion custom_components/pysmaplus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ async def validate_input(
"""Validate the user input allows us to connect."""
url = None
session = None
if CONF_SSL in data and CONF_HOST in data:
if data[CONF_ACCESS] == "speedwireinv":
url = data[CONF_HOST]
elif CONF_SSL in data and CONF_HOST in data:
protocol = "https" if data[CONF_SSL] else "http"
url = f"{protocol}://{data[CONF_HOST]}"
session = async_get_clientsession(hass, verify_ssl=data[CONF_VERIFY_SSL])
am = data[CONF_ACCESS]
if (am == "speedwire"):
am = "speedwireem"
_LOGGER.debug(f"Validate URL: {url} User: {data[CONF_GROUP]} Method: {am}")
sma = pysma.getDevice(session, url, password = data[CONF_PASSWORD], groupuser = data[CONF_GROUP], accessmethod = am)
#sma = pysma.SMA(session, url, data[CONF_PASSWORD], group=data[CONF_GROUP])

Expand Down

0 comments on commit 0c907ea

Please sign in to comment.